Posted May 2, 201411 yr My block has got this two drops: @Override public Item getItemDropped(int par1, Random rand, int par3) { if(rand.nextInt(10) == 0) { return Item.getItemFromBlock(Blocks.ToLSapling); } else { return Item.getItemFromBlock(net.minecraft.init.Blocks.sapling); } } The net.minecraft.init.Blocks.sapling block has 6 subtypes, and i want my block to drop all of them, not at the same time, one each time, and also with a random chance, like: @Override public int damageDropped(int par1) { if(itemDropped == net.minecraft.init.Blocks.sapling) { return rand.nextInt(5); } else { return 0; } } But I've not found any itemDropped method or field, and also there is no Random rand parameter on the damageDropped method Thanks for helping
May 2, 201411 yr private Random; <-- declare at the top of your class (or bottom, however you like to do it) Then in your block constructor, add: this.random = new Random(); ^ That's how you get a random instance. Also, as a suggestion, I would use the Forge method getDrops(world, x, y, z, metadata, fortune) . It's much more versatile.
May 3, 201411 yr Author private Random; <-- declare at the top of your class (or bottom, however you like to do it) Then in your block constructor, add: this.random = new Random(); ^ That's how you get a random instance. Also, as a suggestion, I would use the Forge method getDrops(world, x, y, z, metadata, fortune) . It's much more versatile. Ok, i've witten this code, but now it only drops vanilla saplings with metadata 0 (oak sapling): private Random random = new Random(); @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> drops = new ArrayList<ItemStack>(); if (random.nextInt(10) == 0) { drops.add(new ItemStack(Blocks.ToLSapling)); } else { drops.add(new ItemStack(net.minecraft.init.Blocks.sapling, 1, random.nextInt(5))); } return drops; } Please tell me if made any mistake. Thanks
May 3, 201411 yr Author Are you absolutely sure? What you have there is basically a 1 in 10 chance for your sapling and then an equal chance for all vanilla saplings (except dark oak). That means you might very well get like a couple oak saplings in a row. Yes, i am. The problem is that the method damageDropped from the extended class (net.minecraft.block.BlockLeaves) was setting the damage to 0. But i don't know how to fix it
May 4, 201411 yr Author I've solved it by another way (which seems to work): private Random random = new Random(); private Item itemDropped = null; private int damageDropped; @Override public Item getItemDropped(int par1, Random rand, int par3) { if(rand.nextInt(10) == 0) { if(rand.nextInt(10) == 0) { itemDropped = Item.getItemFromBlock(Blocks.ToLSapling); } else { itemDropped = Item.getItemFromBlock(net.minecraft.init.Blocks.sapling); } } return itemDropped; } @Override public int damageDropped(int par1) { if(itemDropped == Item.getItemFromBlock(Blocks.ToLSapling)) { damageDropped = 0; } else { damageDropped = random.nextInt(6); } return damageDropped; } But any way, thanks to every one who helped
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.