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

So I have this code which makes it so that my ores drop an item rather than themselves (like Diamond Ore does) but I can't get it to drop more with fortune, how would I make it so that they multiply with fortune like diamond ore does?

 

package com.MonstrousApple.mod.gems;

import java.util.Random;

import com.MonstrousApple.mod.MAGlobal;
import com.MonstrousApple.mod.items.MAItems;
import com.MonstrousApple.mod.ores.MAOres;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;

public class MAGem extends Block {

public MAGem(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) {
	if (this == MAGems.SapphireOre) {
		return MAItems.Sapphire;
		}
		else if (this == MAGems.RubyOre) {
		return MAItems.Ruby;
		}
		else {
		return null;
		}
	}


public int quantityDropped(Random random) {
	if (this == MAGems.SapphireOre) {
		return 4 + random.nextInt(5);
		}
		else if (this == MAGems.RubyOre) {
		return 4 + random.nextInt(5);
		}
		else {
		return 0;
		}
	}
}

Override

Block#quantityDropped(IBlockState, int, Random)

instead of

Block#quantityDropped(Random)

, this gives you the fortune level.

 

I would personally recommend having fields to store the dropped item and quantity rather than checking which instance

this

is, it makes your code more extendable.

 

Side note: Always annotate override methods with

@Override

so you get a compiler error if they don't override a super method.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

So like this? Or is there more to add?

 

package com.MonstrousApple.mod.gems;

import java.util.Random;

import com.MonstrousApple.mod.MAGlobal;
import com.MonstrousApple.mod.items.MAItems;
import com.MonstrousApple.mod.ores.MAOres;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;

public class MAGem extends Block {

public MAGem(String unlocalizedName, Material material, float hardness, float resistance) {
	super(material);

	this.setCreativeTab(MAGlobal.maCreativeTabOres);
	this.setUnlocalizedName(unlocalizedName);
	this.setHardness(hardness);
	this.setResistance(resistance);
	}

@Override
public Item getItemDropped(IBlockState state, Random random, int fortune) {
	if (this == MAGems.SapphireOre) {
		return MAItems.Sapphire;
		}
		else if (this == MAGems.RubyOre) {
		return MAItems.Ruby;
		}
		else if (this == MAGems.DiamondOre) {
		return Items.diamond;
		}
		else {
		return null;
		}
	}

public int quantityDropped(IBlockState state, int fortune, Random random) {
	if (this == MAGems.SapphireOre) {
		return 4 + random.nextInt(5);
		}
		else if (this == MAGems.RubyOre) {
		return 4 + random.nextInt(5);
		}
		else {
		return 0;
		}
	}
}

Your new code is doing exactly the same thing as your old code, you need to add the fortune bonus yourself.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Look at

BlockOre#quantityDroppedWithBonus

to see how vanilla ores add the fortune bonus.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.