net.minecraft.inventory.InventoryHelper Java Examples

The following examples show how to use net.minecraft.inventory.InventoryHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockTFOven.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    if (!keepInventory)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityTFOven)
        {
            InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityTFOven)tileentity);
            worldIn.updateComparatorOutputLevel(pos, this);
        }
    }

    super.breakBlock(worldIn, pos, state);
}
 
Example #2
Source File: TileFirepit.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
public void ejectContents(boolean ejectFuel)
{
	if(ejectFuel)
	{
		InventoryHelper.spawnItemStack(world, getPos().getX(), getPos().getY(), getPos().getZ(), this.getStackInSlot(FUEL_SLOT));
		this.setInventorySlotContents(FUEL_SLOT, ItemStack.EMPTY);
	}
	else
	{
		for(int i = TOOL_SLOT; i < this.getSizeInventory(); i++)
		{
			if(i == OUTPUT_SLOT && cookingTimer > 0)
			{
				continue;
			}
			InventoryHelper.spawnItemStack(world, getPos().getX(), getPos().getY(), getPos().getZ(), this.getStackInSlot(i));
			this.setInventorySlotContents(i, ItemStack.EMPTY);
		}
	}

}
 
Example #3
Source File: BlockSurgery.java    From Cyberware with MIT License 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{ 
	TileEntity tileentity = worldIn.getTileEntity(pos);

	if (tileentity instanceof TileEntitySurgery && !worldIn.isRemote)
	{
		TileEntitySurgery surgery = (TileEntitySurgery) tileentity;
		
		for (int i = 0; i < surgery.slots.getSlots(); i++)
		{
			ItemStack stack = surgery.slots.getStackInSlot(i);
			if (stack != null)
			{
				InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
			}
		}
	}
	super.breakBlock(worldIn, pos, state);

}
 
Example #4
Source File: BlockComponentBox.java    From Cyberware with MIT License 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{ 
	TileEntity tileentity = worldIn.getTileEntity(pos);

	if (tileentity instanceof TileEntityComponentBox && !worldIn.isRemote)
	{
		TileEntityComponentBox box = (TileEntityComponentBox) tileentity;
		if (box.doDrop)
		{
			ItemStack stackToDrop = new ItemStack(ib);
			stackToDrop = getStack(box);
			InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stackToDrop);
		}
	}
	

	super.breakBlock(worldIn, pos, state);

}
 
Example #5
Source File: BlockEngineeringTable.java    From Cyberware with MIT License 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{ 
	boolean top = state.getValue(HALF) == EnumEngineeringHalf.UPPER;
	if (top)
	{
		TileEntity tileentity = worldIn.getTileEntity(pos);

		if (tileentity instanceof TileEntityEngineeringTable && !worldIn.isRemote)
		{
			TileEntityEngineeringTable engineering = (TileEntityEngineeringTable) tileentity;
			
			for (int i = 0; i < engineering.slots.getSlots(); i++)
			{
				ItemStack stack = engineering.slots.getStackInSlot(i);
				if (stack != null)
				{
					InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
				}
			}
		}
		super.breakBlock(worldIn, pos, state);
	}
}
 
Example #6
Source File: BlockScanner.java    From Cyberware with MIT License 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{ 
	TileEntity tileentity = worldIn.getTileEntity(pos);

	if (tileentity instanceof TileEntityScanner && !worldIn.isRemote)
	{
		TileEntityScanner scanner = (TileEntityScanner) tileentity;
		
		for (int i = 0; i < scanner.slots.getSlots(); i++)
		{
			ItemStack stack = scanner.slots.getStackInSlot(i);
			if (stack != null)
			{
				InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
			}
		}
	}
	super.breakBlock(worldIn, pos, state);

}
 
Example #7
Source File: BlockBlueprintArchive.java    From Cyberware with MIT License 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{ 
	TileEntity tileentity = worldIn.getTileEntity(pos);

	if (tileentity instanceof TileEntityBlueprintArchive && !worldIn.isRemote)
	{
		TileEntityBlueprintArchive scanner = (TileEntityBlueprintArchive) tileentity;
		
		for (int i = 0; i < scanner.slots.getSlots(); i++)
		{
			ItemStack stack = scanner.slots.getStackInSlot(i);
			if (stack != null)
			{
				InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
			}
		}
	}
	super.breakBlock(worldIn, pos, state);

}
 
Example #8
Source File: BlockMixin.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    TileEntity tile = worldIn.getTileEntity(pos);

    if (tile != null)
    {
        IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        if (itemHandler != null)
        {
            for (int i = 0; i < itemHandler.getSlots(); i++)
            {
                ItemStack stack = itemHandler.getStackInSlot(i);
                if (!stack.isEmpty())
                {
                    InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
                }
            }
        }
    }

    super.breakBlock(worldIn, pos, state);
}
 
Example #9
Source File: PollutedSand.java    From EmergingTechnology with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {

    if (worldIn.isRemote) {
        return true;
    }

    if (facing == EnumFacing.UP) {
        worldIn.setBlockState(pos, Blocks.SAND.getDefaultState(), 3);
        InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.offset(EnumFacing.UP).getY(), pos.getZ(),
                new ItemStack(ModItems.plasticwaste));
        return true;
    }

    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example #10
Source File: PollutedDirt.java    From EmergingTechnology with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {

    if (worldIn.isRemote) {
        return true;
    }

    if (facing == EnumFacing.UP) {
        worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState(), 3);
        InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.offset(EnumFacing.UP).getY(), pos.getZ(),
                new ItemStack(ModItems.plasticwaste));
        return true;
    }

    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example #11
Source File: PollutedGravel.java    From EmergingTechnology with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {

    if (worldIn.isRemote) {
        return true;
    }

    if (facing == EnumFacing.UP) {
        worldIn.setBlockState(pos, Blocks.GRAVEL.getDefaultState(), 3);
        InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.offset(EnumFacing.UP).getY(), pos.getZ(),
                new ItemStack(ModItems.plasticwaste));
        return true;
    }

    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example #12
Source File: BlockSaltFurnace.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    if (!keepInventory)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntitySaltFurnace)
        {
            InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntitySaltFurnace)tileentity);
            worldIn.updateComparatorOutputLevel(pos, this);
        }
    }

    super.breakBlock(worldIn, pos, state);
}
 
Example #13
Source File: BlockTFCompressor.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    if (!keepInventory)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityTFCompressor)
        {
            InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityTFCompressor)tileentity);
            worldIn.updateComparatorOutputLevel(pos, this);
        }
    }

    super.breakBlock(worldIn, pos, state);
}
 
Example #14
Source File: BlockTFCrasher.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    if (!keepInventory)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityTFCrasher)
        {
            InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityTFCrasher)tileentity);
            worldIn.updateComparatorOutputLevel(pos, this);
        }
    }

    super.breakBlock(worldIn, pos, state);
}
 
Example #15
Source File: BlockAggregator.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    if (!keepInventory)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntitySoymilkAggregator)
        {
            InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntitySoymilkAggregator)tileentity);
            worldIn.updateComparatorOutputLevel(pos, this);
        }
    }

    super.breakBlock(worldIn, pos, state);
}
 
Example #16
Source File: BlockAdvancedAggregator.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    if (!keepInventory)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntitySoymilkAdvancedAggregator)
        {
            InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntitySoymilkAdvancedAggregator)tileentity);
            worldIn.updateComparatorOutputLevel(pos, this);
        }
    }

    super.breakBlock(worldIn, pos, state);
}
 
Example #17
Source File: BlockTFStorage.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TileEntity tileentity = worldIn.getTileEntity(pos);
    if (tileentity instanceof TileEntityTFStorage) {
        InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityTFStorage) tileentity);
        worldIn.updateComparatorOutputLevel(pos, this);
    }

    super.breakBlock(worldIn, pos, state);
}
 
Example #18
Source File: BlockFirepit.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
	TileEntity tileentity = worldIn.getTileEntity(pos);

	if (tileentity instanceof IInventory)
	{
		InventoryHelper.dropInventoryItems(worldIn, pos, (IInventory)tileentity);
		worldIn.updateComparatorOutputLevel(pos, this);
	}

	super.breakBlock(worldIn, pos, state);
}
 
Example #19
Source File: DryingRackBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void dropInventoryItems(World worldIn, BlockPos pos, IItemHandler inventory)
{
    for (int i = 0; i < inventory.getSlots(); ++i)
    {
        ItemStack itemstack = inventory.getStackInSlot(i);

        if (itemstack.getCount() > 0)
        {
            InventoryHelper.spawnItemStack(worldIn, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), itemstack);
        }
    }
}
 
Example #20
Source File: SawmillBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void dropInventoryItems(World worldIn, BlockPos pos, IItemHandler inventory)
{
    for (int i = 0; i < inventory.getSlots(); ++i)
    {
        ItemStack itemstack = inventory.getStackInSlot(i);

        if (itemstack.getCount() > 0)
        {
            InventoryHelper.spawnItemStack(worldIn, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), itemstack);
        }
    }
}
 
Example #21
Source File: ChoppingBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void dropInventoryItems(World worldIn, BlockPos pos, IItemHandler inventory)
{
    for (int i = 0; i < inventory.getSlots(); ++i)
    {
        ItemStack itemstack = inventory.getStackInSlot(i);

        if (itemstack.getCount() > 0)
        {
            InventoryHelper.spawnItemStack(worldIn, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), itemstack);
        }
    }
}
 
Example #22
Source File: BlockPhysicsInfuser.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TileEntityPhysicsInfuser tileEntity = (TileEntityPhysicsInfuser) worldIn.getTileEntity(pos);
    // If there's a valid TileEntity, try dropping the contents of it's inventory.
    if (tileEntity != null && !tileEntity.isInvalid()) {
        IItemHandler handler = tileEntity
            .getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        // Safety in case the capabilities system breaks. If we can't find the handler then
        // there isn't anything to drop anyways.
        if (handler != null) {
            // Drop all the items
            for (int slot = 0; slot < handler.getSlots(); slot++) {
                ItemStack stack = handler.getStackInSlot(slot);
                InventoryHelper
                    .spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
            }
        }
    }
    // Remove the dummy block of this physics infuser, if there is one.
    BlockPos dummyBlockPos = getDummyStatePos(state, pos);
    super.breakBlock(worldIn, pos, state);
    if (worldIn.getBlockState(dummyBlockPos)
        .getBlock() == ValkyrienSkiesMod.INSTANCE.physicsInfuserDummy) {
        worldIn.setBlockToAir(dummyBlockPos);
    }
    // Finally, delete the tile entity.
    worldIn.removeTileEntity(pos);
}
 
Example #23
Source File: BlockTFBattery.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TileEntity tileentity = worldIn.getTileEntity(pos);
    if (tileentity instanceof TileEntityTofuBattery) {
        InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityTofuBattery) tileentity);
        worldIn.updateComparatorOutputLevel(pos, this);
    }
    super.breakBlock(worldIn, pos, state);
}
 
Example #24
Source File: BlockComponentBox.java    From Cyberware with MIT License 5 votes vote down vote up
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
	TileEntity tileentity = worldIn.getTileEntity(pos);
	
	if (tileentity instanceof TileEntityComponentBox)
	{
		/*if (player.isCreative() && player.isSneaking())
		{
			TileEntityScanner scanner = ((TileEntityScanner) tileentity);
			scanner.ticks = CyberwareConfig.SCANNER_TIME - 200;
		}*/
		if (player.isSneaking())
		{
			TileEntityComponentBox box = (TileEntityComponentBox) tileentity;
			ItemStack toDrop = this.getStack(box);
			
			if (player.inventory.mainInventory[player.inventory.currentItem] == null)
			{
				player.inventory.mainInventory[player.inventory.currentItem] = toDrop;
			}
			else
			{
				if (!player.inventory.addItemStackToInventory(toDrop))
				{
					InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), toDrop);
				}
			}
			box.doDrop = false;
			worldIn.setBlockToAir(pos);
		}
		else
		{
			player.openGui(Cyberware.INSTANCE, 5, worldIn, pos.getX(), pos.getY(), pos.getZ());
		}
	}
	
	return true;
	
}
 
Example #25
Source File: BlockCampfirePot.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    if (!keepInventory) {
        TileEntity te = worldIn.getTileEntity(pos);
        if (te instanceof TileEntityCampfirePot) {
            InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityCampfirePot)te);
            worldIn.updateComparatorOutputLevel(pos, this);
        }

        spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(BlockLoader.CAMPFIRE_IDLE)));
        spawnAsEntity(worldIn, pos, new ItemStack(ItemLoader.POT));
    }

    super.breakBlock(worldIn, pos, state);
}
 
Example #26
Source File: BlockMinecoprocessor.java    From Minecoprocessors with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
  notifyNeighbors(worldIn, pos, state);

  TileEntity tileentity = worldIn.getTileEntity(pos);
  if (tileentity instanceof TileEntityMinecoprocessor) {
    InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityMinecoprocessor) tileentity);
  }
  super.breakBlock(worldIn, pos, state);
}
 
Example #27
Source File: ModificationTable.java    From MiningGadgets with MIT License 5 votes vote down vote up
@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
    if (newState.getBlock() != this) {
        TileEntity tileEntity = worldIn.getTileEntity(pos);
        if (tileEntity != null) {
            LazyOptional<IItemHandler> cap = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
            cap.ifPresent(handler -> {
                for(int i = 0; i < handler.getSlots(); ++i) {
                    InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), handler.getStackInSlot(i));
                }
            });
        }
        super.onReplaced(state, worldIn, pos, newState, isMoving);
    }
}
 
Example #28
Source File: MachineBase.java    From EmergingTechnology with MIT License 5 votes vote down vote up
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    TileEntity te = world.getTileEntity(pos);

    IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

    for (int i = 0; i < cap.getSlots(); ++i) {
        ItemStack itemstack = cap.getStackInSlot(i);

        if (!itemstack.isEmpty()) {
            InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
        }
    }
}
 
Example #29
Source File: BlockMapleSyrupCauldron.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    if (!keepInventory) {
        TileEntity te = worldIn.getTileEntity(pos);
        if (te instanceof TileEntityMapleCauldron) {
            InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityMapleCauldron)te);
            worldIn.updateComparatorOutputLevel(pos, this);
        }
    }
    super.breakBlock(worldIn, pos, state);
}
 
Example #30
Source File: BlockStoneMortar.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TileEntity tileentity = worldIn.getTileEntity(pos);
    if (tileentity instanceof TileEntityStoneMortar) {
        InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityStoneMortar) tileentity);
        worldIn.updateComparatorOutputLevel(pos, this);
    }
    super.breakBlock(worldIn, pos, state);
}