Search in sources :

Example 1 with SlotPhantom

use of buildcraft.lib.gui.slot.SlotPhantom in project BuildCraft by BuildCraft.

the class ContainerBC_Neptune method readSingleSetPhantom.

private void readSingleSetPhantom(PacketBufferBC buffer, MessageContext ctx) throws IOException {
    int idx = buffer.readVarInt();
    ItemStack stack = buffer.readItemStack();
    if (idx >= 0 && idx < inventorySlots.size()) {
        Slot s = inventorySlots.get(idx);
        if (s instanceof SlotPhantom) {
            SlotPhantom ph = (SlotPhantom) s;
            IItemHandlerAdv handler = ph.itemHandler;
            if (handler instanceof IItemHandlerModifiable && handler.canSet(ph.handlerIndex, stack)) {
                ((IItemHandlerModifiable) handler).setStackInSlot(ph.handlerIndex, stack);
            } else {
                // log rather than throw an exception because of bugged/naughty clients
                String s2 = "[lib.container] Received an illegal phantom slot setting request! ";
                s2 += "[The item handler disallowed the replacement] (Client = ";
                s2 += ctx.getServerHandler().player.getName() + ", slot_index = " + idx;
                s2 += ", stack = " + stack + ")";
                BCLog.logger.warn(s2);
            }
            return;
        }
    }
    // log rather than throw an exception because of bugged/naughty clients
    String s2 = "[lib.container] Received an illegal phantom slot setting request! ";
    s2 += "[Didn't find a phantom slot for the given index] (Client = ";
    s2 += ctx.getServerHandler().player.getName() + ", slot_index = " + idx;
    s2 += ", stack = " + stack + ")";
    BCLog.logger.warn(s2);
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) SlotPhantom(buildcraft.lib.gui.slot.SlotPhantom) IPhantomSlot(buildcraft.lib.gui.slot.IPhantomSlot) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) IItemHandlerAdv(buildcraft.lib.tile.item.IItemHandlerAdv)

Aggregations

IPhantomSlot (buildcraft.lib.gui.slot.IPhantomSlot)1 SlotPhantom (buildcraft.lib.gui.slot.SlotPhantom)1 IItemHandlerAdv (buildcraft.lib.tile.item.IItemHandlerAdv)1 Slot (net.minecraft.inventory.Slot)1 ItemStack (net.minecraft.item.ItemStack)1 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)1