Posted May 6, 201411 yr Random Item drops problem. This bit of code works but how do you make it so you can get 4 arrows. For example I break the block and get a apple how can I get more than one apple at a time please help. public Item getItemDropped(int metadata, Random random, int fortune){ int drop = random.nextInt(; if (drop == 0){ return Items.apple; }else if (drop == 1){ return Items.arrow ; }else if (drop == 2){ return Items.gold_ingot; }else if (drop == 3){ return Items.bed; }else if (drop == 4){ return Items.leather; }else if (drop == 5){ return Items.book; }else if (drop == 6){ return Items.lava_bucket; }else{ return Items.diamond; } }
May 6, 201411 yr you have to override quantityDropped e.g. @Override public int quantityDropped(final Random random) { return 4; } I am the author of Draconic Evolution
May 6, 201411 yr public int quantityDropped(Random random) { return 1 + random.nextInt(3); } the one that brandon3055 wrote will always drop 4 this will give it a bit of "randomness"
May 6, 201411 yr Author public int quantityDropped(Random random) { return 1 + random.nextInt(3); } the one that brandon3055 wrote will always drop 4 this will give it a bit of "randomness" How do you make so it only gives 4 of a single item on the list instead of giving a random number to all of them
May 6, 201411 yr To make the block always drop 4 items (apples, arrows, etc.) just type this: @Override public int quantityDropped(int meta, int fortune, Random random) { return 4; } If you want the block to drop 1, 2, 3, 4,... items depending in the item dropped (like one time 4 apples, another time 3 arrows, another time 7 books....) then type this: private Item itemDropped = null; private int quantityDropped = 0; @Override public Item getItemDropped(int metadata, Random random, int fortune) { int drop = random.nextInt(; if (drop == 0) { itemDropped = Items.apple; } else if (drop == 1) { itemDropped = Items.arrow; } else if (drop == 2) { itemDropped = Items.gold_ingot; } else if (drop == 3) { itemDropped = Items.bed; } else if (drop == 4) { itemDropped = Items.leather; } else if (drop == 5) { itemDropped = Items.book; } else if (drop == 6) { itemDropped = Items.lava_bucket; } else { itemDropped = Items.diamond; } return itemDropped; } @Override public int quantityDropped(int meta, int fortune, Random random) { if(itemDropped == Items.apple) { quantityDropped = 3; } else if(itemDropped == Items.arrow) { quantityDropped = 4; } else { quantityDropped = 7; } return quantityDropped; } Adding some randomness to the quantity dropped: quantityDropped = 5 + random.nextInt(6); // quantity dropped from 5 to 10 items You can add more else if statements on the quantityDropped() method EDIT: Tip, you can use switch instead a lot of else statements, on getItemDropped . E.g: switch(rand.nextInt(6)) { case 1: return Item1; case 2: return Item2; case 3: return Item3; case 4: return Item4; case 5: return Item5; default: return ItemDefault; }
May 6, 201411 yr use Item.getItemFromBlock(Blocks.cobblestone); I am the author of Draconic Evolution
May 6, 201411 yr Author And can you make it so some drops are more rare sorry for asking to many questions just love the idea
May 6, 201411 yr And can you make it so some drops are more rare sorry for asking to many questions just love the idea switch(rand.nextInt(5)) { case 0: case 1: case 2: case 3: itemDropped = Items.bed; break; case 4: itemDropped = Items.blaze_powder; break; } There are 1/5 posiblities of drop a blaze powder and 4/5 of drop a bed That code is equal to this: int drop = rand.nextInt(5); if(drop == 0 || drop == 1 || drop == 2 || drop == 3) { itemDropped = Items.bed; } else { itemDropped = Items.blaze_powder; }
May 6, 201411 yr Author I found a problem with the code else if(itemDropped == Ruby.Ruby) { quantityDropped = 2; } So I made it so you can get two Ruby's from the ore but else { quantityDropped = 1; } return quantityDropped; If I put quantityDropped = 1 to 0 then noting drops but if I put it to 1 then only of the of item drops but in the code I put quantityDropped = 2 for ruby. How do you fix this for all of them
May 6, 201411 yr I found a problem with the code else if(itemDropped == Ruby.Ruby) { quantityDropped = 2; } So I made it so you can get two Ruby's from the ore but else { quantityDropped = 1; } return quantityDropped; If I put quantityDropped = 1 to 0 then noting drops but if I put it to 1 then only of the of item drops but in the code I put quantityDropped = 2 for ruby. How do you fix this for all of them I'm not really sure about what do you mean exactly
May 6, 201411 yr Author I mean I want it to drop 2 ruby's if it picks ruby from the random code but at the bottom it says else { quantityDropped = 1; } return quantityDropped; if I changed that 1 to 0 then noting comes out of the block and if I keep it at one only 1 ruby comes out instead of 2 ruby's
May 6, 201411 yr I mean I want it to drop 2 ruby's if it picks ruby from the random code but at the bottom it says else { quantityDropped = 1; } return quantityDropped; if I changed that 1 to 0 then noting comes out of the block and if I keep it at one only 1 ruby comes out instead of 2 ruby's Ok, now i understand you, but i don't know why it happens. Could you show me all your class or just the quantityDropped() method?
May 6, 201411 yr Author Here is my TinOre class where I am testing it package com.MoreEverything.block; import java.util.Random; import com.MoreEverything.World.TinOre; import com.MoreEverything.item.Ruby; import com.MoreEverything.lib.Strings; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; public class TinOreBlock extends Block { public TinOreBlock(Material p_i45394_1_) { super(p_i45394_1_); // TODO Auto-generated constructor stub } { this.setBlockName(Strings.TinOreBlock); this.setHardness(1f); this.setResistance(3f); this.setCreativeTab(CreativeTabs.tabBlock); this.setStepSound(Block.soundTypeStone); this.setHarvestLevel("pickaxe", 0); } private Item itemDropped = null; private int quantityDropped = 0; @Override public Item getItemDropped(int metadata, Random random, int fortune) { int drop = random.nextInt(2); if(drop == 0) { itemDropped = Items.bed; } else { itemDropped = Items.egg; } if(drop == 1) { itemDropped = Items.apple; } else { itemDropped = Items.coal; } return itemDropped; } @Override public int quantityDropped(int meta, int fortune, Random random) { if(itemDropped == Items.bed) { quantityDropped = 2; } else if(itemDropped == Items.apple) { quantityDropped = 4; } /**else if(itemDropped == Items.gold_ingot) { quantityDropped = 2; } else if(itemDropped == Items.emerald) { quantityDropped = 1; } else if(itemDropped == Items.diamond) { quantityDropped = 1; } /** else if(itemDropped == Item.getItemFromBlock(Blocks.cobblestone)) { quantityDropped = 6; } else if(itemDropped == Tin.Tin) { quantityDropped = 5; } */ else { quantityDropped = 1; } return quantityDropped; } } Also I am using the code you gave me for it to make it a bit rare for other items can you make it work please
May 6, 201411 yr Author Also can you make it so only 4 of one item comes out at a time doesn't work for me I don't know why
May 6, 201411 yr Here is my TinOre class where I am testing it package com.MoreEverything.block; import java.util.Random; import com.MoreEverything.World.TinOre; import com.MoreEverything.item.Ruby; import com.MoreEverything.lib.Strings; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; public class TinOreBlock extends Block { public TinOreBlock(Material p_i45394_1_) { super(p_i45394_1_); // TODO Auto-generated constructor stub } { this.setBlockName(Strings.TinOreBlock); this.setHardness(1f); this.setResistance(3f); this.setCreativeTab(CreativeTabs.tabBlock); this.setStepSound(Block.soundTypeStone); this.setHarvestLevel("pickaxe", 0); } private Item itemDropped = null; private int quantityDropped = 0; @Override public Item getItemDropped(int metadata, Random random, int fortune) { int drop = random.nextInt(2); if(drop == 0) { itemDropped = Items.bed; } else { itemDropped = Items.egg; } if(drop == 1) { itemDropped = Items.apple; } else { itemDropped = Items.coal; } return itemDropped; } @Override public int quantityDropped(int meta, int fortune, Random random) { if(itemDropped == Items.bed) { quantityDropped = 2; } else if(itemDropped == Items.apple) { quantityDropped = 4; } /**else if(itemDropped == Items.gold_ingot) { quantityDropped = 2; } else if(itemDropped == Items.emerald) { quantityDropped = 1; } else if(itemDropped == Items.diamond) { quantityDropped = 1; } /** else if(itemDropped == Item.getItemFromBlock(Blocks.cobblestone)) { quantityDropped = 6; } else if(itemDropped == Tin.Tin) { quantityDropped = 5; } */ else { quantityDropped = 1; } return quantityDropped; } } Also I am using the code you game me for it to make it a bit rare for other items but if you look at the code it gives apple and coal can you make it work please First, the half of this code does nothing: @Override public Item getItemDropped(int metadata, Random random, int fortune) { int drop = random.nextInt(2); if(drop == 0) { itemDropped = Items.bed; } else { itemDropped = Items.egg; } if(drop == 1) { itemDropped = Items.apple; } else { itemDropped = Items.coal; } return itemDropped; } If the "drop" is equal to 1 then drops an apple, and if don't (so if it's 0) then drops coal. So it will never drop beds or egg. (this happens because the last lines overrides the first ones) Second as the block only drops apples or coal, it will only drop 4 apples else if(itemDropped == Items.apple) { quantityDropped = 4; } Or 1 coal: else { quantityDropped = 1; }
May 6, 201411 yr Author @SackCastellon I tried but failed will you be able to change my code so it's only drops a curtan number of 1 item at a time please and make some items rare like diamond so 1/20 chance of getting diamond and do it with all of them but the non rare items are like 1/3 for example only if you can but can you keep the quantityDropped = numbers the same if that's ok package com.MoreEverything.block; import java.util.Random; import com.MoreEverything.World.TinOre; import com.MoreEverything.item.Ruby; import com.MoreEverything.lib.Strings; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; public class TinOreBlock extends Block { public TinOreBlock(Material p_i45394_1_) { super(p_i45394_1_); // TODO Auto-generated constructor stub } { this.setBlockName(Strings.TinOreBlock); this.setHardness(1f); this.setResistance(3f); this.setCreativeTab(CreativeTabs.tabBlock); this.setStepSound(Block.soundTypeStone); this.setHarvestLevel("pickaxe", 0); } private Item itemDropped = null; private int quantityDropped = 0; @Override public Item getItemDropped(int metadata, Random random, int fortune) { int drop = random.nextInt(7); if (drop == 0) { itemDropped = Items.coal; } else if (drop == 1) { itemDropped = Items.iron_ingot; } else if (drop == 2) { itemDropped = Items.gold_ingot; } else if (drop == 3) { itemDropped = Items.emerald; } else if (drop == 4) { itemDropped = Items.diamond; } else if (drop == 5) { itemDropped = Ruby.Ruby; } else if (drop == 6) { itemDropped = Items.dye; } else if (drop == 7) { itemDropped = Items.quartz; } else if (drop == { itemDropped = Item.getItemFromBlock(Blocks.cobblestone); } /** else if (drop == 6) { itemDropped = Tin.Tin; } */ else { itemDropped = Items.egg; } return itemDropped; } @Override public int quantityDropped(int meta, int fortune, Random random) { if(itemDropped == Items.coal) { quantityDropped = 5; } else if(itemDropped == Items.iron_ingot) { quantityDropped = 3; } else if(itemDropped == Items.gold_ingot) { quantityDropped = 2; } else if(itemDropped == Items.emerald) { quantityDropped = 1; } else if(itemDropped == Items.diamond) { quantityDropped = 1; } else if(itemDropped == Ruby.Ruby) { quantityDropped = 2; } else if(itemDropped == Items.dye) { quantityDropped = 4; } else if(itemDropped == Items.quartz) { quantityDropped = 1; } else if(itemDropped == Item.getItemFromBlock(Blocks.cobblestone)) { quantityDropped = 6; } /** else if(itemDropped == Tin.Tin) { quantityDropped = 5; } */ else { quantityDropped = 1; } return quantityDropped; } }
June 21, 201411 yr I have no idea just wanted to make it like Lucky block What if you try this! Sorry if the code is wrong i'm 13 and new to programming and this forum! by the way the diamond block has a 3 out of 28 chance of being dropped! @Override public Item getItemDropped(int metadata, Random random, int fortune) { switch(random.nextInt(28)) { case 0: case 1: case 2: case 3: case 4: case 5: itemDropped = Item.getItemFromBlock(Blocks.grass); System.out.println("5 or under"); break; case 6: case 7: case 8:case 9: case 10: itemDropped = Item.getItemFromBlock(Blocks.cobblestone); System.out.println("6 to 10"); break; case 11: case 12: case 13:case 14: case 15: itemDropped = Item.getItemFromBlock(Blocks.sandstone); System.out.println("11 to 15"); break; case 16: case 17: case 18: case 19: case 20: itemDropped = Item.getItemFromBlock(Blocks.wool); System.out.println("16 to 20"); break; case 21: case 22: case 23: case 24: case 25: itemDropped = Item.getItemFromBlock(Blocks.bookshelf); System.out.println("21 to 25"); break; case 26: case 27: case 28: itemDropped = Item.getItemFromBlock(Blocks.diamond_block); System.out.println("26 to 28"); break; }
June 21, 201411 yr You do realize this post is almost 2 months old, right? I Know Just Posted If Anyone Was Needing Help and Searched On Google and The Help Would be There! But yea It Wasn't the Greatest Idea! Sorry!
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.