use of net.minecraftforge.items.IItemHandlerModifiable in project GregTech by GregTechCE.
the class ItemHandlerList method setStackInSlot.
@Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
IItemHandler itemHandler = handlerBySlotIndex.get(slot);
if (!(itemHandler instanceof IItemHandlerModifiable))
throw new UnsupportedOperationException("Handler " + itemHandler + " does not support this method");
((IItemHandlerModifiable) itemHandler).setStackInSlot(slot - baseIndexOffset.get(itemHandler), stack);
}
use of net.minecraftforge.items.IItemHandlerModifiable in project minecolonies by Minecolonies.
the class AbstractCombinedItemHandler method serializeNBT.
@SuppressWarnings(RAWTYPES)
@Override
public NBTTagCompound serializeNBT() {
final NBTTagCompound compound = new NBTTagCompound();
int index = 0;
final NBTTagList handlerList = new NBTTagList();
final NBTTagList indexList = new NBTTagList();
for (final IItemHandlerModifiable handlerModifiable : handlers) {
if (handlerModifiable instanceof INBTSerializable) {
final INBTSerializable serializable = (INBTSerializable) handlerModifiable;
handlerList.appendTag(serializable.serializeNBT());
indexList.appendTag(new NBTTagInt(index));
}
index++;
}
compound.setTag(NBT_KEY_HANDLERS, handlerList);
if (hasCustomName()) {
compound.setString(NBT_KEY_NAME, customName);
}
return compound;
}
use of net.minecraftforge.items.IItemHandlerModifiable 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);
}
use of net.minecraftforge.items.IItemHandlerModifiable in project BuildCraft by BuildCraft.
the class CombinedItemHandlerWrapper method getFilter.
@Override
public ItemStack getFilter(int slot) {
int index = getIndexForSlot(slot);
IItemHandlerModifiable handler = getHandlerFromIndex(index);
slot = getSlotFromIndex(slot, index);
if (handler instanceof IItemHandlerFiltered) {
return ((IItemHandlerFiltered) handler).getFilter(slot);
}
return handler.getStackInSlot(slot);
}
use of net.minecraftforge.items.IItemHandlerModifiable in project BuildCraft by BuildCraft.
the class ItemHandlerManager method addInvHandler.
public <T extends INBTSerializable<NBTTagCompound> & IItemHandlerModifiable> T addInvHandler(String key, T handler, EnumAccess access, EnumPipePart... parts) {
if (parts == null) {
parts = new EnumPipePart[0];
}
IItemHandlerModifiable external = handler;
if (access == EnumAccess.NONE || access == EnumAccess.PHANTOM) {
external = null;
if (parts.length > 0) {
throw new IllegalArgumentException("Completely useless to not allow access to multiple sides! Just don't pass any sides!");
}
} else if (access == EnumAccess.EXTRACT) {
external = new WrappedItemHandlerExtract(handler);
} else if (access == EnumAccess.INSERT) {
external = new WrappedItemHandlerInsert(handler);
}
if (external != null) {
Set<EnumPipePart> visited = EnumSet.noneOf(EnumPipePart.class);
for (EnumPipePart part : parts) {
if (part == null)
part = EnumPipePart.CENTER;
if (visited.add(part)) {
Wrapper wrapper = wrappers.get(part);
wrapper.handlers.add(external);
wrapper.genWrapper();
}
}
}
if (access != EnumAccess.PHANTOM) {
handlersToDrop.add(handler);
}
handlers.put(key, handler);
return handler;
}
Aggregations