Acrogenous Posted August 8, 2017 Posted August 8, 2017 (edited) public boolean onBlockDestroyed(ItemStack p_onBlockDestroyed_1_, World world, IBlockState blockstate, BlockPos block, EntityLivingBase player) { if(player.isSneaking()) { int x = 0-aoe; int y = 0-aoe; int z = 0-aoe; while(z != aoe) { while(y != aoe) { while(x != aoe) { if(world.getBlockState(new BlockPos(x,y,z)).getBlock()== Blocks.STONE) { world.destroyBlock(new BlockPos(block.getX() +x, block.getY() +y, block.getZ() +z), true); } x++; } x= 0-aoe; y++; } y= 0-aoe; z++; } } return super.onBlockDestroyed(p_onBlockDestroyed_1_, world, blockstate, block, player); } so when you shift mine something it is suppose to mine all blocks around it in "aoe" radius, there are 2 problems however; 1 it still mines things that aren't stone and 2 it doesn't mine all the stone, thanks in advanced. Edited August 8, 2017 by Acrogenous added a version Quote
Draco18s Posted August 8, 2017 Posted August 8, 2017 (edited) Ew. Ew ew ew. Ok, so, 1. for-loops are a Thing. As are negative variables. You don't need those 0s. for(int x = -aoe; x <= aoe; x++) { ... } Two: new BlockPos(x,y,z) (where you're checking to see if the block is stone) != new BlockPos(block.getX() +x, block.getY() +y, block.getZ() +z) (where you are removing the block) Three, BlockPos.getAllInBox(...) is a Thing. Edited August 8, 2017 by Draco18s Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Acrogenous Posted August 8, 2017 Author Posted August 8, 2017 thank you Draco18s; 5 minutes ago, Draco18s said: Ok, so, 1. for-loops are a Thing. As are negative variables. You don't need those 0s. for(int x = -aoe; x <= aoe; x++) { ... } I know for loops are a thing, but don't both my method and your method have roughly the same amount of characters? I can see it is neater however so I will try and use this in the future. I wasn't aware of negative variables (Java isn't my main language but it probably exists in other languages I've just never known) 8 minutes ago, Draco18s said: Two: new BlockPos(x,y,z) (where you're checking to see if the block is stone) != new BlockPos(block.getX() +x, block.getY() +y, block.getZ() +z) (where you are removing the block this is my problem, thanks 8 minutes ago, Draco18s said: Three, BlockPos.getAllInBox(...) is a Thing. I didn't know this, it would make the code neater. My code isn't generally neat, (which are effectively points 1 and 3 here) and I will try and work on this aspect, so thanks for the advice! Quote
Draco18s Posted August 8, 2017 Posted August 8, 2017 (edited) 13 minutes ago, Acrogenous said: thank you Draco18s; I know for loops are a thing, but don't both my method and your method have roughly the same amount of characters? I can see it is neater however so I will try and use this in the future. Character length only matters for Code Golf. That said, if you wanted to use a while loop, you can save characters: Instead of: int x = -aoe; ... { while(x != aoe) { x++; } x= -aoe; y++; } You can do: ... { int x = -aoe; while(x != aoe) { x++; } y++; } By declaring the value at the top of the loop you save having to reset it at the end. Edited August 8, 2017 by Draco18s 1 Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.