Implements opening containers from items with and without a block context.
This commit is contained in:
@@ -47,10 +47,7 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.DyeColor;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
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)) {
|
||||
NetworkHandler.instance()
|
||||
.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;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid GUI target given: " + te);
|
||||
}
|
||||
}
|
||||
|
||||
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.DimensionalCoord;
|
||||
import appeng.parts.AEBasePart;
|
||||
import appeng.parts.misc.PartInterface;
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.netty.handler.codec.DecoderException;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
|
||||
/**
|
||||
* Describes how a container the player has opened was originally
|
||||
@@ -47,7 +47,16 @@ import org.apache.commons.lang3.NotImplementedException;
|
||||
public final class ContainerLocator {
|
||||
|
||||
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,
|
||||
PART
|
||||
}
|
||||
@@ -82,9 +91,38 @@ public final class ContainerLocator {
|
||||
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?
|
||||
throw new IllegalStateException();
|
||||
/**
|
||||
* Construct a container locator for an item being used on a block. The item could still open a container
|
||||
* 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) {
|
||||
@@ -100,11 +138,11 @@ public final class ContainerLocator {
|
||||
}
|
||||
|
||||
public boolean hasItemIndex() {
|
||||
return type == Type.ITEM;
|
||||
return type == Type.PLAYER_INVENTORY || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT;
|
||||
}
|
||||
|
||||
public int getItemIndex() {
|
||||
Preconditions.checkState(type == Type.ITEM);
|
||||
Preconditions.checkState(hasItemIndex());
|
||||
return itemIndex;
|
||||
}
|
||||
|
||||
@@ -113,36 +151,43 @@ public final class ContainerLocator {
|
||||
}
|
||||
|
||||
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() {
|
||||
Preconditions.checkState(type == Type.BLOCK || type == Type.PART);
|
||||
Preconditions.checkState(hasBlockPos());
|
||||
return blockPos;
|
||||
}
|
||||
|
||||
public boolean hasSide() {
|
||||
return type == Type.PART;
|
||||
return type == Type.PART || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT;
|
||||
}
|
||||
|
||||
public AEPartLocation getSide() {
|
||||
Preconditions.checkState(type == Type.PART);
|
||||
Preconditions.checkState(hasSide());
|
||||
return side;
|
||||
}
|
||||
|
||||
public void write(PacketBuffer buf) {
|
||||
switch (type) {
|
||||
case ITEM:
|
||||
case PLAYER_INVENTORY:
|
||||
buf.writeByte(0);
|
||||
buf.writeInt(itemIndex);
|
||||
break;
|
||||
case BLOCK:
|
||||
case PLAYER_INVENTORY_WITH_BLOCK_CONTEXT:
|
||||
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.writeBlockPos(blockPos);
|
||||
break;
|
||||
case PART:
|
||||
buf.writeByte(2);
|
||||
buf.writeByte(3);
|
||||
buf.writeInt(dimensionId);
|
||||
buf.writeBlockPos(blockPos);
|
||||
buf.writeByte(side.ordinal());
|
||||
@@ -157,13 +202,21 @@ public final class ContainerLocator {
|
||||
switch (type) {
|
||||
case 0:
|
||||
return new ContainerLocator(
|
||||
Type.ITEM,
|
||||
Type.PLAYER_INVENTORY,
|
||||
buf.readInt(),
|
||||
-1,
|
||||
null,
|
||||
null
|
||||
);
|
||||
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(
|
||||
Type.BLOCK,
|
||||
-1,
|
||||
@@ -171,7 +224,7 @@ public final class ContainerLocator {
|
||||
buf.readBlockPos(),
|
||||
null
|
||||
);
|
||||
case 2:
|
||||
case 3:
|
||||
return new ContainerLocator(
|
||||
Type.PART,
|
||||
-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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+72
-16
@@ -1,26 +1,30 @@
|
||||
package appeng.container.helper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.api.networking.security.ISecurityGrid;
|
||||
import appeng.api.features.IWirelessTermHandler;
|
||||
import appeng.api.implementations.guiobjects.IGuiItem;
|
||||
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.core.AELog;
|
||||
import appeng.helpers.ICustomNameObject;
|
||||
import appeng.helpers.WirelessTerminalGuiObject;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.inventory.container.SimpleNamedContainerProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
/**
|
||||
@@ -29,18 +33,17 @@ import net.minecraftforge.fml.network.NetworkHooks;
|
||||
*
|
||||
* @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 PartOrTileContainerHelper<C extends AEBaseContainer, I> extends AbstractContainerHelper {
|
||||
public final class ContainerHelper<C extends AEBaseContainer, I> extends AbstractContainerHelper {
|
||||
|
||||
private final Class<I> interfaceClass;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public PartOrTileContainerHelper(ContainerFactory<C, I> factory, Class<I> interfaceClass, SecurityPermissions requiredPermission) {
|
||||
public ContainerHelper(ContainerFactory<C, I> factory, Class<I> interfaceClass, SecurityPermissions requiredPermission) {
|
||||
super(requiredPermission);
|
||||
this.interfaceClass = interfaceClass;
|
||||
this.factory = factory;
|
||||
@@ -75,10 +78,7 @@ public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> exten
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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)
|
||||
ITextComponent title = player.world.getBlockState(locator.getBlockPos()).getBlock().getNameTextComponent();
|
||||
ITextComponent title = findContainerTitle(player.world, locator, accessInterface);
|
||||
|
||||
INamedContainerProvider container = new SimpleNamedContainerProvider(
|
||||
(wnd, p, pl) -> {
|
||||
@@ -94,7 +94,31 @@ public final class PartOrTileContainerHelper<C extends AEBaseContainer, I> exten
|
||||
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) {
|
||||
if (locator.hasItemIndex()) {
|
||||
return getHostFromPlayerInventory(player, locator);
|
||||
}
|
||||
|
||||
if (!locator.hasBlockPos() || !locator.hasSide()) {
|
||||
return null; // No block was clicked or the side is unknown
|
||||
// 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)) {
|
||||
return interfaceClass.cast(part);
|
||||
} 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);
|
||||
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
|
||||
public interface ContainerFactory<C, I> {
|
||||
C create(int windowId, PlayerInventory playerInv, I accessObj);
|
||||
@@ -22,7 +22,7 @@ package appeng.container.implementations;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
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.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
@@ -47,8 +47,8 @@ public class ContainerCraftAmount extends AEBaseContainer
|
||||
|
||||
public static ContainerType<ContainerCraftAmount> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerCraftAmount, ITerminalHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerCraftAmount::new, ITerminalHost.class, SecurityPermissions.CRAFT);
|
||||
private static final ContainerHelper<ContainerCraftAmount, ITerminalHost> helper
|
||||
= new ContainerHelper<>(ContainerCraftAmount::new, ITerminalHost.class, SecurityPermissions.CRAFT);
|
||||
|
||||
private final Slot craftingItem;
|
||||
private IAEItemStack itemToCreate;
|
||||
|
||||
@@ -39,8 +39,7 @@ import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.helper.PartOrTileContainerHelper;
|
||||
import appeng.container.helper.TileContainerHelper;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
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.IContainerListener;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -73,8 +71,8 @@ public class ContainerCraftConfirm extends AEBaseContainer
|
||||
|
||||
public static ContainerType<ContainerCraftConfirm> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerCraftConfirm, ITerminalHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerCraftConfirm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
|
||||
private static final ContainerHelper<ContainerCraftConfirm, ITerminalHost> helper
|
||||
= new ContainerHelper<>(ContainerCraftConfirm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
|
||||
|
||||
public static ContainerCraftConfirm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -25,8 +25,7 @@ import java.util.List;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.helper.PartOrTileContainerHelper;
|
||||
import appeng.container.helper.TileContainerHelper;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -46,8 +45,8 @@ public class ContainerCraftingStatus extends ContainerCraftingCPU
|
||||
|
||||
public static ContainerType<ContainerCraftingStatus> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerCraftingStatus, ITerminalHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerCraftingStatus::new, ITerminalHost.class, SecurityPermissions.CRAFT);
|
||||
private static final ContainerHelper<ContainerCraftingStatus, ITerminalHost> helper
|
||||
= new ContainerHelper<>(ContainerCraftingStatus::new, ITerminalHost.class, SecurityPermissions.CRAFT);
|
||||
|
||||
public static ContainerCraftingStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -21,8 +21,7 @@ package appeng.container.implementations;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.helper.PartOrTileContainerHelper;
|
||||
import appeng.container.helper.TileContainerHelper;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -53,8 +52,8 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE
|
||||
|
||||
public static ContainerType<ContainerCraftingTerm> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerCraftingTerm, ITerminalHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerCraftingTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
|
||||
private static final ContainerHelper<ContainerCraftingTerm, ITerminalHost> helper
|
||||
= new ContainerHelper<>(ContainerCraftingTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
|
||||
|
||||
public static ContainerCraftingTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -20,7 +20,7 @@ package appeng.container.implementations;
|
||||
|
||||
|
||||
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.PlayerInventory;
|
||||
|
||||
@@ -43,8 +43,8 @@ public class ContainerInterface extends ContainerUpgradeable
|
||||
|
||||
public static ContainerType<ContainerInterface> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerInterface, IInterfaceHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerInterface::new, IInterfaceHost.class, SecurityPermissions.BUILD);
|
||||
private static final ContainerHelper<ContainerInterface, IInterfaceHost> helper
|
||||
= new ContainerHelper<>(ContainerInterface::new, IInterfaceHost.class, SecurityPermissions.BUILD);
|
||||
|
||||
public static ContainerInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -24,8 +24,9 @@ import java.nio.BufferOverflowException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
||||
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.ServerPlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
@@ -82,8 +83,8 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
|
||||
|
||||
public static ContainerType<ContainerMEMonitorable> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerMEMonitorable, ITerminalHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerMEMonitorable::new, ITerminalHost.class);
|
||||
private static final ContainerHelper<ContainerMEMonitorable, ITerminalHost> helper
|
||||
= new ContainerHelper<>(ContainerMEMonitorable::new, ITerminalHost.class);
|
||||
|
||||
public static ContainerMEMonitorable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
@@ -116,7 +117,8 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
|
||||
id,
|
||||
ip,
|
||||
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.clientCM = new ConfigManager( this );
|
||||
@@ -166,7 +168,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
|
||||
final IGrid g = node.getGrid();
|
||||
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.helper.PartOrTileContainerHelper;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
@@ -38,8 +38,8 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable
|
||||
|
||||
public static ContainerType<ContainerMEPortableCell> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerMEPortableCell, IPortableCell> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerMEPortableCell::new, IPortableCell.class);
|
||||
private static final ContainerHelper<ContainerMEPortableCell, IPortableCell> helper
|
||||
= new ContainerHelper<>(ContainerMEPortableCell::new, IPortableCell.class);
|
||||
|
||||
public static ContainerMEPortableCell fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -22,8 +22,7 @@ package appeng.container.implementations;
|
||||
import java.io.IOException;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.helper.PartOrTileContainerHelper;
|
||||
import appeng.container.helper.TileContainerHelper;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
@@ -55,8 +54,8 @@ public class ContainerNetworkStatus extends AEBaseContainer
|
||||
|
||||
public static ContainerType<ContainerNetworkStatus> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerNetworkStatus, INetworkTool> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerNetworkStatus::new, INetworkTool.class);
|
||||
private static final ContainerHelper<ContainerNetworkStatus, INetworkTool> helper
|
||||
= new ContainerHelper<>(ContainerNetworkStatus::new, INetworkTool.class);
|
||||
|
||||
public static ContainerNetworkStatus fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -23,8 +23,7 @@ import appeng.api.implementations.guiobjects.INetworkTool;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.helper.PartOrTileContainerHelper;
|
||||
import appeng.container.helper.TileContainerHelper;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
@@ -39,8 +38,8 @@ public class ContainerNetworkTool extends AEBaseContainer
|
||||
|
||||
public static ContainerType<ContainerNetworkTool> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerNetworkTool, INetworkTool> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerNetworkTool::new, INetworkTool.class);
|
||||
private static final ContainerHelper<ContainerNetworkTool, INetworkTool> helper
|
||||
= new ContainerHelper<>(ContainerNetworkTool::new, INetworkTool.class);
|
||||
|
||||
public static ContainerNetworkTool fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -31,8 +31,7 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.helper.PartOrTileContainerHelper;
|
||||
import appeng.container.helper.TileContainerHelper;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import appeng.container.slot.*;
|
||||
import appeng.core.sync.packets.PacketPatternSlot;
|
||||
import appeng.helpers.IContainerCraftingPacket;
|
||||
@@ -77,8 +76,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
|
||||
|
||||
public static ContainerType<ContainerPatternTerm> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerPatternTerm, ITerminalHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerPatternTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
|
||||
private static final ContainerHelper<ContainerPatternTerm, ITerminalHost> helper
|
||||
= new ContainerHelper<>(ContainerPatternTerm::new, ITerminalHost.class, SecurityPermissions.CRAFT);
|
||||
|
||||
public static ContainerPatternTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -20,7 +20,7 @@ package appeng.container.implementations;
|
||||
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.helper.PartOrTileContainerHelper;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
@@ -43,8 +43,8 @@ public class ContainerPriority extends AEBaseContainer
|
||||
|
||||
public static ContainerType<ContainerPriority> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerPriority, IPriorityHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerPriority::new, IPriorityHost.class, SecurityPermissions.BUILD);
|
||||
private static final ContainerHelper<ContainerPriority, IPriorityHost> helper
|
||||
= new ContainerHelper<>(ContainerPriority::new, IPriorityHost.class, SecurityPermissions.BUILD);
|
||||
|
||||
public static ContainerPriority fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -22,7 +22,7 @@ package appeng.container.implementations;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
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.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
@@ -47,8 +47,8 @@ public class ContainerQuartzKnife extends AEBaseContainer
|
||||
|
||||
public static ContainerType<ContainerQuartzKnife> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerQuartzKnife, QuartzKnifeObj> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerQuartzKnife::new, QuartzKnifeObj.class);
|
||||
private static final ContainerHelper<ContainerQuartzKnife, QuartzKnifeObj> helper
|
||||
= new ContainerHelper<>(ContainerQuartzKnife::new, QuartzKnifeObj.class);
|
||||
|
||||
public static ContainerQuartzKnife fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -20,8 +20,7 @@ package appeng.container.implementations;
|
||||
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.helper.PartOrTileContainerHelper;
|
||||
import appeng.container.helper.TileContainerHelper;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
@@ -50,8 +49,8 @@ public class ContainerSecurityStation extends ContainerMEMonitorable implements
|
||||
|
||||
public static ContainerType<ContainerSecurityStation> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerSecurityStation, ITerminalHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerSecurityStation::new, ITerminalHost.class, SecurityPermissions.SECURITY);
|
||||
private static final ContainerHelper<ContainerSecurityStation, ITerminalHost> helper
|
||||
= new ContainerHelper<>(ContainerSecurityStation::new, ITerminalHost.class, SecurityPermissions.SECURITY);
|
||||
|
||||
private final SlotRestrictedInput configSlot;
|
||||
|
||||
|
||||
@@ -20,20 +20,15 @@ package appeng.container.implementations;
|
||||
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.helper.PartContainerHelper;
|
||||
import appeng.container.helper.PartOrTileContainerHelper;
|
||||
import appeng.parts.misc.PartStorageBus;
|
||||
import appeng.tile.misc.TileCellWorkbench;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
@@ -66,8 +61,8 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl
|
||||
|
||||
public static ContainerType<ContainerUpgradeable> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerUpgradeable, IUpgradeableHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerUpgradeable::new, IUpgradeableHost.class, SecurityPermissions.BUILD);
|
||||
private static final ContainerHelper<ContainerUpgradeable, IUpgradeableHost> helper
|
||||
= new ContainerHelper<>(ContainerUpgradeable::new, IUpgradeableHost.class, SecurityPermissions.BUILD);
|
||||
|
||||
public static ContainerUpgradeable fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
@@ -130,7 +125,7 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl
|
||||
{
|
||||
this.lockPlayerInventorySlot( 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ package appeng.container.implementations;
|
||||
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.helper.PartContainerHelper;
|
||||
import appeng.container.helper.PartOrTileContainerHelper;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
|
||||
@@ -38,8 +37,8 @@ public class ContainerWirelessTerm extends ContainerMEPortableCell
|
||||
|
||||
public static ContainerType<ContainerWirelessTerm> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerWirelessTerm, WirelessTerminalGuiObject> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerWirelessTerm::new, WirelessTerminalGuiObject.class);
|
||||
private static final ContainerHelper<ContainerWirelessTerm, WirelessTerminalGuiObject> helper
|
||||
= new ContainerHelper<>(ContainerWirelessTerm::new, WirelessTerminalGuiObject.class);
|
||||
|
||||
public static ContainerWirelessTerm fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -116,7 +116,7 @@ public final class WirelessRegistry implements IWirelessTermRegistry
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -485,11 +471,6 @@ public enum GuiBridge
|
||||
final ItemStack it = player.inventory.getCurrentItem();
|
||||
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;
|
||||
|
||||
|
||||
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.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.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerNetworkTool;
|
||||
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.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;
|
||||
|
||||
|
||||
@@ -76,8 +79,19 @@ public class PacketClick extends AppEngPacket
|
||||
this.leftClick = stream.readBoolean();
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketClick( final BlockPos pos, final Direction side, final float hitX, final float hitY, final float hitZ, final Hand hand )
|
||||
// API for when a block was right clicked
|
||||
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 );
|
||||
}
|
||||
@@ -108,14 +122,21 @@ public class PacketClick extends AppEngPacket
|
||||
this.configureWrite( data );
|
||||
}
|
||||
|
||||
// Indicates that block pos, side and hit vector have valid data
|
||||
private boolean hasBlockContext() {
|
||||
return side != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
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 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();
|
||||
@@ -131,8 +152,14 @@ public class PacketClick extends AppEngPacket
|
||||
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 );
|
||||
|
||||
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 ) )
|
||||
|
||||
@@ -23,7 +23,7 @@ import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.helper.PartOrTileContainerHelper;
|
||||
import appeng.container.helper.ContainerHelper;
|
||||
import appeng.fluids.helper.DualityFluidInterface;
|
||||
import appeng.fluids.helper.FluidSyncHelper;
|
||||
import appeng.fluids.helper.IFluidInterfaceHost;
|
||||
@@ -44,8 +44,8 @@ public class ContainerFluidInterface extends ContainerFluidConfigurable
|
||||
|
||||
public static ContainerType<ContainerFluidInterface> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerFluidInterface, IFluidInterfaceHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerFluidInterface::new, IFluidInterfaceHost.class, SecurityPermissions.BUILD);
|
||||
private static final ContainerHelper<ContainerFluidInterface, IFluidInterfaceHost> helper
|
||||
= new ContainerHelper<>(ContainerFluidInterface::new, IFluidInterfaceHost.class, SecurityPermissions.BUILD);
|
||||
|
||||
public static ContainerFluidInterface fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
return helper.fromNetwork(windowId, inv, buf);
|
||||
|
||||
@@ -26,7 +26,7 @@ import javax.annotation.Nonnull;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.*;
|
||||
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.PlayerInventory;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
@@ -82,8 +82,8 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
|
||||
|
||||
public static ContainerType<ContainerFluidTerminal> TYPE;
|
||||
|
||||
private static final PartOrTileContainerHelper<ContainerFluidTerminal, ITerminalHost> helper
|
||||
= new PartOrTileContainerHelper<>(ContainerFluidTerminal::new, ITerminalHost.class, SecurityPermissions.BUILD);
|
||||
private static final ContainerHelper<ContainerFluidTerminal, ITerminalHost> helper
|
||||
= new ContainerHelper<>(ContainerFluidTerminal::new, ITerminalHost.class, SecurityPermissions.BUILD);
|
||||
|
||||
public static ContainerFluidTerminal fromNetwork(int windowId, PlayerInventory inv, PacketBuffer 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 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.effectiveItem = is;
|
||||
this.myPlayer = ep;
|
||||
this.wth = wh;
|
||||
this.inventorySlot = x;
|
||||
this.inventorySlot = inventorySlot;
|
||||
|
||||
ILocatable obj = null;
|
||||
|
||||
|
||||
@@ -67,8 +67,11 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench
|
||||
}
|
||||
|
||||
@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 );
|
||||
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 )
|
||||
{
|
||||
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() )
|
||||
{
|
||||
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;
|
||||
@@ -130,59 +133,58 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench
|
||||
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 );
|
||||
if( !p.isCrouching() )
|
||||
final BlockState bs = w.getBlockState( pos );
|
||||
if( !p.isCrouching() )
|
||||
{
|
||||
final TileEntity te = w.getTileEntity( pos );
|
||||
if( !( te instanceof IGridHost ) )
|
||||
{
|
||||
final TileEntity te = w.getTileEntity( pos );
|
||||
if( !( te instanceof IGridHost ) )
|
||||
if( bs.rotate( w, pos, Rotation.CLOCKWISE_90 ) != bs )
|
||||
{
|
||||
if( bs.rotate( w, pos, Rotation.CLOCKWISE_90 ) != bs )
|
||||
{
|
||||
bs.neighborChanged( w, pos, Platform.AIR_BLOCK, pos, false );
|
||||
p.swingArm( hand );
|
||||
return !w.isRemote;
|
||||
}
|
||||
bs.neighborChanged( w, pos, Platform.AIR_BLOCK, pos, false );
|
||||
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;
|
||||
}
|
||||
|
||||
final TileEntity te = w.getTileEntity( pos );
|
||||
|
||||
if( te instanceof IGridHost )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerNetworkStatus.TYPE, p, ContainerLocator.forItemUseContext(useContext));
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockRayTraceResult rtr = new BlockRayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos, false);
|
||||
bs.onBlockActivated( w, p, hand, rtr );
|
||||
ContainerOpener.openContainer(ContainerNetworkTool.TYPE, p, ContainerLocator.forHand(p, hand));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell<
|
||||
@Override
|
||||
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 ) );
|
||||
}
|
||||
|
||||
@@ -183,9 +183,9 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell<
|
||||
}
|
||||
|
||||
@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
|
||||
|
||||
@@ -19,12 +19,17 @@
|
||||
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.ContainerOpener;
|
||||
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.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
@@ -33,13 +38,6 @@ import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
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
|
||||
{
|
||||
@@ -54,9 +52,10 @@ public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
@@ -66,7 +65,7 @@ public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, p, ContainerLocator.forHand(hand));
|
||||
ContainerOpener.openContainer(ContainerQuartzKnife.TYPE, p, ContainerLocator.forHand(p, hand));
|
||||
}
|
||||
p.swingArm( hand );
|
||||
return new ActionResult<>( ActionResultType.SUCCESS, p.getHeldItem( hand ) );
|
||||
@@ -94,7 +93,7 @@ public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
|
||||
}
|
||||
|
||||
@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 );
|
||||
}
|
||||
|
||||
@@ -432,7 +432,7 @@ public class PartPlacement
|
||||
|
||||
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() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user