This is so weird; one day my item displayed the durability on the tooltip for it and, the next day it doesn't. I have no clue what could make it not display it but maybe you guy's could find something? Here are my classes:
Main Item Class NOTE: I already tried not setting a NBTTagCompound, removing addInformation and, made sure it is registered as an Item:
package com.happykiller.crewmod.items.tools;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import com.happykiller.crewmod.CrewMod;
import com.happykiller.crewmod.client.gui.GuiId;
import com.happykiller.crewmod.lib.LogHelper;
import com.happykiller.crewmod.lib.MR;
import com.happykiller.crewmod.server.EntityHelper;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
public class CrewHammer extends ItemPickaxe {
public CrewHammer(ToolMaterial tm) {
super(tm);
this.setCreativeTab(CrewMod.tabCrewTools);
this.setUnlocalizedName("CrewHammer");
this.setTextureName(MR.TNAME + "CrewHammer");
this.setFull3D();
this.setMaxStackSize(1);
}
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
System.out.println("CALLED");
//if(!world.isRemote) {
LogHelper.logInfo("THE STACK: " + stack);
//NBTTagCompound cmp = stack.getTagCompound();
LogHelper.logInfo("TAG: " + stack.getTagCompound());
fixNBT(stack);
/*if(cmp == null) {
LogHelper.logWarn("No tag was set, creating a new one...");
cmp = new NBTTagCompound();
cmp.setString("MiningSize", "3x3");
stack.setTagCompound(cmp);
}*/
//LogHelper.logInfo(cmp.toString());
LogHelper.logInfo("Stack Compound Tag: " + stack.getTagCompound());
LogHelper.logInfo("Stack Tag (HammerTag): " + stack.getTagCompound().getTag("HammerTag"));
//}
}
/*public void onCreated(ItemStack stack, World world, EntityPlayer player) {
if(world.isRemote)
return;
NBTTagCompound cmp = stack.stackTagCompound;
if(cmp == null) {
System.out.println("NBT TAG SET");
cmp = new NBTTagCompound();
stack.stackTagCompound = cmp;
}
this.fixNBT(stack);
System.out.println(stack.stackTagCompound);
cmp.setString("MiningSize", "3x3");
}*/
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean flag) {
list.add(EnumChatFormatting.RED + "Use SHIFT + Right-Click to");
list.add(EnumChatFormatting.RED + "open the modification menu.");
list.add("");
list.add(EnumChatFormatting.GREEN + "Hit Left-ALT to open the");
list.add(EnumChatFormatting.GREEN + "quick change menu.");
}
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if(player.isSneaking()) {
FMLNetworkHandler.openGui(player, CrewMod.instance, GuiId.guiCrewHammerID, world, (int)player.posX, (int)player.posY, (int)player.posZ);
}
return stack;
}
public static void fixNBT(ItemStack stack){
if(stack.stackTagCompound == null) {
LogHelper.logWarn("[CrewHammer] " + "The ItemStack NBTTagCompound was null. Attempting fix...");
stack.stackTagCompound = new NBTTagCompound();
}
if(!stack.stackTagCompound.hasKey("HammerTag")) {
stack.stackTagCompound.setTag("HammerTag", new NBTTagCompound());
LogHelper.logWarn("[CrewHammer] " + "The ItemStack did not contain the key 'HammerTag'. Attempting fix...");
}
if(!stack.stackTagCompound.hasKey("MiningSize")) {
LogHelper.logWarn("[CrewHammer] " + "The ItemStack did not contain the key 'MiningSize'. Attempting fix...");
stack.stackTagCompound.setString("MiningSize", "3x3");
}
}
/*public static void fixNBT(ItemStack stack){
NBTTagCompound cmp = stack.stackTagCompound;
if(cmp == null) {
System.out.println("CMP WAS NULL, FIXING...");
stack.stackTagCompound = new NBTTagCompound();
cmp = stack.stackTagCompound;
}
if(!cmp.hasKey("MiningSize")){
System.out.println("MiningSize WAS NULL, FIXING...");
cmp.setString("MiningSize", "1x1");
}
stack.stackTagCompound = cmp;
}*/
/*public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entity) {
EntityPlayer player = (EntityPlayer)entity;
LogHelper.logInfo("CALLED");
LogHelper.logInfo("STACK: " + stack);
LogHelper.logInfo("TAG: " + stack.getTagCompound());
if(world != null && player != null) {
LogHelper.logInfo("WORLD WAS NOT NULL NOR WAS PLAYER");
MovingObjectPosition mop = player.rayTrace(5.0D, 1.0F);
int sideHit = -1;
if(!world.isRemote)
sideHit = mop.sideHit;
if(player.inventory.getCurrentItem() != null) {
if(player.inventory.getCurrentItem().getItem().equals(CrewMod.crewHammer)) {
int direction = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
//ItemStack hammer = stack;
//System.out.println("ITEM IN HAND IS CREW HAMMER");
//Block block = event.block;
//World world = event.world;
//int x = event.x;
//int y = event.y;
//int z = event.z;
//CrewHammer.fixNBT(hammer);
//NBTTagCompound cmp = hammer.stackTagCompound;
//if(event.isCanceled())
//return;
String miningArea = null;
if(stack.hasTagCompound()) {
miningArea = stack.getTagCompound().getString("MiningSize");
//System.out.println("CMP WAS NOT NULL");
}
LogHelper.logInfo(miningArea);
this.breakBlock(world, player, stack, x, y, z, direction, miningArea, sideHit);
}else {
super.onBlockDestroyed(stack, world, block, x, y, z, entity);
}
}else {
super.onBlockDestroyed(stack, world, block, x, y, z, entity);
}
}
return true;
}
/**
* Used for breaking an area of blocks depending on the miningSize.
*
* @param world Instance of the Minecraft world.
* @param player Player breaking the block.
* @param stack Stack in the player's hand.
* @param x X coordinate of the block to be broken.
* @param y Y coordinate of the block to be broken.
* @param z Z coordinate of the block to be broken.
* @param playerFacing The direction the player is facing: NORTH, SOUTH, EAST or, WEST.
* @param miningArea The area of blocks to be destroyed: 1x1 = 0, 3x3 = 1, 5x5 = 2, 7x7 = 3.
*/
public void breakBlock(World world, EntityPlayer player, ItemStack stack, int x, int y, int z, int playerFacing, String miningArea, int sideHit) { //TODO Fix RayTrace!
System.out.println("BREAK BLOCK RUN");
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
/*MovingObjectPosition mop = player.rayTrace(5.0D, 1.0F);
if(mop == null) {
LogHelper.logErr("[CrewHammer] " + "Ray Trace has failed!");
return;
}*/
//int sideHit = -1;
//if(world.isRemote)
// sideHit = mop.sideHit;
//else
// return;
LogHelper.logInfo("[CrewHammer] Side Hit: " + sideHit);
int refX = x;
int refY = y;
int refZ = z;
if(!isEffective(block, meta, stack))
return;
int miningSize = 0;
if(miningArea != null) {
if(miningArea.equals("3x3"))
miningSize = 1;
else if(miningArea == "5x5")
miningSize = 2;
else if(miningArea == "7x7")
miningSize = 3;
else
miningSize = 0;
}else {
LogHelper.logErr("[CrewHammer] The Mining Area was null!");
}
System.out.println(miningArea);
System.out.println(miningSize);
if(playerFacing == 0 || playerFacing == 2) {
//System.out.println("PLAYER FACING 0 or 2");
if(miningSize == 0) {
return;
}else if(miningSize == 1) {
System.out.println("MINING IS 3x3");
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
}else if(miningSize == 2) {
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
}else {
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 3, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 3, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 3, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 3, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 3, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 3, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 3, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 3, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 3, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 3, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 3, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 3, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 2, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 2, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x - 3, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x + 3, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
}
}else {
//System.out.println("PLAYER FACING 1 or 3");
if(miningSize == 0) {
return;
}else if(miningSize == 1) {
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z - 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z + 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
}else if(miningSize == 2) {
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z - 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z + 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z - 2, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z + 2, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z - 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z + 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z - 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z + 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
}else {
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 3, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 3, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 3, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 3, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z - 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z + 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z - 2, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z + 2, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z - 3, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y, z + 3, true, refX, refY, refZ, sideHit, 0, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z - 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z + 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z - 3, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z + 3, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z - 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z + 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z - 3, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z + 3, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z - 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z + 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z - 3, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z + 3, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z - 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z + 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z - 3, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z + 3, true, refX, refY, refZ, sideHit, 2, playerFacing);
this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
}
}
}
/**
* Destroys a block at the given coords if allowed.
*
* @param world The instance of the World.
* @param player The player destroying said block.
* @param x X Coordinate of the block to be destroyed.
* @param y Y Coordinate of the block to be destroyed.
* @param z Z Coordinate of the block to be destroyed.
* @param addDrops If true, adds drops to the block broken.
* @param refX Reference point X of the center block if destroying multiple ones.
* @param refY Reference point Y of the center block if destroying multiple ones.
* @param refZ Reference point Z of the center block if destroying multiple ones.
* @param Ymodifer Used to determine if the Y variable is added to or, subtracted from. 0 = Nothing, 1 = Added to, 2 = Subtracted from.
* @param playerDirection The direction the player is facing: NORTH, SOUTH, EAST or, WEST.
*/
public void destroyBlockIfAllowed(World world, ItemStack stack, EntityPlayer player, int x, int y, int z, boolean addDrops, int refX, int refY, int refZ, int sideHit, int Ymodifer, int playerDirection) {
int actualX = x;
int actualY = y;
int actualZ = z;
if(sideHit == 0 || sideHit == 1) {
//System.out.println("Z updated");
actualY = refY;
int amountToAdd = refY > y ? refY - y : y - refY;
if(playerDirection == 0 || playerDirection == 2) {
if(Ymodifer == 0)
actualZ += 0;
else if(Ymodifer == 1)
actualZ += amountToAdd;
else
actualZ -= amountToAdd;
}else {
if(Ymodifer == 0)
actualX += 0;
else if(Ymodifer == 1)
actualX += amountToAdd;
else
actualX -= amountToAdd;
}
/*System.out.println("Z: " + actualZ);
System.out.println(additionZ);
System.out.println("Y: " + y);
System.out.println("refY: " + refY);*/
}
if(world.isAirBlock(actualX, actualY, actualZ))
return;
Block block = world.getBlock(actualX, actualY, actualZ);
int meta = world.getBlockMetadata(actualX, actualY, actualZ);
if(!isEffective(block, meta, stack))
return;
Block refBlock = world.getBlock(refX, refY, refZ);
// float refStrength = ForgeHooks.blockStrength(refBlock, player, world, refX, refY, refZ);
// float strength = ForgeHooks.blockStrength(block, player, world, actualX, actualY , actualZ);
float refStrength = refBlock.getBlockHardness(world, refX, refY, refZ);
float strength = block.getBlockHardness(world, actualX, actualY, actualZ);
//System.out.println("REFSTRENGTH: " + refStrength);
//System.out.println("STRENGTH: " + strength);
float strDifference = strength/refStrength;
System.out.println(strDifference);
if(!ForgeHooks.canHarvestBlock(block, player, meta) || strength <= -1 || strDifference > 10)
return;
if(block.getExpDrop(world, meta, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack)) > 0)
block.dropXpOnBlockBreak(world, actualX, actualY, actualZ, block.getExpDrop(world, meta, 0));
world.func_147480_a(actualX, actualY, actualZ, addDrops);
int damage = stack.getItemDamage() + 1;
if(!player.capabilities.isCreativeMode)
stack.setItemDamage(damage);
}
public boolean isEffective(Block block, int meta, ItemStack stack) {
if(ForgeHooks.canToolHarvestBlock(block, meta, stack))
return true;
return false;
}
/*//Makes it so the item stays in the crafting grid
public boolean doesContainerItemLeaveCraftingGrid(ItemStack stack) {
return false;
}
//Tells the game your item has a container item
public boolean hasContainerItem() {
return true;
}
//Sets teh container item
public ItemStack getContainerItem(ItemStack itemStack) {
itemStack.attemptDamageItem(1, itemRand);
return itemStack;
}*/
}
Main Class where I register it:
package com.happykiller.crewmod;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.EnumHelper;
import com.happykiller.crewmod.blocks.LavaBlock;
import com.happykiller.crewmod.blocks.ShopBlock;
import com.happykiller.crewmod.blocks.WubWubBlock;
import com.happykiller.crewmod.blocks.crops.BlockCorn;
import com.happykiller.crewmod.blocks.crops.CornCropStart;
import com.happykiller.crewmod.events.EventsFML;
import com.happykiller.crewmod.events.EventsForge;
import com.happykiller.crewmod.food.IceCream;
import com.happykiller.crewmod.items.CrewCoin;
import com.happykiller.crewmod.items.CrewGem;
import com.happykiller.crewmod.items.ItemLavaBlock;
import com.happykiller.crewmod.items.ShopItem;
import com.happykiller.crewmod.items.VillagerHeart;
import com.happykiller.crewmod.items.tools.CrewHammer;
import com.happykiller.crewmod.items.tools.LightningRod;
import com.happykiller.crewmod.items.tools.TrapPickaxe;
import com.happykiller.crewmod.lib.LogHelper;
import com.happykiller.crewmod.lib.MR;
import com.happykiller.crewmod.packets.PacketRegistry;
import com.happykiller.crewmod.proxy.CommonProxy;
import com.happykiller.crewmod.register.RegisterCrafting;
import com.happykiller.crewmod.register.RegisterSmelting;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = MR.MODID, name = MR.NAME, version = MR.VERSION)
public class CrewMod {
@Instance(MR.MODID)
public static CrewMod instance;
@SidedProxy(clientSide = "com.happykiller.crewmod.proxy.ClientProxy", serverSide = "com.happykiller.crewmod.proxy.CommonProxy")
public static CommonProxy proxy;
public static Item crewGem;
public static Item iceCream;
public static Item crewCoin;
public static Item shopItem;
public static Item villagerHeart;
public static Block wubWubBlock;
public static Block shopBlock;
public static Block emeraldLavaBlock;
public static Block diamondLavaBlock;
public static Block goldLavaBlock;
public static Block ironLavaBlock;
public static CornCropStart cornCropStart;
public static BlockCorn cornBlock;
public static Item seedsCorn;
public static Item cobCorn;
public static Item cookedCorn;
public static Item trapPickaxe;
public static Item lightningRod;
/* Crew Tools */
public static Item crewHammer;
/* Tool Materials */
public static final ToolMaterial trapBreaker = EnumHelper.addToolMaterial("trapBreaker", 2, 20, 6.0F, 2.0F, 0);
public static final ToolMaterial crewTools = EnumHelper.addToolMaterial("crewTools", 4, 3500, 12.0F, 6.0F, ;
@EventHandler
public void preInit(FMLPreInitializationEvent event) { //FINISH SHOP GUI'S
PacketRegistry.registerNetwork();
PacketRegistry.registerAllPackets();
/* Items */
crewGem = new CrewGem();
crewCoin = new CrewCoin();
shopItem = new ShopItem();
villagerHeart = new VillagerHeart();
iceCream = new IceCream(8, 0.6F, false);
cobCorn = new ItemFood(2, 0.2F, false).setUnlocalizedName("CornCob").setTextureName(MR.TNAME + "cobCorn").setCreativeTab(tabCrewFood);
cookedCorn = new ItemFood(6, 0.4F, false).setUnlocalizedName("CookedCorn").setTextureName(MR.TNAME + "cookedCorn").setCreativeTab(tabCrewFood);
/* Item Registry */
GameRegistry.registerItem(crewGem, "CrewGem");
GameRegistry.registerItem(iceCream, "IceCream");
GameRegistry.registerItem(crewCoin, "CrewCoin");
GameRegistry.registerItem(shopItem, "ShopItem");
GameRegistry.registerItem(villagerHeart, "VillagerHeart");
GameRegistry.registerItem(cobCorn, "CornCob");
GameRegistry.registerItem(cookedCorn, "CookedCorn");
/* Blocks */
wubWubBlock = new WubWubBlock(Material.rock);
shopBlock = new ShopBlock(Material.rock);
emeraldLavaBlock = new LavaBlock(Material.rock).setBlockName("EmeraldLB").setBlockTextureName("emerald_ore");
diamondLavaBlock = new LavaBlock(Material.rock).setBlockName("DiamondLB").setBlockTextureName("diamond_ore");
goldLavaBlock = new LavaBlock(Material.rock).setBlockName("GoldLB").setBlockTextureName("gold_ore");
ironLavaBlock = new LavaBlock(Material.rock).setBlockName("IronLB").setBlockTextureName("iron_ore");
/* Block Registry */
GameRegistry.registerBlock(wubWubBlock, "WubWubBlock");
GameRegistry.registerBlock(shopBlock, "ShopBlock");
GameRegistry.registerBlock(emeraldLavaBlock, ItemLavaBlock.class, "EmeraldLB");
GameRegistry.registerBlock(diamondLavaBlock, ItemLavaBlock.class, "DiamondLB");
GameRegistry.registerBlock(goldLavaBlock, ItemLavaBlock.class, "GoldLB");
GameRegistry.registerBlock(ironLavaBlock, ItemLavaBlock.class, "IronLB");
/* Crop Blocks */
cornCropStart = new CornCropStart();
cornBlock = new BlockCorn();
/* Crop Block Registry */
GameRegistry.registerBlock(cornCropStart, "CornCrop");
GameRegistry.registerBlock(cornBlock, "CornBlock");
/* Crop Items */
seedsCorn = new ItemSeeds(cornCropStart, Blocks.farmland).setUnlocalizedName("CornSeeds").setTextureName(MR.TNAME + "CornSeeds").setCreativeTab(tabCrewFood);
/* Crop Item Registry */
GameRegistry.registerItem(seedsCorn, "CornSeeds");
/* Tools */
trapPickaxe = new TrapPickaxe(trapBreaker);
lightningRod = new LightningRod();
crewHammer = new CrewHammer(crewTools);
/* Tool Registry */
GameRegistry.registerItem(trapPickaxe, "TrapPickaxe");
GameRegistry.registerItem(lightningRod, "LightningRod");
GameRegistry.registerItem(crewHammer, "CrewHammer");
/* Tile Entity Registry */
//GameRegistry.registerTileEntity(TileEntityShopBlock.class, "tileEntityShopBlock");
LogHelper.logInfo("Pre-Init succesfully loaded!");
}
@EventHandler
public void init(FMLInitializationEvent event) {
RegisterCrafting.addAllRecipes();
RegisterSmelting.addAllSmelting();
MinecraftForge.EVENT_BUS.register(new EventsForge());
FMLCommonHandler.instance().bus().register(new EventsFML());
proxy.initialize();
LogHelper.logInfo("Init succesfully loaded!");
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
LogHelper.logInfo("Post-Init succesfully loaded!");
}
/* Creative Tabs */
public static CreativeTabs tabCrewBlocks = new CreativeTabs("tabCrewBlocks") {
@Override
public Item getTabIconItem() {
return new ItemStack(wubWubBlock).getItem();
};
};
public static CreativeTabs tabCrewMaterials = new CreativeTabs("tabCrewMaterials") {
@Override
public Item getTabIconItem() {
return new ItemStack(crewGem).getItem();
};
};
public static CreativeTabs tabCrewFood = new CreativeTabs("tabCrewFood") {
@Override
public Item getTabIconItem() {
return new ItemStack(iceCream).getItem();
};
};
public static CreativeTabs tabCrewTools = new CreativeTabs("tabCrewTools") {
@Override
public Item getTabIconItem() {
return new ItemStack(trapPickaxe).getItem();
};
};
}