use of net.minecraftforge.items.IItemHandler in project BetterWithAddons by DaedalusGame.
the class TileEntityChute method attemptToEjectStackFromInv.
private void attemptToEjectStackFromInv(boolean powered) {
int stackIndex = InventoryUtil.getFirstOccupiedStackInRange(inventory, 0, 17);
if (stackIndex > -1 && stackIndex < 18) {
ItemStack invStack = inventory.getStackInSlot(stackIndex);
int ejectStackSize = 1;
ItemStack ejectStack = new ItemStack(invStack.getItem(), ejectStackSize, invStack.getItemDamage());
InventoryUtil.copyTags(ejectStack, invStack);
BlockPos ejectpos = pos.offset(ejectDir);
boolean ejectIntoWorld = false;
if (!getOutputBlocked(ejectDir))
if (this.getWorld().isAirBlock(ejectpos))
ejectIntoWorld = true;
else if (this.getWorld().getBlockState(ejectpos).getBlock().isReplaceable(this.getWorld(), ejectpos))
ejectIntoWorld = true;
else {
Block block = this.getWorld().getBlockState(ejectpos).getBlock();
if (block == null || (!world.isSideSolid(ejectpos, ejectDir.getOpposite())) && (this.getWorld().getTileEntity(ejectpos) == null || !(this.getWorld().getTileEntity(ejectpos).hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, ejectDir.getOpposite()))))
ejectIntoWorld = true;
else if (powered) {
TileEntity tile = this.getWorld().getTileEntity(ejectpos);
if (tile != null && tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, ejectDir.getOpposite())) {
IItemHandler below = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, ejectDir.getOpposite());
ItemStack leftover;
for (int slot = 0; slot < below.getSlots(); slot++) {
leftover = below.insertItem(slot, ejectStack, false);
if (leftover.isEmpty()) {
inventory.extractItem(stackIndex, ejectStackSize, false);
break;
}
}
} else
setOutputBlocked(ejectDir, true);
} else {
setOutputBlocked(ejectDir, true);
}
}
if (ejectIntoWorld) {
ejectStack(ejectStack, ejectDir);
inventory.extractItem(stackIndex, ejectStackSize, false);
}
rotateToNextOutput(powered, world.rand);
}
}
use of net.minecraftforge.items.IItemHandler in project Almura by AlmuraDev.
the class CapabilityDualItemHandlerGuiHandler method getServerGuiElement.
@Nullable
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
final TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
if (te == null || !(te instanceof MultiSlotTileEntity)) {
return null;
}
final IItemHandler teItemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (teItemHandler == null) {
return null;
}
final IItemHandler playerItemHandler = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (playerItemHandler == null) {
return null;
}
return new DualItemHandlerContainer(teItemHandler, playerItemHandler);
}
Aggregations