Posted July 27, 20169 yr 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 http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
July 27, 20169 yr 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. 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.
July 27, 20169 yr Author Where should I look? http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
July 27, 20169 yr Start with Block#harvestBlock . 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.
July 28, 20169 yr Author 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 http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
July 28, 20169 yr 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) 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.
July 28, 20169 yr Author 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 http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
July 28, 20169 yr 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 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.
July 28, 20169 yr Author AND HOW DO I DO THAT?? I just did want you told me to do http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
July 29, 20169 yr 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... 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.
July 29, 20169 yr Author 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); } } http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
July 29, 20169 yr Author WHY AM I STILL USING THE STATe VARIABLE? I have now changed it http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
July 29, 20169 yr Author 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); } } http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
July 29, 20169 yr Author Fixed problem #1 with this: } else { if (worldIn.getBlockState(offset2).getBlockHardness(worldIn, offset2)!=Blocks.BEDROCK.getBlockHardness(Blocks.BEDROCK.getDefaultState(), worldIn, null)) { worldIn.setBlockToAir(offset2); } } http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
July 29, 20169 yr 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] 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.
July 30, 20169 yr Author 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 http://i.imgur.com/J4rrGt6.png[/img] [Creator of mcrafterzz mod]
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.