Posted August 25, 201312 yr I am trying to make a custom tool which can harvest ice and it will drop as an item, as it does with silk touch in the vanilla game, however I want to do this without adding enchantments to the custom tool, the code I'm using is as follows: public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) { if(par2Block == Block.ice) { return 5.0F; } else return 0.5F; } public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase) { if (par3 != Block.ice.blockID) { return super.onBlockDestroyed(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLivingBase); } else { return true; } } public boolean canHarvestBlock(Block par1Block) { if(par1Block.blockID == Block.ice.blockID) { return true; } else { return false; } } I am making the tool only to harvest ice, can someone point out my mistake or what I am missing in my item code? Ethyl
August 25, 201312 yr Harvest setting will only affect damage done to the item. To drop the item, spawn an EntityItem with the block data.
August 25, 201312 yr Author I'm very new to modding so I'm unsure of how exactly to do that, I've been looking at the shears code, I'm guessing I need to use the following: float f = 0.7F; double d = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; double d1 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; double d2 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; EntityItem entityitem = new EntityItem(player.worldObj, (double)x + d, (double)y + d1, (double)z + d2, stack); entityitem.delayBeforeCanPickup = 10; player.worldObj.spawnEntityInWorld(entityitem); however I am unsure as to how to make the entity item have the ice block data?
August 25, 201312 yr Yes, this code will spawn an EntityItem. The only data useful for the ice block is its id, Block.ice.blockID. Make it so the ItemStack in EntityItem has this blockID.
August 25, 201312 yr Author I am now using this code but still no luck, am I missing something? public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase) { if (par3 == Block.ice.blockID) { Random rand = new Random(); float f = 0.7F; double d = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; double d1 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; double d2 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; EntityItem entityitem = new EntityItem(par7EntityLivingBase.worldObj, (double)par4 + d, (double)par5 + d1, (double)par6 + d2, new ItemStack(Block.ice.blockID,1,0)); entityitem.delayBeforeCanPickup = 10; par7EntityLivingBase.worldObj.spawnEntityInWorld(entityitem); par2World.setBlock(par4, par5, par6, 0); return true; } else { return false; } }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.