Posted March 21, 201411 yr Hi hello, I would like to do a question. I did a custom axe, but I would like to know if there is a way to tell to my axe that when the player break the specific block with this tool destroy all the connected blocks with this id. I'm trying to destroy the trees just breaking only one block of the tree. I'm looking for a block break event or I don't know if there is a better way to do. Thanks for the help.
March 21, 201411 yr Hi You could look to see how these folks do it, assuming one of them is open source. http://www.minecraftdl.com/timber-mod/ http://www.minecraftdl.com/tree-capitator-mod/ http://www.skydaz.com/timber-mod-installer-for-minecraft-1-6-2/ http://www.skydaz.com/whole-tree-axe-for-minecraft-1-2-5/ It's obviously a pretty popular idea... -TGG
March 21, 201411 yr Author I already check it the only that have the sources is Lumberjack I'll try to see. Thanks.
March 21, 201411 yr @Override public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int x, int y, int z, EntityLivingBase par7EntityLivingBase) { super.onBlockDestroyed(par1ItemStack, par2World, par3, x, y, z, par7EntityLivingBase); if(!par7EntityLivingBase.isSneaking()) //Checks if the entity is not sneaking. You don't need if you don't want. { if(world.getBlockId(x, y, z) == Block.wood.blockID) { this.repeatChop(par2World, x, y, z); } } return true; } public void repeatChop(World world, int x, int y, int z) { for(int i = -1; i <= 1; i++) { for(int j = -1; j <= 1; j++) { for(int k = -1; k <= 1; k++) { if(world.getBlockId(x + i, y + j, z + k) == Block.wood.blockID) { world.destroyBlock(x + i, y + j, z + k, true); this.repeatChop(world, x + i, y + j, z + k); } } } } } This is some personal code that I've worked on for an item in my mod that does the same thing. You can use it if you wish. I've removed bits that aren't needed for you. EDIT: Fixed some code I messed up. All is good. http://www.slothygaming.com/img/ota.png[/img] If your grammar is shit and you blatantly don't know what you're doing, I will not help you.
March 22, 201411 yr @Override public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int x, int y, int z, EntityLivingBase par7EntityLivingBase) { super.onBlockDestroyed(par1ItemStack, par2World, par3, x, y, z, par7EntityLivingBase); if(!par7EntityLivingBase.isSneaking()) //Checks if the entity is not sneaking. You don't need if you don't want. { if(world.getBlockId(x, y, z) == Block.wood.blockID) { this.repeatChop(par2World, x, y, z); } } return true; } public void repeatChop(World world, int x, int y, int z) { for(int i = -1; i <= 1; i++) { for(int j = -1; j <= 1; j++) { for(int k = -1; k <= 1; k++) { if(world.getBlockId(x + i, y + j, z + k) == Block.wood.blockID) { world.destroyBlock(x + i, y + j, z + k, true); this.repeatChop(world, x + i, y + j, z + k); } } } } } This is some personal code that I've worked on for an item in my mod that does the same thing. You can use it if you wish. I've removed bits that aren't needed for you. EDIT: Fixed some code I messed up. All is good. That repeatChop method is highly recursive and is prone to repeatedly check the same nine blocks up to 3 times each. Doing 18 times the amount of work it needs to. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
March 22, 201411 yr Well yes. You can change it if you wish but it is needed if you want it to successfully chop down the entire tree. If I just broke the loop, then it would only chop one log every time. That would then cause you to barely cut down jungle trees. The code lets you start your chop from the middle of a tree if needed and then removes everything below and above it that share the blockID of wood. EDIT: Somewhat misunderstood what you said. Well, no code is perfect. If you find a way to optimize it tell me. http://www.slothygaming.com/img/ota.png[/img] If your grammar is shit and you blatantly don't know what you're doing, I will not help you.
March 22, 201411 yr Author Omg.Thanks, the code is working, that what I was looking for. Now watching your code I can understand the process but is something that is I'm doing for myself I can't do because my creativity is zero. Thanks.
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.