Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

  • 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

  • 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)
    {
        
    }
}

  • 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

 

  • 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

 

  • 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; 
    }
}

  • 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

  • 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

  • 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

 

  • Author
5 minutes ago, diesieben07 said:

It is not a static method...

//but 
HarvestDropEvents h = new HarvestDropEvents();
       h.getDrops();
//doesn't work either

Edited by UM3 F0R TH3 W1N

  • 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 by UM3 F0R TH3 W1N

  • 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

  • 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);
 

  • 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);

  • 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?

  • 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 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.