Jump to content

[1.8.9] Fortune With Custom Ores?


Monstrous_Apple

Recommended Posts

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;
		}
	}
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
		}
	}
}

Link to comment
Share on other sites

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.

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.



×
×
  • Create New...

Important Information

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