Jump to content

Recommended Posts

Posted

Hi, I'm a begginer and I tried to create a new Ore for my mod.

So it's a Cobalt Ore which drop cobalt when you break it with a diamond pickaxe, till then it works.

But I've a searched a method to make the enchantment fortune (enchanted pickaxe) make it drop more than one cobalt.

 

I found a example but, I think I did something wrong, or my method is outdated.

Here's my block class :

 

package wwrp.Blocks;

import java.util.Random;
import cpw.mods.fml.common.registry.GameRegistry;
import wwrp.Common.Modwwrp;
import net.minecraft.block.material.Material;
import net.minecraft.block.Block;
import net.minecraft.item.Item;

public class BlockwwrpcobaltOre extends Block
{
        public BlockwwrpcobaltOre()
        {
        	super(Material.rock);
        	setHarvestLevel("pickaxe",3); // 3= DIAMOND PICKAXE
        	this.setHardness(4.5F);
        	this.setStepSound(Block.soundTypeStone);	
        }

        public int quantityDropped(int meta, int fortune, Random random)
        {
            return quantityDroppedWithBonus(fortune, random);
        }

        @Override
        public Item getItemDropped(int metadata, Random random, int fortune) 
        {
            return wwrp.Common.Modwwrp.cobalt;
        }

}

 

In my principal class :

cobaltOre = new BlockwwrpcobaltOre().setBlockName("cobaltOre").setCreativeTab(wwrpTab).setBlockTextureName(modid + ":" + "oreCobalt");
GameRegistry.registerBlock(cobaltOre, "cobaltOre");

 

Can you help me again ? :(

Thank you in advance !

 

Posted

This could work for example. So this makes sure it always drops one item. Then it add a random int (fortune + 2). If you want less, remove the "2 + ".

public int quantityDropped(int meta, int fortune, Random random)

{

    return 1 + random.nextInt(2 + fortune);

}

Posted

Here it drops always one or more items even if the pickaxe isn't enchanted.

I just want to make my ore influenced by the Fortune enchantment of a pickaxe, like diamond or coal :

 

If you break a coal ore with a simple pickaxe, it'll drop only one coal.

If you break a coal ore with a pickaxe which is enchanted with Fortune (I, II, III), you have a chance to drop more that one coal (the quantity depends

on the fortune level).

 

I simply want to do the same effect for my ore. :)

Posted

My bad, looked into it and made it work, here you go:

 

    public Item getItemDropped(int damage, Random random, int fortune)
    {
        return myItem;
    }

    public int quantityDropped(Random random)
    {
        return 1;
    }

    public int quantityDroppedWithBonus(int fortune, Random random)
    {
        if (fortune > 0)
        {
            int j = random.nextInt(fortune + 2) - 1;

            if (j < 0)
            {
                j = 0;
            }

            return quantityDropped(random) * (j + 1);
        }
        else
        {
            return quantityDropped(random);
        }
    }

  • 1 month later...
Posted

I like it too. Since my ore normally drops just 1 gem, I boiled it down further. I don't even need quantityDropped().

public class classRubyOre extends BlockOre {
public int quantityDroppedWithBonus(int fortune, Random rnd) {
// int n = this.quantityDropped(rnd);	// Use when an ore normally drops random multiples (see Lapis in vanilla BlockOre class)
if (fortune > 0) { // There's fortune, but will it grant a bonus?
	// Here is my fortune formula. It can be tuned to suit game balance.
	// If emulating in another ore, tweak this expression to suit.
	int j = rnd.nextInt(fortune + 2) - 1; // linear, even dist from -1 to 3, 4, or 5 inclusive
	if (j > 0) {	          // Yes, there's a bonus! Add the usual 1 and return
		return j++; // was: n * (j++)
	}
	}              // No bonus; return the usual 1
	return 1; 	// was: n
}
}

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.