Monstrous_Apple Posted May 4, 2016 Posted May 4, 2016 Hi guys, I have my code set up like this to drop different items from a certain block, however it only works with one item, what can I do to fix this? Also how do I get multiple items at certain chances to drop from one block? Thanks. package com.MonstrousApple.mod.ores; import java.util.Random; import com.MonstrousApple.mod.MAGlobal; import com.MonstrousApple.mod.items.MAItems; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; public class MAOre extends Block { public MAOre(String unlocalizedName, Material material, float hardness, float resistance) { super(material); this.setCreativeTab(MAGlobal.maCreativeTabOres); this.setUnlocalizedName(unlocalizedName); this.setHardness(hardness); this.setResistance(resistance); } public Item getItemDropped(IBlockState state, Random rand, int fortune) { return this == MAOres.SapphireOre ? MAItems.Sapphire : Item.getItemFromBlock(this); return this == MAOres.RubyOre ? MAItems.Ruby : Item.getItemFromBlock(this); } public int quantityDropped(Random random) { return this == MAOres.SapphireOre ? 4 + random.nextInt(5) : 1; return this == MAOres.RubyOre ? 4 + random.nextInt(5) : 1; } } Quote
Notunknown Posted May 4, 2016 Posted May 4, 2016 if (this == MAOres.SapphireOre) { //Stuff } else if (this == MAOres.RubyOre) { //Stuff } else { //Stuff } OR you could pass what it drops, the minimum amount it drops and the maximum amount it drops to the constructor and just drop that with said amount. Quote
Mark136 Posted May 4, 2016 Posted May 4, 2016 u mean this? return this == Example1 ? 1 :(this == Example2 ? 2 : (this == Example3 ? 3 : 0)) Quote my Mod: Extended RPG [W.I.P]
p455w0rd Posted May 4, 2016 Posted May 4, 2016 well you can't have 2 consecutive returns..the second will never be executed..your IDE should be complaining to you about this. so this: public Item getItemDropped(IBlockState state, Random rand, int fortune) { return this == MAOres.SapphireOre ? MAItems.Sapphire : Item.getItemFromBlock(this); return this == MAOres.RubyOre ? MAItems.Ruby : Item.getItemFromBlock(this); } public int quantityDropped(Random random) { return this == MAOres.SapphireOre ? 4 + random.nextInt(5) : 1; return this == MAOres.RubyOre ? 4 + random.nextInt(5) : 1; } should be more like this: public Item getItemDropped(IBlockState state, Random rand, int fortune) { if (this == MAOres.SapphireOre) { return MAItems.Sapphire; } else if (this == MAOres.RubyOre) { return MAItems.Ruby; } else { return null; } } public int quantityDropped(Random random) { if (this == MAOres.SapphireOre) { return 4 + random.nextInt(5) } else if (this == MAOres.RubyOre) { return 4 + random.nextInt(5) } else { return 0; } } As for dropping different items, you would use the same random/conditional logic above, just do it before you return Quote http://p455w0rd.net/images/forumsignature.png[/img]
Monstrous_Apple Posted May 4, 2016 Author Posted May 4, 2016 Thanks p455w0rd, I used your example and it worked and thanks to everyone for helping too. Quote
p455w0rd Posted May 4, 2016 Posted May 4, 2016 I would just ask that you learn from this (in other words, don't copy pasta and move on or you'll be back here in a few minutes). Notice the final else in that clause...these are essential. Quote http://p455w0rd.net/images/forumsignature.png[/img]
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.