Implements opening containers from items with and without a block context.

This commit is contained in:
Sebastian Hartte
2020-06-14 21:23:42 +02:00
parent bdd522e8d9
commit d43e8d19dd
30 changed files with 342 additions and 204 deletions
@@ -28,6 +28,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nullable;
/** /**
* Implemented on Item objects, to return objects used to manage, and interact * Implemented on Item objects, to return objects used to manage, and interact
@@ -35,6 +37,14 @@ import net.minecraft.world.World;
*/ */
public interface IGuiItem public interface IGuiItem
{ {
/**
IGuiItemObject getGuiObject( ItemStack is, World world, BlockPos pos ); *
* @param is The item used to open the container.
* @param playerInventorySlot The slot in the player's inventory the item is in.
* @param world The world the player is in.
* @param pos If the item was used on a block in the world, has that block's position. Null if no block was targetted.
* @return Null if no GUI object is available.
*/
@Nullable
IGuiItemObject getGuiObject( ItemStack is, int playerInventorySlot, World world, @Nullable BlockPos pos );
} }
@@ -47,10 +47,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.IFluidState; import net.minecraft.fluid.IFluidState;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.*;
import net.minecraft.item.DyeColor;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.state.BooleanProperty; import net.minecraft.state.BooleanProperty;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType; import net.minecraft.util.ActionResultType;
@@ -312,7 +309,7 @@ public class BlockCableBus extends AEBaseTileBlock<TileCableBus> /* FIXME implem
if (this.cb(worldIn, pos).clicked(player, Hand.MAIN_HAND, hitVec)) { if (this.cb(worldIn, pos).clicked(player, Hand.MAIN_HAND, hitVec)) {
NetworkHandler.instance() NetworkHandler.instance()
.sendToServer( .sendToServer(
new PacketClick(pos, ((BlockRayTraceResult) rtr).getFace(), (float) hitVec.x, (float) hitVec.y, (float) hitVec.z, Hand.MAIN_HAND, true)); new PacketClick(pos, brtr.getFace(), (float) hitVec.x, (float) hitVec.y, (float) hitVec.z, Hand.MAIN_HAND, true));
} }
} }
} }
@@ -139,6 +139,10 @@ public class GuiMEMonitorable<T extends ContainerMEMonitorable> extends AEBaseME
{ {
this.myName = GuiText.Terminal; this.myName = GuiText.Terminal;
} }
else
{
throw new IllegalArgumentException("Invalid GUI target given: " + te);
}
} }
public void postUpdate( final List<IAEItemStack> list ) public void postUpdate( final List<IAEItemStack> list )
@@ -23,16 +23,16 @@ import appeng.api.parts.IPartHost;
import appeng.api.util.AEPartLocation; import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord; import appeng.api.util.DimensionalCoord;
import appeng.parts.AEBasePart; import appeng.parts.AEBasePart;
import appeng.parts.misc.PartInterface;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.DecoderException;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.apache.commons.lang3.NotImplementedException;
/** /**
* Describes how a container the player has opened was originally * Describes how a container the player has opened was originally
@@ -47,7 +47,16 @@ import org.apache.commons.lang3.NotImplementedException;
public final class ContainerLocator { public final class ContainerLocator {
private enum Type { private enum Type {
ITEM, /**
* An item used from the player's inventory.
*/
PLAYER_INVENTORY,
/**
* An item used from the player's inventory, but right-clicked
* on a block face, has block position and side in addition to the
* above.
*/
PLAYER_INVENTORY_WITH_BLOCK_CONTEXT,
BLOCK, BLOCK,
PART PART
} }
@@ -82,9 +91,38 @@ public final class ContainerLocator {
return new ContainerLocator(Type.PART, -1, dimensionId, te.getPos(), AEPartLocation.fromFacing(side)); return new ContainerLocator(Type.PART, -1, dimensionId, te.getPos(), AEPartLocation.fromFacing(side));
} }
public static ContainerLocator forHand(Hand hand) { /**
// FIXME can we get an inventory location for the hand? * Construct a container locator for an item being used on a block. The item could still open a container
throw new IllegalStateException(); * for itself, but it might also open a special container for the block being right-clicked.
*/
public static ContainerLocator forItemUseContext(ItemUseContext context) {
PlayerEntity player = context.getPlayer();
if (player == null) {
throw new IllegalArgumentException("Cannot open a container without a player");
}
int dimensionId = player.world.getDimension().getType().getId();
int slot = getPlayerInventorySlotFromHand(player, context.getHand());
AEPartLocation side = AEPartLocation.fromFacing(context.getFace());
return new ContainerLocator(Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, slot, dimensionId, context.getPos(), side);
}
public static ContainerLocator forHand(PlayerEntity player, Hand hand) {
int slot = getPlayerInventorySlotFromHand(player, hand);
return new ContainerLocator(Type.PLAYER_INVENTORY, slot, -1, null, null);
}
private static int getPlayerInventorySlotFromHand(PlayerEntity player, Hand hand) {
ItemStack is = player.getHeldItem(hand);
if (is.isEmpty()) {
throw new IllegalArgumentException("Cannot open an item-inventory with empty hands");
}
int invSize = player.inventory.getSizeInventory();
for (int i = 0; i < invSize; i++) {
if (player.inventory.getStackInSlot(i) == is) {
return i;
}
}
throw new IllegalArgumentException("Could not find item held in hand " + hand + " in player inventory");
} }
public static ContainerLocator forPart(AEBasePart part) { public static ContainerLocator forPart(AEBasePart part) {
@@ -100,11 +138,11 @@ public final class ContainerLocator {
} }
public boolean hasItemIndex() { public boolean hasItemIndex() {
return type == Type.ITEM; return type == Type.PLAYER_INVENTORY || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT;
} }
public int getItemIndex() { public int getItemIndex() {
Preconditions.checkState(type == Type.ITEM); Preconditions.checkState(hasItemIndex());
return itemIndex; return itemIndex;
} }
@@ -113,36 +151,43 @@ public final class ContainerLocator {
} }
public boolean hasBlockPos() { public boolean hasBlockPos() {
return type == Type.BLOCK || type == Type.PART; return type == Type.BLOCK || type == Type.PART || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT;
} }
public BlockPos getBlockPos() { public BlockPos getBlockPos() {
Preconditions.checkState(type == Type.BLOCK || type == Type.PART); Preconditions.checkState(hasBlockPos());
return blockPos; return blockPos;
} }
public boolean hasSide() { public boolean hasSide() {
return type == Type.PART; return type == Type.PART || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT;
} }
public AEPartLocation getSide() { public AEPartLocation getSide() {
Preconditions.checkState(type == Type.PART); Preconditions.checkState(hasSide());
return side; return side;
} }
public void write(PacketBuffer buf) { public void write(PacketBuffer buf) {
switch (type) { switch (type) {
case ITEM: case PLAYER_INVENTORY:
buf.writeByte(0); buf.writeByte(0);
buf.writeInt(itemIndex); buf.writeInt(itemIndex);
break; break;
case BLOCK: case PLAYER_INVENTORY_WITH_BLOCK_CONTEXT:
buf.writeByte(1); buf.writeByte(1);
buf.writeInt(itemIndex);
buf.writeInt(dimensionId);
buf.writeBlockPos(blockPos);
buf.writeByte(side.ordinal());
break;
case BLOCK:
buf.writeByte(22);
buf.writeInt(dimensionId); buf.writeInt(dimensionId);
buf.writeBlockPos(blockPos); buf.writeBlockPos(blockPos);
break; break;
case PART: case PART:
buf.writeByte(2); buf.writeByte(3);
buf.writeInt(dimensionId); buf.writeInt(dimensionId);
buf.writeBlockPos(blockPos); buf.writeBlockPos(blockPos);
buf.writeByte(side.ordinal()); buf.writeByte(side.ordinal());
@@ -157,13 +202,21 @@ public final class ContainerLocator {
switch (type) { switch (type) {
case 0: case 0:
return new ContainerLocator( return new ContainerLocator(
Type.ITEM, Type.PLAYER_INVENTORY,
buf.readInt(), buf.readInt(),
-1, -1,
null, null,
null null
); );
case 1: case 1:
return new ContainerLocator(
Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT,
buf.readInt(),
buf.readInt(),
buf.readBlockPos(),
AEPartLocation.values()[buf.readByte()]
);
case 2:
return new ContainerLocator( return new ContainerLocator(
Type.BLOCK, Type.BLOCK,
-1, -1,
@@ -171,7 +224,7 @@ public final class ContainerLocator {
buf.readBlockPos(), buf.readBlockPos(),
null null
); );
case 2: case 3:
return new ContainerLocator( return new ContainerLocator(
Type.PART, Type.PART,
-1, -1,
@@ -184,4 +237,25 @@ public final class ContainerLocator {
} }
} }
@Override
public String toString() {
StringBuilder result = new StringBuilder(type.name());
result.append('{');
if (hasItemIndex()) {
result.append("slot=").append(itemIndex).append(',');
}
if (hasBlockPos()) {
result.append("dim=").append(dimensionId).append(',');
result.append("pos=").append(blockPos).append(',');
}
if (hasSide()) {
result.append("side=").append(side).append(',');
}
if (result.charAt(result.length() - 1) == ',') {
result.setLength(result.length() - 1);
}
result.append('}');
return result.toString();
}
} }
@@ -1,26 +1,30 @@
package appeng.container.helper; package appeng.container.helper;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions; import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid; import appeng.api.features.IWirelessTermHandler;
import appeng.api.networking.IGridNode; import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.networking.energy.IEnergyGrid; import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.parts.IPart; import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost; import appeng.api.parts.IPartHost;
import appeng.container.AEBaseContainer; import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.core.AELog; import appeng.core.AELog;
import appeng.helpers.ICustomNameObject;
import appeng.helpers.WirelessTerminalGuiObject;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.inventory.container.SimpleNamedContainerProvider; import net.minecraft.inventory.container.SimpleNamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.fml.network.NetworkHooks;
/** /**
@@ -29,18 +33,17 @@ import net.minecraftforge.fml.network.NetworkHooks;
* *
* @param <C> * @param <C>
*/ */
// FIXME: This is also used in contexts where access is via an item that implements I or exposes I via IGuiItemObject public final class ContainerHelper<C extends AEBaseContainer, I> extends AbstractContainerHelper {
public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> extends AbstractContainerHelper {
private final Class<I> interfaceClass; private final Class<I> interfaceClass;
private final ContainerFactory<C, I> factory; private final ContainerFactory<C, I> factory;
public PartOrTileContainerHelper(ContainerFactory<C, I> factory, Class<I> interfaceClass) { public ContainerHelper(ContainerFactory<C, I> factory, Class<I> interfaceClass) {
this(factory, interfaceClass, null); this(factory, interfaceClass, null);
} }
public PartOrTileContainerHelper(ContainerFactory<C, I> factory, Class<I> interfaceClass, SecurityPermissions requiredPermission) { public ContainerHelper(ContainerFactory<C, I> factory, Class<I> interfaceClass, SecurityPermissions requiredPermission) {
super(requiredPermission); super(requiredPermission);
this.interfaceClass = interfaceClass; this.interfaceClass = interfaceClass;
this.factory = factory; this.factory = factory;
@@ -75,10 +78,7 @@ public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> exten
return false; return false;
} }
// Use block name at position ITextComponent title = findContainerTitle(player.world, locator, accessInterface);
// FIXME: this is not right, we'd need to check the part's item stack, or custom naming interface impl
// FIXME: Should move this up, because at this point, it's hard to know where the terminal host came from (part or tile)
ITextComponent title = player.world.getBlockState(locator.getBlockPos()).getBlock().getNameTextComponent();
INamedContainerProvider container = new SimpleNamedContainerProvider( INamedContainerProvider container = new SimpleNamedContainerProvider(
(wnd, p, pl) -> { (wnd, p, pl) -> {
@@ -94,7 +94,31 @@ public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> exten
return true; return true;
} }
private ITextComponent findContainerTitle(World world, ContainerLocator locator, I accessInterface) {
if (accessInterface instanceof ICustomNameObject) {
ICustomNameObject customNameObject = (ICustomNameObject) accessInterface;
if (customNameObject.hasCustomInventoryName()) {
return customNameObject.getCustomInventoryName();
}
}
// Use block name at position
// FIXME: this is not right, we'd need to check the part's item stack, or custom naming interface impl
// FIXME: Should move this up, because at this point, it's hard to know where the terminal host came from (part or tile)
if (locator.hasBlockPos()) {
return world.getBlockState(locator.getBlockPos()).getBlock().getNameTextComponent();
}
return new StringTextComponent("Unknown");
}
private I getHostFromLocator(PlayerEntity player, ContainerLocator locator) { private I getHostFromLocator(PlayerEntity player, ContainerLocator locator) {
if (locator.hasItemIndex()) {
return getHostFromPlayerInventory(player, locator);
}
if (!locator.hasBlockPos() || !locator.hasSide()) { if (!locator.hasBlockPos() || !locator.hasSide()) {
return null; // No block was clicked or the side is unknown return null; // No block was clicked or the side is unknown
// FIXME: If no side is provided, should be try with INTERNAL??? // FIXME: If no side is provided, should be try with INTERNAL???
@@ -116,7 +140,7 @@ public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> exten
if (interfaceClass.isInstance(part)) { if (interfaceClass.isInstance(part)) {
return interfaceClass.cast(part); return interfaceClass.cast(part);
} else { } else {
AELog.debug("Trying to open a container @ {} for a {}, but the container requires {}", AELog.debug("Trying to open a container @ %s for a %s, but the container requires %s",
locator, part.getClass(), interfaceClass); locator, part.getClass(), interfaceClass);
return null; return null;
} }
@@ -126,6 +150,38 @@ public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> exten
} }
} }
private I getHostFromPlayerInventory(PlayerEntity player, ContainerLocator locator) {
ItemStack it = player.inventory.getStackInSlot(locator.getItemIndex());
if (it.isEmpty()) {
AELog.debug("Cannot open container for player %s since they no longer hold the item in slot %d",
player, locator.hasItemIndex());
return null;
}
if ( it.getItem() instanceof IGuiItem )
{
IGuiItem guiItem = (IGuiItem) it.getItem();
// Optionally contains the block the item was used on to open the container
BlockPos blockPos = locator.hasBlockPos() ? locator.getBlockPos() : null;
IGuiItemObject guiObject = guiItem.getGuiObject(it, locator.getItemIndex(), player.world, blockPos);
if (interfaceClass.isInstance(guiObject)) {
return interfaceClass.cast(guiObject);
}
}
if( interfaceClass.isAssignableFrom(WirelessTerminalGuiObject.class) )
{
final IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler( it );
if ( wh != null) {
return interfaceClass.cast(new WirelessTerminalGuiObject(wh, it, player, locator.getItemIndex()));
}
}
return null;
}
@FunctionalInterface @FunctionalInterface
public interface ContainerFactory<C, I> { public interface ContainerFactory<C, I> {
C create(int windowId, PlayerInventory playerInv, I accessObj); C create(int windowId, PlayerInventory playerInv, I accessObj);
@@ -22,7 +22,7 @@ package appeng.container.implementations;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
@@ -47,8 +47,8 @@ public class ContainerCraftAmount extends AEBaseContainer
public static ContainerType<ContainerCraftAmount> TYPE; public static ContainerType<ContainerCraftAmount> TYPE;
private static final PartOrTileContainerHelper<ContainerCraftAmount, ITerminalHost> helper private static final ContainerHelper<ContainerCraftAmount, ITerminalHost> helper
= new PartOrTileContainerHelper<>(ContainerCraftAmount::new, ITerminalHost.class, SecurityPermissions.CRAFT); = new ContainerHelper<>(ContainerCraftAmount::new, ITerminalHost.class, SecurityPermissions.CRAFT);
private final Slot craftingItem; private final Slot craftingItem;
private IAEItemStack itemToCreate; private IAEItemStack itemToCreate;
@@ -39,8 +39,7 @@ import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener; import appeng.container.ContainerOpener;
import appeng.container.guisync.GuiSync; import appeng.container.guisync.GuiSync;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import appeng.container.helper.TileContainerHelper;
import appeng.core.AELog; import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate; import appeng.core.sync.packets.PacketMEInventoryUpdate;
@@ -57,7 +56,6 @@ import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.IContainerListener; import net.minecraft.inventory.container.IContainerListener;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
@@ -73,8 +71,8 @@ public class ContainerCraftConfirm extends AEBaseContainer
public static ContainerType<ContainerCraftConfirm> TYPE; public static ContainerType<ContainerCraftConfirm> TYPE;
private static final PartOrTileContainerHelper<ContainerCraftConfirm, ITerminalHost> helper private static final ContainerHelper<ContainerCraftConfirm, ITerminalHost> helper
= new PartOrTileContainerHelper<>(ContainerCraftConfirm::new, ITerminalHost.class, SecurityPermissions.CRAFT); = new ContainerHelper<>(ContainerCraftConfirm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static ContainerCraftConfirm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerCraftConfirm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -25,8 +25,7 @@ import java.util.List;
import appeng.api.config.SecurityPermissions; import appeng.api.config.SecurityPermissions;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import appeng.container.helper.TileContainerHelper;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@@ -46,8 +45,8 @@ public class ContainerCraftingStatus extends ContainerCraftingCPU
public static ContainerType<ContainerCraftingStatus> TYPE; public static ContainerType<ContainerCraftingStatus> TYPE;
private static final PartOrTileContainerHelper<ContainerCraftingStatus, ITerminalHost> helper private static final ContainerHelper<ContainerCraftingStatus, ITerminalHost> helper
= new PartOrTileContainerHelper<>(ContainerCraftingStatus::new, ITerminalHost.class, SecurityPermissions.CRAFT); = new ContainerHelper<>(ContainerCraftingStatus::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static ContainerCraftingStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerCraftingStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -21,8 +21,7 @@ package appeng.container.implementations;
import appeng.api.config.SecurityPermissions; import appeng.api.config.SecurityPermissions;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import appeng.container.helper.TileContainerHelper;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
@@ -53,8 +52,8 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE
public static ContainerType<ContainerCraftingTerm> TYPE; public static ContainerType<ContainerCraftingTerm> TYPE;
private static final PartOrTileContainerHelper<ContainerCraftingTerm, ITerminalHost> helper private static final ContainerHelper<ContainerCraftingTerm, ITerminalHost> helper
= new PartOrTileContainerHelper<>(ContainerCraftingTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT); = new ContainerHelper<>(ContainerCraftingTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static ContainerCraftingTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerCraftingTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -20,7 +20,7 @@ package appeng.container.implementations;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@@ -43,8 +43,8 @@ public class ContainerInterface extends ContainerUpgradeable
public static ContainerType<ContainerInterface> TYPE; public static ContainerType<ContainerInterface> TYPE;
private static final PartOrTileContainerHelper<ContainerInterface, IInterfaceHost> helper private static final ContainerHelper<ContainerInterface, IInterfaceHost> helper
= new PartOrTileContainerHelper<>(ContainerInterface::new, IInterfaceHost.class, SecurityPermissions.BUILD); = new ContainerHelper<>(ContainerInterface::new, IInterfaceHost.class, SecurityPermissions.BUILD);
public static ContainerInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -24,8 +24,9 @@ import java.nio.BufferOverflowException;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@@ -82,8 +83,8 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
public static ContainerType<ContainerMEMonitorable> TYPE; public static ContainerType<ContainerMEMonitorable> TYPE;
private static final PartOrTileContainerHelper<ContainerMEMonitorable, ITerminalHost> helper private static final ContainerHelper<ContainerMEMonitorable, ITerminalHost> helper
= new PartOrTileContainerHelper<>(ContainerMEMonitorable::new, ITerminalHost.class); = new ContainerHelper<>(ContainerMEMonitorable::new, ITerminalHost.class);
public static ContainerMEMonitorable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerMEMonitorable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -116,7 +117,8 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
id, id,
ip, ip,
monitorable instanceof TileEntity ? (TileEntity) monitorable : null, monitorable instanceof TileEntity ? (TileEntity) monitorable : null,
monitorable instanceof IPart ? (IPart) monitorable : null ); monitorable instanceof IPart ? (IPart) monitorable : null,
monitorable instanceof IGuiItemObject ? (IGuiItemObject) monitorable : null);
this.host = monitorable; this.host = monitorable;
this.clientCM = new ConfigManager( this ); this.clientCM = new ConfigManager( this );
@@ -166,7 +168,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
final IGrid g = node.getGrid(); final IGrid g = node.getGrid();
if( g != null ) if( g != null )
{ {
this.setPowerSource( new ChannelPowerSrc( this.networkNode, (IEnergySource) g.getCache( IEnergyGrid.class ) ) ); this.setPowerSource( new ChannelPowerSrc( this.networkNode, g.getCache( IEnergyGrid.class )) );
} }
} }
} }
@@ -20,7 +20,7 @@ package appeng.container.implementations;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
@@ -38,8 +38,8 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable
public static ContainerType<ContainerMEPortableCell> TYPE; public static ContainerType<ContainerMEPortableCell> TYPE;
private static final PartOrTileContainerHelper<ContainerMEPortableCell, IPortableCell> helper private static final ContainerHelper<ContainerMEPortableCell, IPortableCell> helper
= new PartOrTileContainerHelper<>(ContainerMEPortableCell::new, IPortableCell.class); = new ContainerHelper<>(ContainerMEPortableCell::new, IPortableCell.class);
public static ContainerMEPortableCell fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerMEPortableCell fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -22,8 +22,7 @@ package appeng.container.implementations;
import java.io.IOException; import java.io.IOException;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import appeng.container.helper.TileContainerHelper;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@@ -55,8 +54,8 @@ public class ContainerNetworkStatus extends AEBaseContainer
public static ContainerType<ContainerNetworkStatus> TYPE; public static ContainerType<ContainerNetworkStatus> TYPE;
private static final PartOrTileContainerHelper<ContainerNetworkStatus, INetworkTool> helper private static final ContainerHelper<ContainerNetworkStatus, INetworkTool> helper
= new PartOrTileContainerHelper<>(ContainerNetworkStatus::new, INetworkTool.class); = new ContainerHelper<>(ContainerNetworkStatus::new, INetworkTool.class);
public static ContainerNetworkStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerNetworkStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -23,8 +23,7 @@ import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.container.AEBaseContainer; import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync; import appeng.container.guisync.GuiSync;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import appeng.container.helper.TileContainerHelper;
import appeng.container.slot.SlotRestrictedInput; import appeng.container.slot.SlotRestrictedInput;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@@ -39,8 +38,8 @@ public class ContainerNetworkTool extends AEBaseContainer
public static ContainerType<ContainerNetworkTool> TYPE; public static ContainerType<ContainerNetworkTool> TYPE;
private static final PartOrTileContainerHelper<ContainerNetworkTool, INetworkTool> helper private static final ContainerHelper<ContainerNetworkTool, INetworkTool> helper
= new PartOrTileContainerHelper<>(ContainerNetworkTool::new, INetworkTool.class); = new ContainerHelper<>(ContainerNetworkTool::new, INetworkTool.class);
public static ContainerNetworkTool fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerNetworkTool fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -31,8 +31,7 @@ import appeng.api.storage.data.IItemList;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.ContainerNull; import appeng.container.ContainerNull;
import appeng.container.guisync.GuiSync; import appeng.container.guisync.GuiSync;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import appeng.container.helper.TileContainerHelper;
import appeng.container.slot.*; import appeng.container.slot.*;
import appeng.core.sync.packets.PacketPatternSlot; import appeng.core.sync.packets.PacketPatternSlot;
import appeng.helpers.IContainerCraftingPacket; import appeng.helpers.IContainerCraftingPacket;
@@ -77,8 +76,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
public static ContainerType<ContainerPatternTerm> TYPE; public static ContainerType<ContainerPatternTerm> TYPE;
private static final PartOrTileContainerHelper<ContainerPatternTerm, ITerminalHost> helper private static final ContainerHelper<ContainerPatternTerm, ITerminalHost> helper
= new PartOrTileContainerHelper<>(ContainerPatternTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT); = new ContainerHelper<>(ContainerPatternTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
public static ContainerPatternTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerPatternTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -20,7 +20,7 @@ package appeng.container.implementations;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@@ -43,8 +43,8 @@ public class ContainerPriority extends AEBaseContainer
public static ContainerType<ContainerPriority> TYPE; public static ContainerType<ContainerPriority> TYPE;
private static final PartOrTileContainerHelper<ContainerPriority, IPriorityHost> helper private static final ContainerHelper<ContainerPriority, IPriorityHost> helper
= new PartOrTileContainerHelper<>(ContainerPriority::new, IPriorityHost.class, SecurityPermissions.BUILD); = new ContainerHelper<>(ContainerPriority::new, IPriorityHost.class, SecurityPermissions.BUILD);
public static ContainerPriority fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerPriority fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -22,7 +22,7 @@ package appeng.container.implementations;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
@@ -47,8 +47,8 @@ public class ContainerQuartzKnife extends AEBaseContainer
public static ContainerType<ContainerQuartzKnife> TYPE; public static ContainerType<ContainerQuartzKnife> TYPE;
private static final PartOrTileContainerHelper<ContainerQuartzKnife, QuartzKnifeObj> helper private static final ContainerHelper<ContainerQuartzKnife, QuartzKnifeObj> helper
= new PartOrTileContainerHelper<>(ContainerQuartzKnife::new, QuartzKnifeObj.class); = new ContainerHelper<>(ContainerQuartzKnife::new, QuartzKnifeObj.class);
public static ContainerQuartzKnife fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerQuartzKnife fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -20,8 +20,7 @@ package appeng.container.implementations;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import appeng.container.helper.TileContainerHelper;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
@@ -50,8 +49,8 @@ public class ContainerSecurityStation extends ContainerMEMonitorable implements
public static ContainerType<ContainerSecurityStation> TYPE; public static ContainerType<ContainerSecurityStation> TYPE;
private static final PartOrTileContainerHelper<ContainerSecurityStation, ITerminalHost> helper private static final ContainerHelper<ContainerSecurityStation, ITerminalHost> helper
= new PartOrTileContainerHelper<>(ContainerSecurityStation::new, ITerminalHost.class, SecurityPermissions.SECURITY); = new ContainerHelper<>(ContainerSecurityStation::new, ITerminalHost.class, SecurityPermissions.SECURITY);
private final SlotRestrictedInput configSlot; private final SlotRestrictedInput configSlot;
@@ -20,20 +20,15 @@ package appeng.container.implementations;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartContainerHelper; import appeng.container.helper.ContainerHelper;
import appeng.container.helper.PartOrTileContainerHelper;
import appeng.parts.misc.PartStorageBus;
import appeng.tile.misc.TileCellWorkbench;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
@@ -66,8 +61,8 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl
public static ContainerType<ContainerUpgradeable> TYPE; public static ContainerType<ContainerUpgradeable> TYPE;
private static final PartOrTileContainerHelper<ContainerUpgradeable, IUpgradeableHost> helper private static final ContainerHelper<ContainerUpgradeable, IUpgradeableHost> helper
= new PartOrTileContainerHelper<>(ContainerUpgradeable::new, IUpgradeableHost.class, SecurityPermissions.BUILD); = new ContainerHelper<>(ContainerUpgradeable::new, IUpgradeableHost.class, SecurityPermissions.BUILD);
public static ContainerUpgradeable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerUpgradeable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -130,7 +125,7 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl
{ {
this.lockPlayerInventorySlot( x ); this.lockPlayerInventorySlot( x );
this.tbSlot = x; this.tbSlot = x;
this.tbInventory = (NetworkToolViewer) ( (IGuiItem) pii.getItem() ).getGuiObject( pii, w, new BlockPos( xCoord, yCoord, zCoord ) ); this.tbInventory = (NetworkToolViewer) ( (IGuiItem) pii.getItem() ).getGuiObject( pii, x, w, new BlockPos( xCoord, yCoord, zCoord ) );
break; break;
} }
} }
@@ -20,8 +20,7 @@ package appeng.container.implementations;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartContainerHelper; import appeng.container.helper.ContainerHelper;
import appeng.container.helper.PartOrTileContainerHelper;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@@ -38,8 +37,8 @@ public class ContainerWirelessTerm extends ContainerMEPortableCell
public static ContainerType<ContainerWirelessTerm> TYPE; public static ContainerType<ContainerWirelessTerm> TYPE;
private static final PartOrTileContainerHelper<ContainerWirelessTerm, WirelessTerminalGuiObject> helper private static final ContainerHelper<ContainerWirelessTerm, WirelessTerminalGuiObject> helper
= new PartOrTileContainerHelper<>(ContainerWirelessTerm::new, WirelessTerminalGuiObject.class); = new ContainerHelper<>(ContainerWirelessTerm::new, WirelessTerminalGuiObject.class);
public static ContainerWirelessTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerWirelessTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -116,7 +116,7 @@ public final class WirelessRegistry implements IWirelessTermRegistry
if( handler.hasPower( player, 0.5, item ) ) if( handler.hasPower( player, 0.5, item ) )
{ {
ContainerOpener.openContainer(ContainerWirelessTerm.TYPE, player, ContainerLocator.forHand(hand)); ContainerOpener.openContainer(ContainerWirelessTerm.TYPE, player, ContainerLocator.forHand(player, hand));
} }
else else
{ {
@@ -307,20 +307,6 @@ public enum GuiBridge
private Object getGuiObject( final ItemStack it, final PlayerEntity player, final World w, final int x, final int y, final int z ) private Object getGuiObject( final ItemStack it, final PlayerEntity player, final World w, final int x, final int y, final int z )
{ {
if( !it.isEmpty() )
{
if( it.getItem() instanceof IGuiItem )
{
return ( (IGuiItem) it.getItem() ).getGuiObject( it, w, new BlockPos( x, y, z ) );
}
final IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler( it );
if( wh != null )
{
return new WirelessTerminalGuiObject( wh, it, player, w, x, y, z );
}
}
return null; return null;
} }
@@ -485,11 +471,6 @@ public enum GuiBridge
final ItemStack it = player.inventory.getCurrentItem(); final ItemStack it = player.inventory.getCurrentItem();
if( !it.isEmpty() && it.getItem() instanceof IGuiItem ) if( !it.isEmpty() && it.getItem() instanceof IGuiItem )
{ {
final Object myItem = ( (IGuiItem) it.getItem() ).getGuiObject( it, w, pos );
if( this.CorrectTileOrPart( myItem ) )
{
return true;
}
} }
} }
@@ -19,26 +19,29 @@
package appeng.core.sync.packets; package appeng.core.sync.packets;
import appeng.block.networking.BlockCableBus;
import appeng.items.tools.ToolNetworkTool;
import appeng.items.tools.powered.ToolColorApplicator;
import io.netty.buffer.Unpooled;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.definitions.IComparableDefinition; import appeng.api.definitions.IComparableDefinition;
import appeng.api.definitions.IItems; import appeng.api.definitions.IItems;
import appeng.api.implementations.items.IMemoryCard; import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages; import appeng.api.implementations.items.MemoryCardMessages;
import appeng.block.networking.BlockCableBus;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.ContainerNetworkTool;
import appeng.core.sync.AppEngPacket; import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo; import appeng.core.sync.network.INetworkInfo;
import appeng.items.tools.ToolNetworkTool;
import appeng.items.tools.powered.ToolColorApplicator;
import io.netty.buffer.Unpooled;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@@ -76,8 +79,19 @@ public class PacketClick extends AppEngPacket
this.leftClick = stream.readBoolean(); this.leftClick = stream.readBoolean();
} }
// api // API for when a block was right clicked
public PacketClick( final BlockPos pos, final Direction side, final float hitX, final float hitY, final float hitZ, final Hand hand ) public PacketClick( ItemUseContext context )
{
this(context.getPos(), context.getFace(), context.getPos().getX(), context.getPos().getY(), context.getPos().getZ(), context.getHand());
}
// API for when an item in hand was right-clicked, with no block context
public PacketClick( Hand hand )
{
this(BlockPos.ZERO, null, 0, 0, 0, hand);
}
private PacketClick( final BlockPos pos, final Direction side, final float hitX, final float hitY, final float hitZ, final Hand hand )
{ {
this( pos, side, hitX, hitY, hitZ, hand, false ); this( pos, side, hitX, hitY, hitZ, hand, false );
} }
@@ -108,14 +122,21 @@ public class PacketClick extends AppEngPacket
this.configureWrite( data ); this.configureWrite( data );
} }
// Indicates that block pos, side and hit vector have valid data
private boolean hasBlockContext() {
return side != null;
}
@Override @Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player ) public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{ {
final ItemStack is = player.inventory.getCurrentItem(); final BlockPos pos = new BlockPos( this.x, this.y, this.z );
final ItemStack is = player.getHeldItem(hand);
final IItems items = AEApi.instance().definitions().items(); final IItems items = AEApi.instance().definitions().items();
final IComparableDefinition maybeMemoryCard = items.memoryCard(); final IComparableDefinition maybeMemoryCard = items.memoryCard();
final IComparableDefinition maybeColorApplicator = items.colorApplicator(); final IComparableDefinition maybeColorApplicator = items.colorApplicator();
final BlockPos pos = new BlockPos( this.x, this.y, this.z );
if( this.leftClick ) if( this.leftClick )
{ {
final Block block = player.world.getBlockState( pos ).getBlock(); final Block block = player.world.getBlockState( pos ).getBlock();
@@ -131,8 +152,14 @@ public class PacketClick extends AppEngPacket
if( is.getItem() instanceof ToolNetworkTool) if( is.getItem() instanceof ToolNetworkTool)
{ {
final ToolNetworkTool tnt = (ToolNetworkTool) is.getItem(); final ToolNetworkTool tnt = (ToolNetworkTool) is.getItem();
tnt.serverSideToolLogic( is, player, this.hand, player.world, pos, this.side, this.hitX, this.hitY,
this.hitZ ); if (hasBlockContext()) {
// Reconstruct an item use context
ItemUseContext useContext = new ItemUseContext(player, hand, new BlockRayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos, false));
tnt.serverSideToolLogic(useContext);
} else {
ContainerOpener.openContainer(ContainerNetworkTool.TYPE, player, ContainerLocator.forHand(player, hand));
}
} }
if( maybeMemoryCard.isSameAs( is ) ) if( maybeMemoryCard.isSameAs( is ) )
@@ -23,7 +23,7 @@ import appeng.api.config.SecurityPermissions;
import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEFluidStack;
import appeng.api.util.IConfigManager; import appeng.api.util.IConfigManager;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import appeng.fluids.helper.DualityFluidInterface; import appeng.fluids.helper.DualityFluidInterface;
import appeng.fluids.helper.FluidSyncHelper; import appeng.fluids.helper.FluidSyncHelper;
import appeng.fluids.helper.IFluidInterfaceHost; import appeng.fluids.helper.IFluidInterfaceHost;
@@ -44,8 +44,8 @@ public class ContainerFluidInterface extends ContainerFluidConfigurable
public static ContainerType<ContainerFluidInterface> TYPE; public static ContainerType<ContainerFluidInterface> TYPE;
private static final PartOrTileContainerHelper<ContainerFluidInterface, IFluidInterfaceHost> helper private static final ContainerHelper<ContainerFluidInterface, IFluidInterfaceHost> helper
= new PartOrTileContainerHelper<>(ContainerFluidInterface::new, IFluidInterfaceHost.class, SecurityPermissions.BUILD); = new ContainerHelper<>(ContainerFluidInterface::new, IFluidInterfaceHost.class, SecurityPermissions.BUILD);
public static ContainerFluidInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerFluidInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -26,7 +26,7 @@ import javax.annotation.Nonnull;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.*; import appeng.api.config.*;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.helper.PartOrTileContainerHelper; import appeng.container.helper.ContainerHelper;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
@@ -82,8 +82,8 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
public static ContainerType<ContainerFluidTerminal> TYPE; public static ContainerType<ContainerFluidTerminal> TYPE;
private static final PartOrTileContainerHelper<ContainerFluidTerminal, ITerminalHost> helper private static final ContainerHelper<ContainerFluidTerminal, ITerminalHost> helper
= new PartOrTileContainerHelper<>(ContainerFluidTerminal::new, ITerminalHost.class, SecurityPermissions.BUILD); = new ContainerHelper<>(ContainerFluidTerminal::new, ITerminalHost.class, SecurityPermissions.BUILD);
public static ContainerFluidTerminal fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) { public static ContainerFluidTerminal fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
return helper.fromNetwork(windowId, inv, buf); return helper.fromNetwork(windowId, inv, buf);
@@ -65,13 +65,13 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost, II
private double myRange = Double.MAX_VALUE; private double myRange = Double.MAX_VALUE;
private final int inventorySlot; private final int inventorySlot;
public WirelessTerminalGuiObject( final IWirelessTermHandler wh, final ItemStack is, final PlayerEntity ep, final World w, final int x, final int y, final int z ) public WirelessTerminalGuiObject( final IWirelessTermHandler wh, final ItemStack is, final PlayerEntity ep, int inventorySlot )
{ {
this.encryptionKey = wh.getEncryptionKey( is ); this.encryptionKey = wh.getEncryptionKey( is );
this.effectiveItem = is; this.effectiveItem = is;
this.myPlayer = ep; this.myPlayer = ep;
this.wth = wh; this.wth = wh;
this.inventorySlot = x; this.inventorySlot = inventorySlot;
ILocatable obj = null; ILocatable obj = null;
@@ -67,8 +67,11 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench
} }
@Override @Override
public IGuiItemObject getGuiObject( final ItemStack is, final World world, final BlockPos pos ) public IGuiItemObject getGuiObject( final ItemStack is, int playerInventorySlot, final World world, final BlockPos pos )
{ {
if (pos == null) {
return new NetworkToolViewer( is, null );
}
final TileEntity te = world.getTileEntity( pos ); final TileEntity te = world.getTileEntity( pos );
return new NetworkToolViewer( is, (IGridHost) ( te instanceof IGridHost ? te : null ) ); return new NetworkToolViewer( is, (IGridHost) ( te instanceof IGridHost ? te : null ) );
} }
@@ -82,7 +85,7 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench
if( mop == null || mop.getType() == RayTraceResult.Type.MISS ) if( mop == null || mop.getType() == RayTraceResult.Type.MISS )
{ {
NetworkHandler.instance().sendToServer( new PacketClick( BlockPos.ZERO, null, 0, 0, 0, hand ) ); NetworkHandler.instance().sendToServer( new PacketClick( hand ) );
} }
} }
@@ -118,7 +121,7 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench
if( Platform.isClient() ) if( Platform.isClient() )
{ {
NetworkHandler.instance().sendToServer( new PacketClick( context.getPos(), context.getFace(), context.getPos().getX(), context.getPos().getY(), context.getPos().getZ(), context.getHand() ) ); NetworkHandler.instance().sendToServer( new PacketClick( context ) );
} }
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
@@ -130,59 +133,58 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench
return true; return true;
} }
public boolean serverSideToolLogic( final ItemStack is, final PlayerEntity p, final Hand hand, final World w, final BlockPos pos, final Direction side, final float hitX, final float hitY, final float hitZ ) public boolean serverSideToolLogic( ItemUseContext useContext )
{ {
if( side != null ) BlockPos pos = useContext.getPos();
PlayerEntity p = useContext.getPlayer();
World w = p.world;
Hand hand = useContext.getHand();
Direction side = useContext.getFace();
if( !Platform.hasPermissions( new DimensionalCoord( w, pos ), p ) )
{ {
if( !Platform.hasPermissions( new DimensionalCoord( w, pos ), p ) ) return false;
{ }
return false;
}
final BlockState bs = w.getBlockState( pos ); final BlockState bs = w.getBlockState( pos );
if( !p.isCrouching() ) if( !p.isCrouching() )
{
final TileEntity te = w.getTileEntity( pos );
if( !( te instanceof IGridHost ) )
{ {
final TileEntity te = w.getTileEntity( pos ); if( bs.rotate( w, pos, Rotation.CLOCKWISE_90 ) != bs )
if( !( te instanceof IGridHost ) )
{ {
if( bs.rotate( w, pos, Rotation.CLOCKWISE_90 ) != bs ) bs.neighborChanged( w, pos, Platform.AIR_BLOCK, pos, false );
{ p.swingArm( hand );
bs.neighborChanged( w, pos, Platform.AIR_BLOCK, pos, false ); return !w.isRemote;
p.swingArm( hand );
return !w.isRemote;
}
} }
} }
}
if( !p.isCrouching() ) if( !p.isCrouching() )
{
if( p.openContainer instanceof AEBaseContainer )
{ {
if( p.openContainer instanceof AEBaseContainer )
{
return true;
}
final TileEntity te = w.getTileEntity( pos );
if( te instanceof IGridHost )
{
ContainerOpener.openContainer(ContainerNetworkStatus.TYPE, p, ContainerLocator.forTileEntitySide(te, side));
}
else
{
ContainerOpener.openContainer(ContainerNetworkTool.TYPE, p, ContainerLocator.forHand(hand));
}
return true; return true;
} }
final TileEntity te = w.getTileEntity( pos );
if( te instanceof IGridHost )
{
ContainerOpener.openContainer(ContainerNetworkStatus.TYPE, p, ContainerLocator.forItemUseContext(useContext));
}
else else
{ {
BlockRayTraceResult rtr = new BlockRayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos, false); ContainerOpener.openContainer(ContainerNetworkTool.TYPE, p, ContainerLocator.forHand(p, hand));
bs.onBlockActivated( w, p, hand, rtr );
} }
return true;
} }
else else
{ {
ContainerOpener.openContainer(ContainerNetworkTool.TYPE, p, ContainerLocator.forHand(hand)); BlockRayTraceResult rtr = new BlockRayTraceResult(useContext.getHitVec(), side, pos, false);
bs.onBlockActivated( w, p, hand, rtr );
} }
return false; return false;
@@ -71,7 +71,7 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell<
@Override @Override
public ActionResult<ItemStack> onItemRightClick( final World w, final PlayerEntity player, final Hand hand ) public ActionResult<ItemStack> onItemRightClick( final World w, final PlayerEntity player, final Hand hand )
{ {
ContainerOpener.openContainer(ContainerMEPortableCell.TYPE, player, ContainerLocator.forHand(hand)); ContainerOpener.openContainer(ContainerMEPortableCell.TYPE, player, ContainerLocator.forHand(player, hand));
return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) ); return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) );
} }
@@ -183,9 +183,9 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell<
} }
@Override @Override
public IGuiItemObject getGuiObject( final ItemStack is, final World w, final BlockPos pos ) public IGuiItemObject getGuiObject( final ItemStack is, int playerInventorySlot, final World w, final BlockPos pos )
{ {
return new PortableCellViewer( is, pos.getX() ); return new PortableCellViewer( is, playerInventorySlot );
} }
@Override @Override
@@ -19,12 +19,17 @@
package appeng.items.tools.quartz; package appeng.items.tools.quartz;
import appeng.api.features.AEFeature;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.container.ContainerLocator; import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener; import appeng.container.ContainerOpener;
import appeng.container.implementations.ContainerQuartzKnife; import appeng.container.implementations.ContainerQuartzKnife;
import appeng.items.AEBaseItem;
import appeng.items.contents.QuartzKnifeObj;
import appeng.util.Platform;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext; import net.minecraft.item.ItemUseContext;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@@ -33,13 +38,6 @@ import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.features.AEFeature;
import appeng.items.AEBaseItem;
import appeng.items.contents.QuartzKnifeObj;
import appeng.util.Platform;
public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
{ {
@@ -54,9 +52,10 @@ public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
@Override @Override
public ActionResultType onItemUse(ItemUseContext context ) public ActionResultType onItemUse(ItemUseContext context )
{ {
if( Platform.isServer() ) PlayerEntity player = context.getPlayer();
if( Platform.isServer() && player != null )
{ {
ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, context.getPlayer(), ContainerLocator.forHand(context.getHand())); ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, context.getPlayer(), ContainerLocator.forItemUseContext(context));
} }
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }
@@ -66,7 +65,7 @@ public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
{ {
if( Platform.isServer() ) if( Platform.isServer() )
{ {
ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, p, ContainerLocator.forHand(hand)); ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, p, ContainerLocator.forHand(p, hand));
} }
p.swingArm( hand ); p.swingArm( hand );
return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) ); return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) );
@@ -94,7 +93,7 @@ public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
} }
@Override @Override
public IGuiItemObject getGuiObject( final ItemStack is, final World world, final BlockPos pos ) public IGuiItemObject getGuiObject( final ItemStack is, int playerInventorySlot, final World world, final BlockPos pos )
{ {
return new QuartzKnifeObj( is ); return new QuartzKnifeObj( is );
} }
@@ -432,7 +432,7 @@ public class PartPlacement
if( event.getPlayer().isCrouching() && !held.isEmpty() && supportedItem ) if( event.getPlayer().isCrouching() && !held.isEmpty() && supportedItem )
{ {
NetworkHandler.instance().sendToServer( new PacketClick( event.getPos(), event.getFace(), 0, 0, 0, event.getHand() ) ); NetworkHandler.instance().sendToServer( new PacketClick( event.getHand() ) );
} }
} }
} }