Jump to content

How do I add a drop to leaves ?


Irhala
 Share

Recommended Posts

Is there a way to add drops to leaves ? I'm trying to make them drop some sticks sometimes.

I found a forge method to add drops to tall grass, MinecraftForge.addGrassSeed(...), but I didn't found the same for leaves.

 

I don't want to change base class files ._.

 

Thanks for your help  ;)

Link to comment
Share on other sites

Then, you should just look under minecraft's leaves, see how they do the "droprate" for their items as well as whatever else you need, and modify their code as you need to. Sorry, if this isn't what you want, I have trouble understanding lots of people. :P

Link to comment
Share on other sites

Then, you should just look under minecraft's leaves, see how they do the "droprate" for their items as well as whatever else you need, and modify their code as you need to. Sorry, if this isn't what you want, I have trouble understanding lots of people. :P

No, he just needs an event handler. If he does it like that he needs to make it a coremod, and nobody wants to make their mod a coremod if they don't have to.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

there are forge events (like this), but as far as i can tell there isn't one which is called when the block is broken (see full list). Someone correct me if i'm wrong, but after a few Google searches all I've found are people asking why there isn't one.

 

Ah. Well, I get it now. :P Hmm.... Could you make a class that extended the leaf drops?

 

that probably wouldn't work. Your class wouldn't be called when the block was broken unless you overwrote some vanilla code, which is something i guess you already know you don't want to do.

 

You could, possibly, try doing something like the following where you register your blocks:

Block.blocksList[block.leaves.blockID] = null;
myLeaves = new BlockMyLeaves(Block.leaves.blockID); //BlockMyLeaves being your extension of BlockLeaves and myLeaves being the block name

 

not sure how well that will work, but it could be worth a shot.

 

good luck :)

Link to comment
Share on other sites

You could, possibly, try doing something like the following where you register your blocks:

Code: [select]

Block.blocksList[block.leaves.blockID] = null;

myLeaves = new BlockMyLeaves(Block.leaves.blockID); //BlockMyLeaves being your extension of BlockLeaves and myLeaves being the block name

 

not sure how well that will work, but it could be worth a shot.

 

Wouldn't this be useful if I were using my own Leaves, not vanilla's leaves ?

Link to comment
Share on other sites

you create a class which extends BlockLeaves, this class has all the properties of BlockLeaves. Then be removing the vanilla block form the array and replacing it with your block you cause your block to be generated whenever the vanilla leaves would have been. You can then override the drops so that it drops sticks as well as saplings.

 

P.S you will need to override the drops as follows so that the probability of saplings does not change:

    @Override
    public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
    {
        ArrayList<ItemStack> ret = super.getBlockDropped(world, x, y, z, metadata, fortune);
        ret.add(new ItemStack(Item.stick.itemID, 1));
        return ret;
    }

Link to comment
Share on other sites

shouldn't cause too much incompatibility. Most mods which reference leaves will be doing it by Block.leaves.blockID, which is the same as our blockID, or by if(block instanceof BlockLeaves) which is true for our block also as it extends BlockLeaves. A problem may occur if they do if(block.class == BlockLeaves.Class) but this wouldn't be anything critical, and i think should be fairly uncommon.

Link to comment
Share on other sites

But if you're able to make the BlockMyLeaves extension work, i'd be grateful, because it would teach me so much more :)

I'd be able to use it for other parts of Minecraft, especially the block breaking system (no longer tree-punching !)

Link to comment
Share on other sites

But if you're able to make the BlockMyLeaves extension work, i'd be grateful, because it would teach me so much more :)

I'd be able to use it for other parts of Minecraft, especially the block breaking system (no longer tree-punching !)

Create your BlockMyLeaves extends BlockLeaves, then put this in your @Init:

Block.blocksList[blockLeaves.blockID] = new BlockMyLeaves();

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

Create your BlockMyLeaves extends BlockLeaves, then put this in your @Init:

Block.blocksList[blockLeaves.blockID] = new BlockMyLeaves();

 

 

argh!! not like that!

you will get a problem with

if (blocksList[par1] != null)
        {
            throw new IllegalArgumentException("Slot " + par1 + " is already occupied by " + blocksList[par1] + " when adding " + this);
        }

in the block constructor. Hence i did it how i posted.

Block.blocksList[block.leaves.blockID] = null;
myLeaves = new BlockMyLeaves(Block.leaves.blockID); //BlockMyLeaves being your extension of BlockLeaves and myLeaves being the block name

 

then the constructor for your block will put it into the array.

Link to comment
Share on other sites

I tried, but when I create the constructor (either as public or protected)

protected BlockMyLeaves(int par1) {
	super(par1);
}

It tells me to add a BlockMyLeaves(int) constructor, and when i click on it, it creates the same one -.-

Link to comment
Share on other sites

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

 Share



×
×
  • Create New...

Important Information

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