use of net.minecraftforge.items.IItemHandler in project ImmersiveEngineering by BluSunrize.
the class Utils method canInsertStackIntoInventory.
public static boolean canInsertStackIntoInventory(TileEntity inventory, ItemStack stack, EnumFacing side) {
if (stack != null && inventory != null && inventory.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)) {
IItemHandler handler = inventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
ItemStack temp = ItemHandlerHelper.insertItem(handler, stack.copy(), true);
if (temp == null || temp.stackSize < stack.stackSize)
return true;
}
return false;
}
use of net.minecraftforge.items.IItemHandler in project VanillaTeleporter by dyeo.
the class BlockTeleporter method breakBlockRecall.
public void breakBlockRecall(World world, World nextWorld, BlockPos pos, BlockPos nextPos, IBlockState state, EntityPlayerMP player) {
TileEntityTeleporter tileEntityTeleporter = (TileEntityTeleporter) world.getTileEntity(pos);
if (tileEntityTeleporter != null) {
tileEntityTeleporter.removeFromNetwork();
if (tileEntityTeleporter.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
IItemHandler handler = tileEntityTeleporter.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
ItemStack stack = handler.getStackInSlot(0);
if (!stack.isEmpty()) {
InventoryHelper.spawnItemStack(nextWorld, nextPos.getX(), nextPos.getY() + 1, nextPos.getZ(), stack);
}
}
}
InventoryHelper.spawnItemStack(nextWorld, nextPos.getX(), nextPos.getY() + 1, nextPos.getZ(), new ItemStack(ModBlocks.TELEPORTER, 1, getMetaFromState(state)));
world.setBlockToAir(pos);
while (world.getTileEntity(pos) != null) {
world.removeTileEntity(pos);
}
}
use of net.minecraftforge.items.IItemHandler in project VanillaTeleporter by dyeo.
the class BlockTeleporter method breakBlock.
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
TileEntityTeleporter tileEntityTeleporter = (TileEntityTeleporter) world.getTileEntity(pos);
if (tileEntityTeleporter != null) {
tileEntityTeleporter.removeFromNetwork();
if (tileEntityTeleporter.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
IItemHandler handler = tileEntityTeleporter.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
ItemStack stack = handler.getStackInSlot(0);
if (!stack.isEmpty()) {
stack = stack.copy();
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), stack);
}
}
}
// super _must_ be called last because it removes the tile entity
super.breakBlock(world, pos, state);
}
use of net.minecraftforge.items.IItemHandler in project BetterWithAddons by DaedalusGame.
the class BlockWeight method measureBlock.
public int measureBlock(World world, BlockPos pos, IBlockState state) {
BlockPos checkpos = pos.up();
IBlockState checkstate = world.getBlockState(checkpos);
TileEntity te = world.getTileEntity(checkpos);
boolean isFull = true;
boolean isEmpty = true;
int delay = 20;
if (te != null) {
boolean foundAnyMeasurable = false;
for (EnumFacing facing : EnumFacing.VALUES) {
if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) {
IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
if (!InventoryUtil.isEmpty(inventory))
isEmpty = false;
if (!InventoryUtil.isFull(inventory))
isFull = false;
foundAnyMeasurable = true;
}
if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)) {
IFluidHandler tank = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing);
FluidStack fluid = tank.drain(Integer.MAX_VALUE, false);
if (fluid != null && tank.fill(fluid, false) > 0)
isFull = false;
if (fluid != null && fluid.amount != 0)
isEmpty = false;
foundAnyMeasurable = true;
}
}
if (foundAnyMeasurable)
delay = 1;
else
isFull = false;
} else if (SPECIAL_BEHAVIOR.containsKey(checkstate.getBlock())) {
ISpecialMeasuringBehavior behavior = SPECIAL_BEHAVIOR.get(checkstate.getBlock());
isEmpty = behavior.isEmpty(world, checkpos, checkstate);
isFull = behavior.isFull(world, checkpos, checkstate);
delay = behavior.getDelay(world, checkpos, checkstate);
} else {
isFull = false;
}
boolean active = decideActivity(isEmpty, isFull);
if (active != state.getValue(ACTIVE)) {
world.setBlockState(pos, state.withProperty(ACTIVE, active));
float f = active ? 0.6F : 0.5F;
world.playSound(null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 1.0F, f);
}
return delay;
}
use of net.minecraftforge.items.IItemHandler in project BetterWithAddons by DaedalusGame.
the class TileEntityAncestrySand method fillBottles.
public void fillBottles() {
IBlockState hopper = world.getBlockState(pos.down());
if (spirits <= InteractionEriottoMod.SPIRIT_PER_BOTTLE)
return;
if (hopper.getBlock() != BWMBlocks.SINGLE_MACHINES || hopper.getValue(BlockMechMachines.TYPE) != BlockMechMachines.EnumType.HOPPER)
return;
boolean isOn = false;
IBlockState state = world.getBlockState(pos);
isOn = calculateInput() > 0;
if (isOn) {
TileEntity te = world.getTileEntity(pos.down());
if (te instanceof TileEntityFilteredHopper) {
TileEntityFilteredHopper tileHopper = (TileEntityFilteredHopper) te;
IItemHandler handler = tileHopper.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
ItemStack stack = new ItemStack(ModItems.ancestryBottle);
ItemStack consumed = new ItemStack(Items.GLASS_BOTTLE);
if (tileHopper.getFilterStack().getItem() == Item.getItemFromBlock(Blocks.SOUL_SAND) && InvUtils.canInsert(handler, stack, 1) && InvUtils.getFirstOccupiedStackOfItem(handler, consumed) >= 0) {
InvUtils.consumeItemsInInventory(handler, consumed, 1, false);
InvUtils.insert(handler, stack, false);
consumeSpirits(InteractionEriottoMod.SPIRIT_PER_BOTTLE);
}
}
}
}
Aggregations