Posted December 26, 20186 yr Hello fellow modders, I have made some seeds for my crop and I wanted to know how I can get these seeds to be dropped from grass! I know this is possible as I have seen it done before however I am clueless of how it is done. Can anyone help me doing this as I would love to have this in my mod. Many thanks in advance!
December 26, 20186 yr Author 3 minutes ago, diesieben07 said: You can add drops to other blocks by subscribing to BlockEvent.HarvestDropsEvent. this may sound stupid, but can you remind me of how to do that pls lol, ive took a break from programming and just got back into it, so ive forgotten a lot
December 26, 20186 yr Author 25 minutes ago, diesieben07 said: You can read up on how Forge's events work in the documentation. so what do I need to put inside of my Event class? this is what I currently have: package com.turtywurty.minecraftmadness.events.seeds; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class SeedsFromGrassEvent { @SubscribeEvent public void getSeedsFromGrass(HarvestDropsEvent event) { } }
December 26, 20186 yr Author 22 minutes ago, diesieben07 said: First of all, I doubt you own that domain name. Actually, I know you don't own it, since it's still for sale. what domain name lol
December 26, 20186 yr Author that's my package name not my domain name, I use it for all my mods but ok Edited December 26, 20186 yr by UM3 F0R TH3 W1N
December 26, 20186 yr Author 1 minute ago, diesieben07 said: They are the same. well that's not important so ok
December 26, 20186 yr Author 28 minutes ago, diesieben07 said: Do add your drop, that doesn't make sense anyways ^
December 26, 20186 yr Author and theres no methods that it lets me use Edited December 26, 20186 yr by UM3 F0R TH3 W1N
December 26, 20186 yr Author 1 minute ago, diesieben07 said: No. You need to call HarvestDropsEvent#getDrops and add your desired drops to it. it doesn't let me call it
December 26, 20186 yr Author 2 minutes ago, diesieben07 said: Provide code of what you have tried. package com.turtywurty.minecraftmadness.events.seeds; import java.util.List; import net.minecraft.item.ItemStack; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class SeedsFromGrassEvent { public final List<ItemStack> drops; @SubscribeEvent public void getSeedsFromGrass(HarvestDropsEvent event) { } public List<ItemStack> getDrops() { return drops; } }
December 26, 20186 yr Author Just now, diesieben07 said: That is nowhere near what I said. Why did you add a field? Why did you add a method? You need to call a method. I tried, it wont let me
December 26, 20186 yr Author 1 minute ago, diesieben07 said: Again: Show. What. You. Tried. package com.turtywurty.minecraftmadness.events.seeds; import java.util.List; import net.minecraft.item.ItemStack; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class SeedsFromGrassEvent { @SubscribeEvent public void getSeedsFromGrass(HarvestDropsEvent event) { getDrops(); } } but getDrops(); has an error saying that I need to create the method
December 26, 20186 yr Author Just now, diesieben07 said: Yes, because getDrops is a method on HarvestDropsEvent. You know Java, right? a bit but as I said, I took a break, so ive forgotten a lot of it also: HarvestDropsEvent.getDrops(); doesn't work either
December 26, 20186 yr Author 5 minutes ago, diesieben07 said: It is not a static method... //but HarvestDropEvents h = new HarvestDropEvents(); h.getDrops(); //doesn't work either Edited December 26, 20186 yr by UM3 F0R TH3 W1N
December 26, 20186 yr Author so, this works: package com.turtywurty.minecraftmadness.events.seeds; import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class SeedsFromGrassEvent { @SubscribeEvent public void getSeedsFromGrass(HarvestDropsEvent event) { event.getDrops(); } } so what do I do now, we're getting somewhere now lol Edited December 26, 20186 yr by UM3 F0R TH3 W1N
December 26, 20186 yr Author 11 minutes ago, diesieben07 said: Add your desired item stack to the List you have now obtained. This is not a chat room. alright, thanks soo much for the help, sorry for me being a noob but I've got the hang of it now, i'm currently in the process of testing it and im hoping it works, however don't I need to call this method in my main class or something
December 26, 20186 yr Author 7 minutes ago, diesieben07 said: You will need to register your event handler to the event bus, refer to the documentation linked above for more information on that. so like this: MinecraftForge.EVENT_BUS.register(SeedsFromGrassEvent.class);
December 26, 20186 yr Author Just now, diesieben07 said: That would be for a static event handler method, your code so far has shown a non-static one. so this would work right: SeedsFromGrassEvent seedEvent = new SeedsFromGrassEvent(); MinecraftForge.EVENT_BUS.register(seedEvent);
December 26, 20186 yr Author 1 minute ago, diesieben07 said: Why don't you try it? ok, it works but they drop every single time, is there a way I can change it to be the exact same as normal seeds?
December 26, 20186 yr Author 9 minutes ago, diesieben07 said: Tall grass has a drop-chance of 1/8 for seeds. So, generate a random number from 0 through 7 (Random#nextInt(8)) and check if it's 0. You can see this in BlockDoublePlant#getItemDropped. ok thx so much, however it says that HarvestDropsEvent#getDropChance() is a float value not integer Edited December 26, 20186 yr by UM3 F0R TH3 W1N
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.