Jump to content

[1.7.10] How to make multiple Items drop from a single Block w. Random Chance


JohnnyMccurm

Recommended Posts

Hey guys

 

I wondered if there was any way to make a Block drop multiple Items and at different quantities when it is destroyed by the user.

 

What I mean by this is, I'd like, for example a Cheese Block that drops:

A high chance of Cheese Chunks, (1+ 0-3 per destruction)

A moderate chance of Cheese Slices, (0-2)

and has a very rare chance to contain a Mouse. (0-1)

 

How would I achieve this with a Custom block OR an Official Minecraft block?

I thought about using an if or case construct and I figured they weren't completely random (I preset limited outcomes) and I'd like a better way of achieving this result.

Think Java is tough? try BrainFuck!

Link to comment
Share on other sites

Override

public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)

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.

Link to comment
Share on other sites

I am a massive noob when it comes to modding, I only started last week, can you guys provide a practical example? I'd be grateful.

 

And thanks for the help, I appreciate the quick response, this is going to be the core functionality of the mod I seek to create.

 

 

**Update**

 

@Override
    public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
        ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
        drops.add(new ItemStack(Items.coal, world.rand.nextInt(3) + 1));
        drops.add(new ItemStack(Items.iron_ingot, world.rand.nextInt(2) + 1));
        if (world.rand.nextFloat() < 0.5F)
            drops.add(new ItemStack(Items.diamond));
        return drops;
    }

 

Typed this up fast to see if it would work.

 

 

**Update 2**

 

I'm incredibly surprised that it worked, but it did apparently, just need to play around with the code a little.

 

How would I do this for vanilla blocks then?

 

 

Pic related, two custom face items I made dropping from a single block and in different quantities :D

 

 

 

Think Java is tough? try BrainFuck!

Link to comment
Share on other sites

[nobbc]

code here

[/nobbc]

 

Also, define "doesn't work"

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.

Link to comment
Share on other sites

How would I do this for vanilla blocks then?

 

You need to handle the HarvestDropsEvent.  If you haven't used events before, you might want to check my tutorial here: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

 

Events are actually really easy once you figure them out, and are actually the best way to modify most vanilla behavior.  So it is worth while taking the time to figure them out.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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



×
×
  • Create New...

Important Information

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