fixed tool NBT crashing when returning null nbt

This commit is contained in:
Mohammad-Ali Minaie
2017-03-25 22:56:41 -04:00
parent aba73035b5
commit ca3379f073
7 changed files with 223 additions and 176 deletions

View File

@@ -9,9 +9,13 @@ import net.minecraft.nbt.NBTTagCompound;
public interface ToolNBT {
default boolean getHot(ItemStack stack){
if(stack.hasTagCompound()){
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getBoolean("hot");
}
}
}
return false;
}
default void setHot(ItemStack stack, Boolean bool){
@@ -19,9 +23,13 @@ public interface ToolNBT {
}
default int getModifiers(ItemStack stack) {
if(stack.hasTagCompound()) {
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("modifiers");
}
}
}
return 0;
}
default void setModifiers(ItemStack stack, Integer mods){
@@ -29,15 +37,29 @@ public interface ToolNBT {
}
default boolean getEmerald(ItemStack stack){
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getBoolean("emerald");
}
}
}
return false;
}
default void setEmerald(ItemStack stack, Boolean bool){
stack.getSubCompound("tags").setBoolean("emerald", bool);
}
default int getDiamondLevel(ItemStack stack) {
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("diamond");
}
}
}
return 0;
}
default void setDiamondLevel(ItemStack stack, Integer level){
stack.getSubCompound("tags").setInteger("diamond", level);
@@ -45,21 +67,42 @@ public interface ToolNBT {
default int getRedstoneLevel(ItemStack stack) {
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("redstone");
}
}
}
return 0;
}
default void setRedstoneLevel(ItemStack stack, Integer level){
stack.getSubCompound("tags").setInteger("redstone", level);
}
default int getLapisLevel(ItemStack stack) {
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags").getInteger("lapis");
}
}
}
return 0;
}
default void setLapisLevel(ItemStack stack, Integer level){
stack.getSubCompound("tags").setInteger("lapis", level);
}
default NBTTagCompound getTags(ItemStack stack){
if(!stack.isEmpty()) {
if (stack.hasTagCompound()) {
if (stack.getSubCompound("tags") != null) {
return stack.getSubCompound("tags");
}
}
}
return null;
}
}

View File

@@ -312,7 +312,7 @@ public class ItemStoneTongs extends Item {
//System.out.println(itemstack.getTagCompound().getInteger("type"));
}
//System.out.println(player.getHeldItem(hand).getTagCompound().getInteger("type"));
return EnumActionResult.SUCCESS;
return EnumActionResult.FAIL;
}

View File

@@ -48,37 +48,39 @@ public class CustomAxe extends ItemAxe implements ToolNBT {
public float apply(ItemStack item, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) {
if (item.hasTagCompound()) {
if (getHot(item) == false) {
if (getHot(item) != true) {
if (getModifiers(item) != 0) {
if ( (getEmerald(item) == true) &&
if ((getEmerald(item) == true) &&
(getDiamondLevel(item) == 0) &&
(getRedstoneLevel(item) == 0) &&
(getLapisLevel(item) == 0)) {
return 0.1F;
}
if ( (getEmerald(item) == true) &&
if ((getEmerald(item) == true) &&
(getDiamondLevel(item) == 1) &&
(getRedstoneLevel(item) == 0) &&
(getLapisLevel(item) == 0)) {
return 0.11F;
}
if ( (getEmerald(item) == true) &&
if ((getEmerald(item) == true) &&
(getDiamondLevel(item) == 2) &&
(getRedstoneLevel(item) == 0) &&
(getLapisLevel(item) == 0)) {
return 0.12F;
}
if ( (getEmerald(item) == true) &&
if ((getEmerald(item) == true) &&
(getDiamondLevel(item) == 1) &&
(getRedstoneLevel(item) == 1) &&
(getLapisLevel(item) == 0)) {
return 0.111F;
}
if ( (getEmerald(item) == true) &&
if ((getEmerald(item) == true) &&
(getDiamondLevel(item) == 0) &&
(getRedstoneLevel(item) == 2) &&
(getLapisLevel(item) == 0)) {
@@ -87,21 +89,21 @@ public class CustomAxe extends ItemAxe implements ToolNBT {
// ============
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 1) &&
(getRedstoneLevel(item) == 0) &&
(getLapisLevel(item) == 0)) {
return 0.01F;
}
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 2) &&
(getRedstoneLevel(item) == 0) &&
(getLapisLevel(item) == 0)) {
return 0.02F;
}
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 3) &&
(getRedstoneLevel(item) == 0) &&
(getLapisLevel(item) == 0)) {
@@ -110,21 +112,21 @@ public class CustomAxe extends ItemAxe implements ToolNBT {
//=======
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 0) &&
(getRedstoneLevel(item) == 1) &&
(getLapisLevel(item) == 0)) {
return 0.001F;
}
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 0) &&
(getRedstoneLevel(item) == 2) &&
(getLapisLevel(item) == 0)) {
return 0.002F;
}
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 0) &&
(getRedstoneLevel(item) == 3) &&
(getLapisLevel(item) == 0)) {
@@ -133,21 +135,21 @@ public class CustomAxe extends ItemAxe implements ToolNBT {
//=========
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 0) &&
(getRedstoneLevel(item) == 0) &&
(getLapisLevel(item) == 1)) {
return 0.0001F;
}
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 0) &&
(getRedstoneLevel(item) == 0) &&
(getLapisLevel(item) == 2)) {
return 0.0002F;
}
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 0) &&
(getRedstoneLevel(item) == 0) &&
(getLapisLevel(item) == 3)) {
@@ -156,45 +158,45 @@ public class CustomAxe extends ItemAxe implements ToolNBT {
//=======
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 1) &&
(getRedstoneLevel(item) == 1) &&
(getLapisLevel(item) == 1)) {
return 0.0111F;
}
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 2) &&
(getRedstoneLevel(item) == 1) &&
(getLapisLevel(item) == 0)) {
return 0.021F;
}
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 1) &&
(getRedstoneLevel(item) == 2) &&
(getLapisLevel(item) == 0)) {
return 0.012F;
}
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 0) &&
(getRedstoneLevel(item) == 1) &&
(getLapisLevel(item) == 2)) {
return 0.0012F;
}
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 0) &&
(getRedstoneLevel(item) == 2) &&
(getLapisLevel(item) == 1)) {
return 0.0021F;
}
if ( (getEmerald(item) == false) &&
if ((getEmerald(item) == false) &&
(getDiamondLevel(item) == 1) &&
(getRedstoneLevel(item) == 0) &&
(getLapisLevel(item) == 2) ) {
(getLapisLevel(item) == 2)) {
return 0.0102F;
}
}
@@ -204,10 +206,11 @@ public class CustomAxe extends ItemAxe implements ToolNBT {
}
if (getHot(item) == false) {
if (item.getSubCompound("tags").getInteger("modifiers") == 0) {
if (getModifiers(item) == 0) {
return 0.0F;
}
}
}
return 0.0F;
}
@@ -268,27 +271,27 @@ public class CustomAxe extends ItemAxe implements ToolNBT {
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack item, EntityPlayer player, List<String> tooltip, boolean advanced)
{
if(player.getEntityWorld().isRemote) {
if(!item.isEmpty()) {
if (player.getEntityWorld().isRemote) {
if(item.hasTagCompound()) {
if (item.hasTagCompound()) {
tooltip.add(ChatFormatting.GRAY + "Upgrades Left: " + (3 - getModifiers(item)) );
if (item.getSubCompound("tags").getBoolean("emerald") == true) {
if (getEmerald(item) == true) {
tooltip.add(ChatFormatting.DARK_GREEN + "Emerald");
}
if (item.getSubCompound("tags").getInteger("diamond") > 0) {
if (getDiamondLevel(item) > 0) {
tooltip.add(ChatFormatting.AQUA + "Diamond Level: " + getDiamondLevel(item));
}
if (item.getSubCompound("tags").getInteger("redstone") > 0) {
if (getRedstoneLevel(item) > 0) {
tooltip.add(ChatFormatting.RED + "Redstone Level: " + getRedstoneLevel(item) );
}
if (item.getSubCompound("tags").getInteger("lapis") > 0) {
if (getLapisLevel(item) > 0) {
tooltip.add(ChatFormatting.BLUE + "Lapis Level: " + getLapisLevel(item) );
}
}
}
}
}
@Override
@@ -296,7 +299,7 @@ public class CustomAxe extends ItemAxe implements ToolNBT {
{
if(!player.world.isRemote){
World world = player.getEntityWorld();
System.out.println(world.getBlockState(pos).getBlock());
//System.out.println(world.getBlockState(pos).getBlock());
if(itemstack.getItem() instanceof CustomPickaxe){
if( getEmerald(itemstack)){
itemstack.addEnchantment(Enchantment.getEnchantmentByID(33), 1);

View File

@@ -204,7 +204,7 @@ public class CustomHoe extends ItemHoe implements ToolNBT {
}
if (getHot(item) == false) {
if (item.getSubCompound("tags").getInteger("modifiers") == 0) {
if (getModifiers(item) == 0) {
return 0.0F;
}
}
@@ -273,16 +273,16 @@ public class CustomHoe extends ItemHoe implements ToolNBT {
if(item.hasTagCompound()) {
tooltip.add(ChatFormatting.GRAY + "Upgrades Left: " + (3 - getModifiers(item)) );
if (item.getSubCompound("tags").getBoolean("emerald") == true) {
if (getEmerald(item) == true) {
tooltip.add(ChatFormatting.DARK_GREEN + "Emerald");
}
if (item.getSubCompound("tags").getInteger("diamond") > 0) {
if (getDiamondLevel(item) > 0) {
tooltip.add(ChatFormatting.AQUA + "Diamond Level: " + getDiamondLevel(item));
}
if (item.getSubCompound("tags").getInteger("redstone") > 0) {
if (getRedstoneLevel(item) > 0) {
tooltip.add(ChatFormatting.RED + "Redstone Level: " + getRedstoneLevel(item) );
}
if (item.getSubCompound("tags").getInteger("lapis") > 0) {
if (getLapisLevel(item) > 0) {
tooltip.add(ChatFormatting.BLUE + "Lapis Level: " + getLapisLevel(item) );
}
}

View File

@@ -211,7 +211,7 @@ public class CustomPickaxe extends ItemPickaxe implements ToolNBT{
}
if (getHot(item) == false) {
if (item.getSubCompound("tags").getInteger("modifiers") == 0) {
if (getModifiers(item) == 0) {
return 0.0F;
}
}
@@ -280,16 +280,16 @@ public class CustomPickaxe extends ItemPickaxe implements ToolNBT{
if(item.hasTagCompound()) {
tooltip.add(ChatFormatting.GRAY + "Upgrades Left: " + (3 - getModifiers(item)) );
if (item.getSubCompound("tags").getBoolean("emerald") == true) {
if (getEmerald(item) == true) {
tooltip.add(ChatFormatting.DARK_GREEN + "Emerald");
}
if (item.getSubCompound("tags").getInteger("diamond") > 0) {
if (getDiamondLevel(item) > 0) {
tooltip.add(ChatFormatting.AQUA + "Diamond Level: " + getDiamondLevel(item));
}
if (item.getSubCompound("tags").getInteger("redstone") > 0) {
if (getRedstoneLevel(item) > 0) {
tooltip.add(ChatFormatting.RED + "Redstone Level: " + getRedstoneLevel(item) );
}
if (item.getSubCompound("tags").getInteger("lapis") > 0) {
if (getLapisLevel(item) > 0) {
tooltip.add(ChatFormatting.BLUE + "Lapis Level: " + getLapisLevel(item) );
}
}

View File

@@ -204,7 +204,7 @@ public class CustomShovel extends ItemSpade implements ToolNBT {
}
if (getHot(item) == false) {
if (item.getSubCompound("tags").getInteger("modifiers") == 0) {
if (getModifiers(item) == 0) {
return 0.0F;
}
}
@@ -273,16 +273,16 @@ public class CustomShovel extends ItemSpade implements ToolNBT {
if(item.hasTagCompound()) {
tooltip.add(ChatFormatting.GRAY + "Upgrades Left: " + (3 - getModifiers(item)) );
if (item.getSubCompound("tags").getBoolean("emerald") == true) {
if (getEmerald(item) == true) {
tooltip.add(ChatFormatting.DARK_GREEN + "Emerald");
}
if (item.getSubCompound("tags").getInteger("diamond") > 0) {
if (getDiamondLevel(item) > 0) {
tooltip.add(ChatFormatting.AQUA + "Diamond Level: " + getDiamondLevel(item));
}
if (item.getSubCompound("tags").getInteger("redstone") > 0) {
if (getRedstoneLevel(item) > 0) {
tooltip.add(ChatFormatting.RED + "Redstone Level: " + getRedstoneLevel(item) );
}
if (item.getSubCompound("tags").getInteger("lapis") > 0) {
if (getLapisLevel(item) > 0) {
tooltip.add(ChatFormatting.BLUE + "Lapis Level: " + getLapisLevel(item) );
}
}

View File

@@ -3,6 +3,7 @@ itemGroup.forgecraft=ForgeCraft
tile.firebox.name=Forge
tile.bloomery.name=Bloomery
tile.stoneanvil.name=Stone Anvil
tile.pistonbellows.name=Wooden Piston Bellows
tile.emptycrucible.name=Empty Crucible
tile.emptycruciblehit.name=Hot Empty Crucible