Jump to content

Making block harvest-able only with enchantment


Briggybros

Recommended Posts

Hello, I have a block which I want to only be able to harvest when I have a specified enchantment on my pickaxe.

I have this code in the block class:

	@Override
    public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6)
    {
        if (EnchantmentHelper.getEnchantmentLevel(XXXX.xxxx.effectId, par2EntityPlayer.getHeldItem()) > 0);
        {
        	ItemStack is = new ItemStack(XXXX.yyyy);
        	par1World.spawnEntityInWorld(new EntityItem(par1World, par3, par4, par5, is));
        }
    }

 

and this to define what can harvest it:

MinecraftForge.setBlockHarvestLevel(zzzz, "pickaxe", 0);

 

my enchantment code looks like so:

package mods.XXXX;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnumEnchantmentType;
import net.minecraft.util.StatCollector;

public class EnchantmentXxxx extends Enchantment {

public EnchantmentXxxx(int par1, int par2) {
	super(par1, par2, EnumEnchantmentType.digger);
}

public int getMaxLevel() {
	return 1;
}

public String getTranslatedName(int par1) {
	String enchantmentName = "Xxxx";
	return enchantmentName + " " + StatCollector.translateToLocal("enchantment.level." + par1);
}

    public int getMinEnchantability(int par1)
    {
        return 22;
    }
    
    public int getMaxEnchantability(int par1)
    {
        return 22;
    }
}

 

However, when I mine my block with any pickaxe, it drops the itemstack specified in the harvestBlock method regradless of whether the pickaxe has the enchantment or not.

Link to comment
Share on other sites

@Override
public int quantityDropped(int meta, int fortune, Random random)
{
        return 0;
}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

All I can say at this point is:

 

Add debug statements, figure out where the program is going that it shouldn't be and why.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.