Bedrock_Miner Posted August 19, 2014 Share Posted August 19, 2014 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. Quote http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS Link to comment Share on other sites More sharing options...
jeffryfisher Posted August 19, 2014 Share Posted August 19, 2014 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. Quote 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. Link to comment Share on other sites More sharing options...
Ewe Loon Posted August 19, 2014 Share Posted August 19, 2014 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); } Quote Link to comment Share on other sites More sharing options...
sequituri Posted August 20, 2014 Share Posted August 20, 2014 Left-click block with pickaxe until it breaks. Quote -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img] Link to comment Share on other sites More sharing options...
jeffryfisher Posted August 20, 2014 Share Posted August 20, 2014 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. Quote 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. Link to comment Share on other sites More sharing options...
imadnsn Posted August 20, 2014 Share Posted August 20, 2014 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(). Quote Link to comment Share on other sites More sharing options...
The_SlayerMC Posted August 20, 2014 Share Posted August 20, 2014 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; } Quote Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods Link to comment Share on other sites More sharing options...
imadnsn Posted August 20, 2014 Share Posted August 20, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.