BobMan Posted November 2, 2014 Share Posted November 2, 2014 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! Quote Link to comment Share on other sites More sharing options...
BobMan Posted November 2, 2014 Author Share Posted November 2, 2014 And how would I do that? Quote Link to comment Share on other sites More sharing options...
Manslaughter777 Posted November 3, 2014 Share Posted November 3, 2014 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 Quote Link to comment Share on other sites More sharing options...
Manslaughter777 Posted November 3, 2014 Share Posted November 3, 2014 a) Why are you using an int[]? Use an Item[] or better yet a List<Item>. b) getItemDropped is for Blocks. A) an int still works and you need it for the random generating part B) he is using a block so the getItemDropped works. If u think this is wrong post ur own code Quote Link to comment Share on other sites More sharing options...
fr0st Posted November 3, 2014 Share Posted November 3, 2014 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.. Quote I try my best, so apologies if I said something obviously stupid! Link to comment Share on other sites More sharing options...
daafganggdg Posted November 4, 2014 Share Posted November 4, 2014 A) an int still works and you need it for the random generating part thats NOT how you use an array 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.