Posted August 19, 201411 yr Probably a beginner question, but: How do you break a block properly so that it drops its Items as if a player destroyed it? Can't figure out which code to use. http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
August 19, 201411 yr Search the Block class for methods containing the word "drop". Choose one to override. If unsure, look at a vanilla example such as diamond ore, which drops diamonds rather than itself. See how it does it and then imitate. The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
August 19, 201411 yr this is taken from one of my mods Block bit = par1World.getBlock(x+xo, y+yo, z+zo); int met = par1World.getBlockMetadata(x+xo, y+yo, z+zo); if ((bit instanceof BlockLog)||(bit instanceof BlockLeavesBase)){ bit.harvestBlock(par1World, plr, x+xo, y+yo, z+zo,met); par1World.setBlockToAir(x+xo, y+yo, z+zo); }
August 20, 201411 yr Left-click block with pickaxe until it breaks. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
August 20, 201411 yr You shouldn't need to dive into the mechanics of breaking the block; the vanilla behavior should get that far as is. As for hitting until it breaks, that just drops the block by default, not some item (e.g. diamond) found within an ore (e.g. diamond ore). Your something-Block subclass needs to override a method pertaining to what it drops when harvested, but I can't recall the exact method name. Search for "drop" and imitate the BlockDiamond class. The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
August 20, 201411 yr The way I've done it is the same as the way BuildCraft has done it. You first get drops by calling block.getDrops(), then you get drop chance by calling ForgeEventFactory.fireBlockHarvesting() which is the same fired by forge when a block breaks and is being harvested. Then at last you make another empty list and iterate over the drops list and if a random generated number (every time) is less than the chance you add the drop to your other list. After you get the drops, iterate over them and spawn each by using world.spawnEntityInWorld().
August 20, 201411 yr It's not that hard to look into the ore block file... @Override public Item getItemDropped(int par1, Random par2, int par3) { return Items.diamond; } Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
August 20, 201411 yr It's not that hard to look into the ore block file... @Override public Item getItemDropped(int par1, Random par2, int par3) { return Items.diamond; } Some blocks have different multiple drops, and some have different dropped metadata, so block.getDrops is better.
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.