Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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;

 

}

 

 

}

 

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.

u mean this?

return this == Example1 ? 1 :(this == Example2 ? 2 : (this == Example3 ? 3 : 0))

my Mod: Extended RPG [W.I.P]

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.