Posted December 3, 20204 yr Hi, I made a pickaxe in my mod that I actually want it to break ore veins more easily, so I made a blockbreakevent, and then a script that checks for every block around the ore you broke if there are any blocks of the same type, and if there are, then break them. My script is actually not working, and I don't really know why 😅, so I post this for any help, I would really appreciate it. Thanks ! Here is my event : @SubscribeEvent public static void onBreakEventWithPickaxe(BlockEvent.BreakEvent e) { PlayerEntity playerIn = e.getPlayer(); Item pickaxe = ModItems.NETHER_STAR_PICKAXE.get(); Block block = e.getState().getBlock(); IWorld world = e.getWorld(); if (e.getState().getBlock() instanceof OreBlock && playerIn.getHeldItemMainhand().getItem() == pickaxe) { int radius = 3; int height = 6; int posX = e.getPos().getX() - radius; int posY = e.getPos().getY() - radius; int posZ = e.getPos().getZ() - (height / 2); for (int i = 0; i < radius * 2 * radius * 2 * height; i++) { BlockPos pos = new BlockPos(posX, posY, posZ); if (world.getBlockState(pos).getBlock() == block) { world.destroyBlock(pos, true); } posX++; if (posX == radius * 2 + 1) { posY++; posX = e.getPos().getX() - radius; } if (posY == radius * 2 + 1) { posZ++; posY = e.getPos().getY() - radius; posX = e.getPos().getX() - radius; } } } }
December 3, 20204 yr BlockPos.getAllInBox(...) would be a much, much better way of handling that loop. Or hell, using three nested loops for x, y, and z... 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.
December 3, 20204 yr Author Okkk, thanks, indeed it was a pain making a such loop 😅, I am trying to find how BlockPos.getAllInBox(...) works, but I don't fully understand Have you got any advice ? 😅 I mean, I found out how to create the Stream with the two positions, but how can I use the Stream it creates ? Edited December 3, 20204 yr by bibouche_
December 3, 20204 yr Author Ok so I think I figured it out, with a simple foreach loop, but I still can't make it works 😑 I made this : @SubscribeEvent public static void onBlockBreakEvent(BlockEvent.BreakEvent e) { PlayerEntity playerIn = e.getPlayer(); Block block = e.getState().getBlock(); IWorld world = e.getWorld(); if (e.getState().getBlock() instanceof OreBlock) { int radius = 3; int baseX = e.getPos().getX() - radius; int baseY = e.getPos().getY() - radius; int baseZ = e.getPos().getZ() - radius; int finalX = e.getPos().getX() + radius; int finalY = e.getPos().getY() + radius; int finalZ = e.getPos().getZ() + radius; BlockPos firstPos = new BlockPos(baseX, baseY, baseZ); BlockPos secondPos = new BlockPos(finalX, finalY, finalZ); Stream<BlockPos> blockList = BlockPos.getAllInBox(firstPos, secondPos); for ( BlockPos pos : blockList.collect(Collectors.toList()) ) { if (world.getBlockState(pos).getBlock() == block) { world.destroyBlock(pos, true); } } } }
December 3, 20204 yr Stream implements IEnumerable, so you don't need to convert it to a List 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.
December 3, 20204 yr Author Ok, so I do need to convert it to a list ? But is there a problem with my foreach loop ? when I make it sysout position for every pos of the stream, it prints the same position at all, and I don't really understand why Edited December 3, 20204 yr by bibouche_
December 3, 20204 yr 3 minutes ago, bibouche_ said: Ok, so I do need to convert it to a list ? you can use the collect() method from the stream, and then pass the desired collection type conversion, in this case Collectors.toList()
December 3, 20204 yr 25 minutes ago, diesieben07 said: IEnumerable is a C# thing. Derp yeah. 25 minutes ago, diesieben07 said: The Java equivalent would be Iterable, which Stream does not implement. I thought it did. Nevermind then. 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.
December 3, 20204 yr Author 28 minutes ago, kiou.23 said: you can use the collect() method from the stream, and then pass the desired collection type conversion, in this case Collectors.toList() yup, I did that, but it isn't working, and when I print the pos for every element of the stream, it prints the same position at all, and I don't understand why Edited December 3, 20204 yr by bibouche_
December 4, 20204 yr Author Oh thank you so much, it finally works, I'm so happy I made the Stream.forEach() loop, and that's all
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.