Java Code Examples for net.minecraft.inventory.InventoryHelper#spawnItemStack()

The following examples show how to use net.minecraft.inventory.InventoryHelper#spawnItemStack() . 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: 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 2
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 3
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 4
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 5
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 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: 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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
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);
        }
    }
}