Dropping more than one item with a tool

Started by kreezxil on Fri, 10/30/2015 - 21:15

Topic category: Advanced modding

Last seen on 15:22, 1. Feb 2018
Joined Feb 2015
User points:


  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Dropping more than one item with a tool
Fri, 10/30/2015 - 21:15

I want my tool when I use it to do one damage to itself, and then depending on the type of block it is acting on, drop several different kinds of items, preferrably into the world instead of the player's inventory.

What I have right now is:

        @Override public boolean onBlockDestroyed(World world, Block block, BlockPos pos, EntityPlayer entity, float hitX, float hitY, float hitZ){
            float var4 = 1.0F;
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();

I am fairly certain the following IF is wrong, for one it throws an error on it, what is the proper way to do the following? 

            if(block.Block == "minecraft:sand" && block.Data == 1) { //red sand
                    world.setBlockToAir(new BlockPos(i, j, k));
                    if(entity instanceof EntityPlayer)((EntityPlayer)entity).inventory.addItemStackToInventory(new ItemStack(Items.dye, 1));
                    if(entity instanceof EntityPlayer)((EntityPlayer)entity).inventory.addItemStackToInventory(new ItemStack(Blocks.sand, 1));
                    itemStack.damageItem(1, entity);
                  return true;

As you can see I want my tool when I right click on red sand to create regular sand and red dye, the rest of the block appear to not have errors, just that first IF, but if there are other errors in my thought, I'd appreciate insight into them. I plan to have this tool to be used on dirt and gravel too. It's a sifter. Ideally I'd want it to work like a pick axe or shovel, requiring one to wack the block in question repeatedly based on the harvesting tier before getting the products.

Thanks in advance for any help.

- Kreezxil