Jump to content

Item Dropped From Block


Monstrous_Apple

Recommended Posts

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;

 

}

 

 

}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.