Add part placement preview, render all part boxes on hover (#349)
This commit is contained in:
@@ -83,6 +83,7 @@ public final class AEConfig extends Configuration implements IConfigurableObject
|
||||
private int craftingCalculationTimePerTick = 5;
|
||||
private PowerUnits selectedPowerUnit = PowerUnits.AE;
|
||||
private boolean showCraftableTooltip = true;
|
||||
private boolean showPlacementPreview = true;
|
||||
|
||||
// Spatial IO/Dimension
|
||||
private int storageProviderID = -1;
|
||||
@@ -257,6 +258,7 @@ public final class AEConfig extends Configuration implements IConfigurableObject
|
||||
this.useLargeFonts = this.get("Client", "useTerminalUseLargeFont", false).getBoolean(false);
|
||||
this.useColoredCraftingStatus = this.get("Client", "useColoredCraftingStatus", true).getBoolean(true);
|
||||
this.showCraftableTooltip = this.get("Client", "showCraftableTooltip", true, "Whether to add \"Craftable\" to item tooltips when they can be crafted automatically.").getBoolean(true);
|
||||
this.showPlacementPreview = this.get("Client", "showPlacementPreview", true, "Whether to show a preview of part and facade placement.").getBoolean(true);
|
||||
|
||||
// load buttons..
|
||||
for (int btnNum = 0; btnNum < 4; btnNum++) {
|
||||
@@ -514,6 +516,10 @@ public final class AEConfig extends Configuration implements IConfigurableObject
|
||||
return this.showCraftableTooltip;
|
||||
}
|
||||
|
||||
public boolean showPlacementPreview() {
|
||||
return this.showPlacementPreview;
|
||||
}
|
||||
|
||||
public boolean isDisableColoredCableRecipesInJEI() {
|
||||
return this.disableColoredCableRecipesInJEI;
|
||||
}
|
||||
|
||||
@@ -54,13 +54,13 @@ import appeng.core.stats.PartItemPredicate;
|
||||
import appeng.core.stats.Stats;
|
||||
import appeng.core.worlddata.SpatialDimensionManager;
|
||||
import appeng.fluids.registries.BasicFluidCellGuiHandler;
|
||||
import appeng.hooks.WrenchClickHook;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.items.materials.ItemMaterial;
|
||||
import appeng.items.parts.ItemFacade;
|
||||
import appeng.items.parts.ItemPart;
|
||||
import appeng.loot.ChestLoot;
|
||||
import appeng.me.cache.*;
|
||||
import appeng.parts.PartPlacement;
|
||||
import appeng.recipes.AEItemResolver;
|
||||
import appeng.recipes.AERecipeLoader;
|
||||
import appeng.recipes.game.DisassembleRecipe;
|
||||
@@ -109,7 +109,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -193,7 +192,7 @@ final class Registration {
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(TickHandler.INSTANCE);
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new PartPlacement());
|
||||
MinecraftForge.EVENT_BUS.register(new WrenchClickHook());
|
||||
|
||||
if (AEConfig.instance().isFeatureEnabled(AEFeature.CHEST_LOOT)) {
|
||||
MinecraftForge.EVENT_BUS.register(new ChestLoot());
|
||||
|
||||
@@ -19,28 +19,91 @@
|
||||
package appeng.core.api;
|
||||
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.ITileDefinition;
|
||||
import appeng.api.parts.CableRenderMode;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHelper;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.parts.PartPlacement;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
public class ApiPart implements IPartHelper {
|
||||
|
||||
@Override
|
||||
public EnumActionResult placeBus(final ItemStack is, final BlockPos pos, final EnumFacing side, final EntityPlayer player, final EnumHand hand, final World w) {
|
||||
return PartPlacement.place(is, pos, side, player, hand, w, PartPlacement.PlaceType.PLACE_ITEM, 0);
|
||||
return PartPlacement.place(is, pos, side, player, hand, w);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CableRenderMode getCableRenderMode() {
|
||||
return AppEng.proxy.getRenderMode();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IPart getPart(World w, BlockPos pos, AEPartLocation side) {
|
||||
final TileEntity tile = w.getTileEntity(pos);
|
||||
if (tile instanceof IPartHost partHost) {
|
||||
return partHost.getPart(side);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IPartHost getPartHost(World w, BlockPos pos) {
|
||||
final TileEntity tile = w.getTileEntity(pos);
|
||||
if (tile instanceof IPartHost partHost) {
|
||||
return partHost;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IPartHost getOrPlacePartHost(World w, BlockPos pos, boolean force, @Nullable EntityPlayer p) {
|
||||
final TileEntity tile = w.getTileEntity(pos);
|
||||
if (tile instanceof IPartHost partHost) {
|
||||
return partHost;
|
||||
} else {
|
||||
if (!force && !canPlacePartHost(w, pos, p)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ITileDefinition multiPart = AEApi.instance().definitions().blocks().multiPart();
|
||||
if (!multiPart.isEnabled()) return null;
|
||||
Block blk = multiPart.maybeBlock().orElse(null);
|
||||
if (blk == null) return null;
|
||||
|
||||
final IBlockState state = blk.getDefaultState();
|
||||
w.setBlockState(pos, state, 3);
|
||||
return w.getTileEntity(pos) instanceof IPartHost host ? host : null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlacePartHost(World w, BlockPos pos, @Nullable EntityPlayer p) {
|
||||
if (p != null && !Platform.hasPermissions(w, pos, p)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Block blk = w.getBlockState(pos).getBlock();
|
||||
return blk == null || blk.isReplaceable(w, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +44,6 @@ public class AppEngPacketHandlerBase {
|
||||
|
||||
PACKET_CONFIG_BUTTON(PacketConfigButton.class),
|
||||
|
||||
PACKET_PART_PLACEMENT(PacketPartPlacement.class),
|
||||
|
||||
PACKET_LIGHTNING(PacketLightning.class),
|
||||
|
||||
PACKET_MATTER_CANNON(PacketMatterCannon.class),
|
||||
|
||||
@@ -19,21 +19,13 @@
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IComparableDefinition;
|
||||
import appeng.api.definitions.IItems;
|
||||
import appeng.api.implementations.items.IMemoryCard;
|
||||
import appeng.api.implementations.items.MemoryCardMessages;
|
||||
import appeng.block.networking.BlockCableBus;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.core.sync.network.INetworkInfo;
|
||||
import appeng.items.tools.ToolNetworkTool;
|
||||
import appeng.items.tools.powered.ToolColorApplicator;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -99,31 +91,12 @@ public class PacketClick extends AppEngPacket {
|
||||
|
||||
@Override
|
||||
public void serverPacketData(final INetworkInfo manager, final AppEngPacket packet, final EntityPlayer player) {
|
||||
final ItemStack is = player.inventory.getCurrentItem();
|
||||
final IItems items = AEApi.instance().definitions().items();
|
||||
final IComparableDefinition maybeMemoryCard = items.memoryCard();
|
||||
final IComparableDefinition maybeColorApplicator = items.colorApplicator();
|
||||
final BlockPos pos = new BlockPos(this.x, this.y, this.z);
|
||||
if (this.leftClick) {
|
||||
final Block block = player.world.getBlockState(pos).getBlock();
|
||||
if (block instanceof BlockCableBus) {
|
||||
((BlockCableBus) block).onBlockClickPacket(player.world, pos, player, this.hand, new Vec3d(this.hitX, this.hitY, this.hitZ));
|
||||
}
|
||||
} else {
|
||||
if (!is.isEmpty()) {
|
||||
if (is.getItem() instanceof ToolNetworkTool) {
|
||||
final ToolNetworkTool tnt = (ToolNetworkTool) is.getItem();
|
||||
tnt.serverSideToolLogic(is, player, this.hand, player.world, pos, this.side, this.hitX, this.hitY,
|
||||
this.hitZ);
|
||||
} else if (maybeMemoryCard.isSameAs(is)) {
|
||||
final IMemoryCard mem = (IMemoryCard) is.getItem();
|
||||
mem.notifyUser(player, MemoryCardMessages.SETTINGS_CLEARED);
|
||||
is.setTagCompound(null);
|
||||
} else if (maybeColorApplicator.isSameAs(is)) {
|
||||
final ToolColorApplicator mem = (ToolColorApplicator) is.getItem();
|
||||
mem.cycleColors(is, mem.getColor(is), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.core.sync.network.INetworkInfo;
|
||||
import appeng.parts.PartPlacement;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
|
||||
public class PacketPartPlacement extends AppEngPacket {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private int face;
|
||||
private float eyeHeight;
|
||||
private EnumHand hand;
|
||||
|
||||
// automatic.
|
||||
public PacketPartPlacement(final ByteBuf stream) {
|
||||
this.x = stream.readInt();
|
||||
this.y = stream.readInt();
|
||||
this.z = stream.readInt();
|
||||
this.face = stream.readByte();
|
||||
this.eyeHeight = stream.readFloat();
|
||||
this.hand = EnumHand.values()[stream.readByte()];
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketPartPlacement(final BlockPos pos, final EnumFacing face, final float eyeHeight, final EnumHand hand) {
|
||||
final ByteBuf data = Unpooled.buffer();
|
||||
|
||||
data.writeInt(this.getPacketID());
|
||||
data.writeInt(pos.getX());
|
||||
data.writeInt(pos.getY());
|
||||
data.writeInt(pos.getZ());
|
||||
data.writeByte(face.ordinal());
|
||||
data.writeFloat(eyeHeight);
|
||||
data.writeByte(hand.ordinal());
|
||||
|
||||
this.configureWrite(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverPacketData(final INetworkInfo manager, final AppEngPacket packet, final EntityPlayer player) {
|
||||
final EntityPlayerMP sender = (EntityPlayerMP) player;
|
||||
AppEng.proxy.updateRenderMode(sender);
|
||||
PartPlacement.setEyeHeight(this.eyeHeight);
|
||||
PartPlacement.place(sender.getHeldItem(this.hand), new BlockPos(this.x, this.y, this.z), EnumFacing.VALUES[this.face], sender, this.hand,
|
||||
sender.world,
|
||||
PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0);
|
||||
AppEng.proxy.updateRenderMode(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user