winnetrie Posted June 6, 2016 Posted June 6, 2016 I'm trying to add cherries as drop to the cherry trees from Biomesoplenty. But it doesn't work and i don't know why. If i do this: public class TemExtraBOPDrops { @SubscribeEvent public void TemBOPloot(HarvestDropsEvent event) { Block block = event.block; int random = randomWithRange(0,2); if (block ==Blocks.leaves){ if (random == 1){ event.drops.add(new ItemStack(TemItems.cherry)); } } } public static int randomWithRange(int min, int max){ Random rand= new Random(); int randomNum = rand.nextInt((max-min)+1)+min; return randomNum; } } then the cherry drops. But when i change it to this: public class TemExtraBOPDrops { @SubscribeEvent public void TemBOPloot(HarvestDropsEvent event) { Block block = event.block; //ItemStack stack = new ItemStack(block); int random = randomWithRange(0,2); //if (stack.getItemDamage() == 1 || stack.getItemDamage() == 3 ){ if (block ==BOPCBlocks.leaves3){ if (random == 1){ event.drops.add(new ItemStack(TemItems.cherry)); } } } public static int randomWithRange(int min, int max){ Random rand= new Random(); int randomNum = rand.nextInt((max-min)+1)+min; return randomNum; } } then it doesn't drop. Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
winnetrie Posted June 6, 2016 Author Posted June 6, 2016 i am pretty sure and i tried out all the others too, just in case. Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
winnetrie Posted June 6, 2016 Author Posted June 6, 2016 i have put a System.out.println("event has occured"); It seems the HarvestDropsEvent is not fired for the biomesoplenty leaves. Maybe i should use here breakevent Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
winnetrie Posted June 6, 2016 Author Posted June 6, 2016 i tried this now: public class TemExtraBOPDrops { @SubscribeEvent public void TemBOPloot(BreakEvent event) { System.out.println("event has occured"); Block block = event.block; World world = event.world; int x = event.x; int y = event.y; int z = event.z; ItemStack stack = new ItemStack(TemItems.cherry); EntityItem item = new EntityItem(world,x,y,z, stack); if (block == BOPCBlocks.leaves3){ if (event.blockMetadata==1){ world.spawnEntityInWorld(item); } } //ItemStack stack = new ItemStack(block); //int random = randomWithRange(0,2); //if (stack.getItemDamage() == 1 || stack.getItemDamage() == 3 ){ //if (block ==BOPCBlocks.leaves3){ //System.out.println("De juiste bladeren!!"); //if (random == 1){ //event.drops.add(new ItemStack(TemItems.cherry)); //} //} } public static int randomWithRange(int min, int max){ Random rand= new Random(); int randomNum = rand.nextInt((max-min)+1)+min; return randomNum; } } This seems to work somehow a bit. The cherries do spawn but the spawnrate is randomly. I was expecting dropping it every time since i did not provide a spawnrate! weird... Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
Draco18s Posted June 7, 2016 Posted June 7, 2016 Don't create the item stack and entity if you don't intend to spawn it in the world, you're just adding extra work for the garbage collector. (Won't fix your problem, but it makes your code cleaner) 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.
winnetrie Posted June 7, 2016 Author Posted June 7, 2016 Oh i see. You have any idea why it doesn't work with the harvestdropsevent? Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
Draco18s Posted June 7, 2016 Posted June 7, 2016 Show your BOPCBlocks class. 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.
winnetrie Posted June 7, 2016 Author Posted June 7, 2016 Jup that's right, it's from the API. Ok i did a few more test with this: public class TemExtraBOPDrops { @SubscribeEvent public void TemBOPloot(HarvestDropsEvent event) { System.out.println("event has occured"); Block block = event.block; int random = randomWithRange(0,2); //if (block == Blocks.leaves){ if (block == BOPCBlocks.leaves3){ System.out.println("leaves!!"); if (random == 1){ event.drops.add(new ItemStack(TemItems.cherry)); } } } public static int randomWithRange(int min, int max){ Random rand= new Random(); int randomNum = rand.nextInt((max-min)+1)+min; return randomNum; } } Like it is now it doesn't work. whenever i break a block that is a biomesoplenty leaves block, the "event has occured" does not show up in the console. If i do break an other block it does shows up. So the event does work on whatever block as long as it isn't a leaves block from BOP. That's weird i think. Why would it not trigger that event on those leaveblocks? And because the harvestdropsevent does not occur on those leaveblocks the whole thing does nothing. When i switch it to Blocks.leaves ( just to test it) , everything works fine and i get the "leaves!!" message too in the console. So let's say i would not check the right leaves like diesieben07 mentioned (it could be, but it's not), then the event still triggers and should show me the message "event has occured". I really hope someone can help me with this. I do not understand why this isn't working. It should work, but it doesn't...... EDIT:I took a look into the BlockBOPLeaves.class and i saw it doesn't have a -harvestBlock- method. Not sure if this is causing the problem. Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
winnetrie Posted June 7, 2016 Author Posted June 7, 2016 Ok i made it work with the breakevent. It works fine now, but now i also want to check for a specific block. BOPCBlocks.leaves3 has 4 types and i only want to check for 1 and 3. How do i get them? I tried this: public class TemExtraBOPDrops { @SubscribeEvent public void TemBOPloot(BreakEvent event) { System.out.println("event has occured"); Block block = event.block; World world = event.world; int x = event.x; int y = event.y; int z = event.z; //int meta = world.getBlockMetadata(x, y, z); //if (meta ==1 || meta ==3){ //System.out.println("meta found"); if (block==BOPCBlocks.leaves3 ){ System.out.println("condition met"); int random = randomWithRange(0,10); if (random == 1){ ItemStack stack = new ItemStack(TemItems.cherry); EntityItem item = new EntityItem(world,x,y,z, stack); world.spawnEntityInWorld(item); } } //} } public static int randomWithRange(int min, int max){ Random rand= new Random(); int randomNum = rand.nextInt((max-min)+1)+min; return randomNum; } } nevermind, found it: @SubscribeEvent public void TemBOPloot(BreakEvent event) { System.out.println("event has occured"); Block block = event.block; World world = event.world; int x = event.x; int y = event.y; int z = event.z; int meta = block.getDamageValue(world, x, y, z); if (meta ==1 || meta ==3){ System.out.println("meta found"); if (block==BOPCBlocks.leaves3 ){ System.out.println("condition met"); int random = randomWithRange(0,10); if (random == 1){ ItemStack stack = new ItemStack(TemItems.cherry); EntityItem item = new EntityItem(world,x,y,z, stack); world.spawnEntityInWorld(item); } } } } public static int randomWithRange(int min, int max){ Random rand= new Random(); int randomNum = rand.nextInt((max-min)+1)+min; return randomNum; } } I looked into the breakevent class and found -block.getDamageValue(world, x, y, z)- I think my problem is now solved. I am looking at their source code and I don't see a reason why the event shouldn't fire. The leaveblocks from bop do not have a harvestdropsevent, so instead i used the breakevent and this works. Thank you! Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
Draco18s Posted June 7, 2016 Posted June 7, 2016 You should check for block first, then meta. Also, you shouldn't use block.getDamageValue , you should use world.getBlockMetadata . The default implementation of the former calls Block#damageDropped, which is not necessarily the same as the block's current metadata value. 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.
winnetrie Posted June 7, 2016 Author Posted June 7, 2016 You should check for block first, then meta. Also, you shouldn't use block.getDamageValue , you should use world.getBlockMetadata . The default implementation of the former calls Block#damageDropped, which is not necessarily the same as the block's current metadata value. Yeah you're right i should check the block first then meta. I tried world.getBlockMetadata before (that was my first idea too) but that doesn't do anything. That's why i looked into the breakevent class i and found the block.getDamageValue. Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
Draco18s Posted June 7, 2016 Posted June 7, 2016 I tried world.getBlockMetadata before (that was my first idea too) but that doesn't do anything. What do you mean it doesn't do anything? 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.
winnetrie Posted June 8, 2016 Author Posted June 8, 2016 What do you mean it doesn't do anything? well, it does do something for sure, but not the thing i want. Let's say it doesn't work then. So i ran a small test to know why that doesn't work. So when i do it like this: public class TemExtraBOPDrops { @SubscribeEvent public void TemBOPloot(BreakEvent event) { //System.out.println("event has occured"); Block block = event.block; World world = event.world; int x = event.x; int y = event.y; int z = event.z; if (block==BOPCBlocks.leaves3 ){ //int meta = block.getDamageValue(world, x, y, z); int meta = world.getBlockMetadata(x, y, z); System.out.println(meta); if (meta ==1 || meta ==3){ int random = randomWithRange(0,10); if (random == 1){ ItemStack stack = new ItemStack(TemItems.cherry); EntityItem item = new EntityItem(world,x,y,z, stack); world.spawnEntityInWorld(item); } } } } public static int randomWithRange(int min, int max){ Random rand= new Random(); int randomNum = rand.nextInt((max-min)+1)+min; return randomNum; } } then depending wich of the 2 leaves i "break" the variable meta returns 11 or 9. (sometimes it returns 1 or 3 too, but very rare) Because i need to check if it's 1 or 3 , the if statement will never return true. I don't know why it returns 11 and 9, maybe my code is wrong or maybe i really need to use block.getDamageValue(world, x, y, z) And i'm pretty sure the metadata of those block are 1 and 3. You have more experience in this, so maybe you know why it is returning 11 and 9. EDIT:i'm completely confused now. I did the /give command to see what happens if i enter 9 or 11 as value. I found out that /give playername biomesoplenty:leaves3 10 9 give me the right leaves I also found out when replacing meta 9 with 1, 5, 9, 13, 17, 21, and so on gives the same block (they do not stack). Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
Draco18s Posted June 8, 2016 Posted June 8, 2016 Ahhh. Gotcha. See, "it doesn't work" isn't sufficient to understand the problem. "The blocks have a metadata of 11 or sometimes 9" however, is. You need some bitwise operators. int meta = world.getBlockMetadata(x, y, z) & 3; That'll strip of the decay checking flags. 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.
winnetrie Posted June 8, 2016 Author Posted June 8, 2016 Nice, thank you! This works fine now! Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
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.