use of net.minecraftforge.items.IItemHandlerModifiable in project Metalworks by canitzp.
the class TileBase method writeCapabilities.
protected void writeCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side) {
IItemHandler inventory = this.getInventory(side);
if (inventory != null && inventory instanceof IItemHandlerModifiable) {
nbt.setTag("Inventory", CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(inventory, side));
}
IFluidHandler tank = getTank(side);
if (tank != null && tank instanceof IFluidTank) {
nbt.setTag("FluidTank", CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.writeNBT(tank, side));
}
IEnergyStorage energy = getEnergy(side);
if (energy != null && energy instanceof EnergyStorage) {
nbt.setTag("Energy", CapabilityEnergy.ENERGY.writeNBT(energy, side));
}
}
use of net.minecraftforge.items.IItemHandlerModifiable in project ImmersiveEngineering by BluSunrize.
the class ItemDrill method setHead.
public void setHead(ItemStack drill, ItemStack head) {
IItemHandler inv = drill.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
((IItemHandlerModifiable) inv).setStackInSlot(0, head);
}
use of net.minecraftforge.items.IItemHandlerModifiable in project ICBM-Classic by BuiltBrokenModding.
the class CapabilityEmpInventory method applyEmpAction.
@Override
public float applyEmpAction(World world, double x, double y, double z, IBlast emp_blast, float power, boolean doAction) {
final IItemHandlerModifiable iItemHandler = getCapability();
if (iItemHandler != null) {
// Loop items
for (int slotIndex = 0; slotIndex < iItemHandler.getSlots(); slotIndex++) {
final ItemStack slotStack = iItemHandler.getStackInSlot(slotIndex);
// Check to make sure its not a placeholder
if (!slotStack.isEmpty()) {
// Copy stack for editing
final ItemStack itemStack = slotStack.copy();
// Run call
power = empItemStack(itemStack, world, x, y, z, getHost(), emp_blast, power, doAction);
// Only apply changes if we are not simulating and there was a change in the stack
if (doAction && !InventoryUtility.stacksMatchExact(itemStack, slotStack)) {
try {
iItemHandler.setStackInSlot(slotIndex, itemStack);
} catch (// Safety check, just in case
RuntimeException e) {
ICBMClassic.logger().error("BlastEMP: Unexpected error while updating inventory item '" + itemStack + "' from slot '" + slotIndex + "' in '" + iItemHandler + "' contained in '" + getHost() + "' while running " + this, e);
}
}
}
}
}
return power;
}
use of net.minecraftforge.items.IItemHandlerModifiable in project MinecraftForge by MinecraftForge.
the class CombinedInvWrapper method getStackInSlot.
@Override
@Nonnull
public ItemStack getStackInSlot(int slot) {
int index = getIndexForSlot(slot);
IItemHandlerModifiable handler = getHandlerFromIndex(index);
slot = getSlotFromIndex(slot, index);
return handler.getStackInSlot(slot);
}
use of net.minecraftforge.items.IItemHandlerModifiable in project RecurrentComplex by Ivorforce.
the class ItemHandlers method complete.
public static CombinedInvWrapper complete(ICapabilityProvider provider) {
List<IItemHandlerModifiable> handlers = new ArrayList<>();
Arrays.stream(EnumFacing.VALUES).forEach(f -> {
if (provider.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, f)) {
IItemHandler capability = provider.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, f);
if (capability instanceof IItemHandlerModifiable)
handlers.add((IItemHandlerModifiable) capability);
}
});
return new CombinedInvWrapper(handlers.toArray(new IItemHandlerModifiable[0]));
}
Aggregations