winnetrie Posted May 8, 2016 Posted May 8, 2016 I'm looking for something i can remove/add drop(s) of an existing block. I found some information on forums but nothing like that was working, so i tried something myself: I made a new class for this and i do not even know if this is right. If it is right, how do i register this? public class TemDrops { @SubscribeEvent public void Temloot(BlockEvent.HarvestDropsEvent event) { List<ItemStack> loot = event.drops; Iterator<ItemStack> Leash = loot.iterator(); while (Leash.hasNext()) { ItemStack is = Leash.next(); if (is != null && is.getItem() == Item.getItemFromBlock(Blocks.leaves)) { ((List<ItemStack>) Leash).add(new ItemStack(Items.potato)); } } } } Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
Ernio Posted May 8, 2016 Posted May 8, 2016 MinecraftForge.EVENT_BUS.register(new YourClass()); In pre-1.8 there is also FML event bus, but that is for different events. (google). Quote 1.7.10 is no longer supported by forge, you are on your own.
winnetrie Posted May 8, 2016 Author Posted May 8, 2016 MinecraftForge.EVENT_BUS.register(new YourClass()); In pre-1.8 there is also FML event bus, but that is for different events. (google). Yeah that was the first thing i tried, but it didn't do anything i registered it in my CommonProxy class like this: public void init(FMLInitializationEvent event) { TemRecipes.init(); if(Loader.isModLoaded("BiomesOPlenty")){ BOPAddonRecipes.init(); } MinecraftForge.EVENT_BUS.register(new TemDrops()); // GameRegistry.registerWorldGenerator(new TemChunkGenerator(), 1); GameRegistry.registerWorldGenerator(new ChalkStoneGenerator(), 10); } So i guess there is something wrong with the TemDrops.class itself Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
Ernio Posted May 8, 2016 Posted May 8, 2016 Are you saying method is not called or logic is not working like it is supposed to? Make Syso there and check. Also - very important - Harvesting is NOT called in creative mode (notice there is no drops when you pawn block in creative). Ppl often forget that. Quote 1.7.10 is no longer supported by forge, you are on your own.
winnetrie Posted May 8, 2016 Author Posted May 8, 2016 It seems (for me) the registering isn't done. I placed on multiple line in my TemDrops.class the system.out.println("TEST TEST TEST"); and none of these are showing up. I'm aware of the creative mode thing. Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
Draco18s Posted May 8, 2016 Posted May 8, 2016 For 1.7.10, the event is fired on the MinecraftForge.EVENT_BUS , which you are doing. Show your current TemDrops class with the "TEST TEST TEST" line. 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 May 8, 2016 Author Posted May 8, 2016 I have it working now. I tried something else: public class TemDrops { @SubscribeEvent public void Temloot(BlockEvent.BreakEvent e) { Block block =e.block; if ( block instanceof BlockLeaves) { Random r = new Random(); if ( r.nextFloat() < 0.2F){ EntityItem i = new EntityItem(e.world, e.x, e.y, e.z, new ItemStack(Items.stick)); System.out.println("TEST TEST TESTertje"); e.world.spawnEntityInWorld(i); } } } } I have seen a page "jabelar's minecraft forge tutorials"(lot's of information there!! ). There the autor says on his page to use breakevent instead of harvestevent to get a drop from blocks like leaves. So the registering was done but my method wasn't right. I now have made a better 1 with some help ofc. While this method adds a drop, i was wondering how i would remove a drop. I also made it check an instance of BlockLeaves. EDIT: Oh btw leaves DO drop the sticks in creative mode, but only the sticks. Maybe i need to make a check if the player is in creative mode or not. Does it matter anyway? Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
Draco18s Posted May 8, 2016 Posted May 8, 2016 Leaves still triggers HarvestDropsEvent . It overrides harvestBlock , but all it does is call super(). The block default method calls dropBlockAsItem which passes off to dropBlockAsItemWithChance which calls getDrops just prior to firing the event, which BlockLeaves overrides again (to possibly drop a sapling). Adding a stick to that is just as easy as event.drops.add(new ItemStack(...)) Removing is a bit trickier, as you should loop through the array to locate the item you want to remove, and for every other item add it to a new array (you don't want to just delete everything: some other mod may have added an item that should still drop!). Then call event.drops.clear() and then copy your saved list back to event.drops. 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.
Draco18s Posted May 9, 2016 Posted May 9, 2016 Because I forget things. 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 May 13, 2016 Author Posted May 13, 2016 Could i have some help plz, how to do it right? Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
winnetrie Posted May 13, 2016 Author Posted May 13, 2016 I have this now: public class TemDrops { @SubscribeEvent public void Temloot(HarvestDropsEvent event) { System.out.println("TEST TEST TESTertje"); Iterator<ItemStack> Leash = event.drops.iterator(); while (Leash.hasNext()) { Block block= event.block; ItemStack is = Leash.next(); if (block != Blocks.leaves) { System.out.println("nothing"); } else{ System.out.println("leaves!!"); event.drops.add(new ItemStack(Items.potato)); } } } } But this isn't working at all and it makes minecraft crash if the 'else' statement triggers. Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
winnetrie Posted May 13, 2016 Author Posted May 13, 2016 You are trying to add to a List while iterating through it, this is not allowed. AAAH yes now i understand it. So i can only remove from that list while iterating but not adding. To add something to the drop i now have this: public class TemDrops { @SubscribeEvent public void Temloot(HarvestDropsEvent event) { Block block = event.block; if (block instanceof BlockLeaves){ event.drops.add(new ItemStack(Items.potato)); } } } I didn't had a need to remove something but i was wondering how to. It is ennoying not to know. And yes i really need to study more java, i know! Quote Try out my new Modpack for MC 1.15.2 https://www.curseforge.com/minecraft/modpacks/terran-civilization
Draco18s Posted May 13, 2016 Posted May 13, 2016 Yes. There's no point in adding inside the loop (even if it didn't crash, you'd then have to check the item you just added as well and that could be bad!). Also, your loop in your prior post makes no sense. //for each item in the list // save a reference to the item // if the block harvested is Leaves // add potato. You never do anything with the ItemStack 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.