MCrafterzz Posted July 27, 2016 Share Posted July 27, 2016 I have created a hammer, but I have a problem (yes another problem), I don't know how to break blocks with enchantments so for example silk touch gives you the silk touch block. Here is the code that needs to be changed: worldIn.destroyBlock(offset2, true); Full souce code: http://pastebin.com/UHZCSs6K Quote http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod] Link to comment Share on other sites More sharing options...
Draco18s Posted July 27, 2016 Share Posted July 27, 2016 World#DestroyBlock bypasses all the code that is specific to the player harvesting blocks. If you want to harvest blocks you need to call the code responsible for harvesting blocks. If you want Silk Touch to work, then use your IDE to figure out where the code already references Silk Touch. 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. Link to comment Share on other sites More sharing options...
MCrafterzz Posted July 27, 2016 Author Share Posted July 27, 2016 Where should I look? Quote http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod] Link to comment Share on other sites More sharing options...
Choonster Posted July 27, 2016 Share Posted July 27, 2016 Start with Block#harvestBlock . Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future. Link to comment Share on other sites More sharing options...
MCrafterzz Posted July 28, 2016 Author Share Posted July 28, 2016 I've changed it to this: state.getBlock().harvestBlock(worldIn, player, offset2, state, null, itemStack); But only the original block breaks even if I get the drops from all of them Quote http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod] Link to comment Share on other sites More sharing options...
Draco18s Posted July 28, 2016 Share Posted July 28, 2016 Block#harvestBlock doesn't actually set the block to air. You would know this if you actually looked at the method. Point is, you can't call just one method, or you completely bypass the set of hooks designed to let other mods know that the block was harvested and removed, or in some cases, letting the block itself know. Take a look at PlayerInterationManager#tryHarvestBlock(BlockPos) The series of things to do is: Block#canHarvestBlock (ensure you can actually harvest the block: you might be able to skip this if you're destroying same-type blocks only) ItemStack#onBlockDestroyed (you would probably skip this because this is how your Item knows that it destroyed a block, and if that calls these methods again, you have a problem) Block#removedByPlayer (automatically called Block#onBlockHarvested; default empty method, but used by various blocks to handle TE containers) Block#onBlockDestroyedByPlayer Block#harvestBlock (finally get the harvested drops to...drop) 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. Link to comment Share on other sites More sharing options...
MCrafterzz Posted July 28, 2016 Author Share Posted July 28, 2016 I have now changed it to this: if (state.getBlock().canHarvestBlock(worldIn, offset2, player)) { state.getBlock().removedByPlayer(state, worldIn, offset2, player, true); state.getBlock().onBlockDestroyedByPlayer(worldIn, offset2, state); state.getBlock().harvestBlock(worldIn, player, offset2, state, null, itemStack); } else { worldIn.setBlockToAir(offset2); } The error: http://pastebin.com/iyU6Z4ec Quote http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod] Link to comment Share on other sites More sharing options...
Draco18s Posted July 28, 2016 Share Posted July 28, 2016 Gosh. It's almost like you're asking a block of diamond ore what type of dirt it is. When you change position you need to get a NEW BLOCKSTATE or check that the two blocks ARE THE SAME FIRST 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. Link to comment Share on other sites More sharing options...
MCrafterzz Posted July 28, 2016 Author Share Posted July 28, 2016 AND HOW DO I DO THAT?? I just did want you told me to do Quote http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod] Link to comment Share on other sites More sharing options...
Draco18s Posted July 29, 2016 Share Posted July 29, 2016 state.getBlock() //the block I mined out (diamond ore) ...removedByPlayer(state, worldIn, offset2, player, true); //offset2, the location of a different block (dirt), state: the diamond ore... 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. Link to comment Share on other sites More sharing options...
MCrafterzz Posted July 29, 2016 Author Share Posted July 29, 2016 Thank you, but there are 2 problems: 1. I can't make it be able to not break unbreakeble blocks 2. Only the original block drops (all of them breakes) if (worldIn.getBlockState(offset2).getBlock().canHarvestBlock(worldIn, offset2, player)) { worldIn.getBlockState(offset2).getBlock().removedByPlayer(state, worldIn, offset2, player, true); worldIn.getBlockState(offset2).getBlock().onBlockDestroyedByPlayer(worldIn, offset2, state); worldIn.getBlockState(offset2).getBlock().harvestBlock(worldIn, player, offset2, state, null, itemStack); } else { if (worldIn.isBlockModifiable(player, offset2)) { worldIn.setBlockToAir(offset2); } } Quote http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod] Link to comment Share on other sites More sharing options...
MCrafterzz Posted July 29, 2016 Author Share Posted July 29, 2016 WHY AM I STILL USING THE STATe VARIABLE? I have now changed it Quote http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod] Link to comment Share on other sites More sharing options...
MCrafterzz Posted July 29, 2016 Author Share Posted July 29, 2016 Still doen't work, updated code: if (worldIn.getBlockState(offset2).getBlock().canHarvestBlock(worldIn, offset2, player)) { worldIn.getBlockState(offset2).getBlock().removedByPlayer(worldIn.getBlockState(offset2), worldIn, offset2, player, true); worldIn.getBlockState(offset2).getBlock().onBlockDestroyedByPlayer(worldIn, offset2, worldIn.getBlockState(offset2)); worldIn.getBlockState(offset2).getBlock().harvestBlock(worldIn, player, offset2, worldIn.getBlockState(offset2), null, itemStack); } else { if (worldIn.isBlockModifiable(player, offset2)) { worldIn.setBlockToAir(offset2); } } Quote http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod] Link to comment Share on other sites More sharing options...
MCrafterzz Posted July 29, 2016 Author Share Posted July 29, 2016 Fixed problem #1 with this: } else { if (worldIn.getBlockState(offset2).getBlockHardness(worldIn, offset2)!=Blocks.BEDROCK.getBlockHardness(Blocks.BEDROCK.getDefaultState(), worldIn, null)) { worldIn.setBlockToAir(offset2); } } Quote http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod] Link to comment Share on other sites More sharing options...
Draco18s Posted July 29, 2016 Share Posted July 29, 2016 So, defined "doesn't work" for me here, because this worked for me just fine: public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) { if(entityLiving instanceof EntityPlayer) { EntityPlayer harvester = (EntityPlayer) entityLiving; Iterable<BlockPos> list = BlockPos.getAllInBox(pos.add(-1, -1, -1), pos.add(1,1,1)); for(BlockPos offset2 : list) { IBlockState state2 = world.getBlockState(offset2); Block block2 = state2.getBlock(); boolean canharvest = block2.canHarvestBlock(world, offset2, harvester); if (canharvest) { block2.removedByPlayer(state2, world, offset2, harvester, true); block2.onBlockDestroyedByPlayer(world, offset2, state2); block2.harvestBlock(world, harvester, offset2, state2, null, stack); } else { if (world.isBlockModifiable(harvester, offset2)) { world.setBlockToAir(offset2); } } } } return super.onBlockDestroyed(stack, world, state, pos, entityLiving); } http://s32.postimg.org/uemjtabol/2016_07_29_13_18_51.png[/img] 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. Link to comment Share on other sites More sharing options...
MCrafterzz Posted July 30, 2016 Author Share Posted July 30, 2016 It now works, THANK YOU so much! I don't know why it didn't work before. The only change was that I had IBlockState offsetState = worldIn.getBlockState(offset2); at the top instead of worldIn.getBlockState(offset2) on every line. Don't know why that made a different, but the important thing is that it now works Quote http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod] 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.