Jump to content

[1.7.2] How to make a block drop a random item on right click and it destroys


BobMan

Recommended Posts

Well for the random items you should do something like:

 

int[] itemList = new int[20]; //amount of random items

itemList[0] = MainModClass.randomItem1;

itemList[1] = MainModClass.randomItem2;

itemList[2] = MainModClass.randomItem3;

etc..:

 

Then you would want a random thingy.

Random rand = new Random();

int randomInt = rand.nextInt(20); //amount of random items

 

Then in the getItemDropped() method you return:

 

itemList[randomInt];

 

So it would be:

public void getItemDropped(PARAMS HERE) {

return itemList[randomInt];

}

 

This SHOULD work, not 100% cause I didn't test it

 

 

 

Link to comment
Share on other sites

Well... he's here to learn, not to copy-paste ready code..

 

Also, what are you talking about?

itemList should have been a List<Item>, or an item array.. whereas obviously for the random part you need the randomInt as an integer... you might have gotten that wrong..

I try my best, so apologies if I said something obviously stupid!

Link to comment
Share on other sites

A) an int still works and you need it for the random generating part

thats NOT how you use an array :D

B) he is using a block so the getItemDropped works.

OP said on right click.

 

Too the actual problem

I have been wondering how to make a crate and on right click it drops a random item from my mod and the crate disapears? Please respond back. Thank you!

I guess the crate is a block?

 

There's the method

 public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_){}

you want to override in your Crate class,

There you can do your operations

I personally would create an Item Array (a list is probably somewhat smarter)

generate a random number

spawn a EntityItem in the world with yourItemArray[yourRandomNumber]

then say world.setBlockToAir(x, y, z);

and there you go

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.