Jump to content

Recommended Posts

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!

Posted
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

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

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

Posted
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

Posted
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

 

Posted (edited)

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
Posted
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

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

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

Posted (edited)
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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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