Jump to content

Furnace Recipes [double input] not working


OwnAgePau

Recommended Posts

Hi there,

 

I am making a double input furnace that has 2 inputs and 1 fuel that lead to 1 output, i have figured out quite some of this by now but i seem to get just this nullpointer exception that i can't figure out. I will place the code of the TileEntityGemcutter, GemcutterRecipes, ContainerGemcutter and the code of the block itself as last.

 

The error i get is a null-pointer exception, normally i can figure out most of them but on this one i haven't gotten to a solution yet:

 

 

---- Minecraft Crash Report ----
// I just don't know what went wrong 

Time: 21-7-13 14:17
Description: Ticking tile entity

java.lang.NullPointerException
at Mod_Ores.Blocks.Gemcutter.TileEntityGemcutter.canCut(TileEntityGemcutter.java:260)
at Mod_Ores.Blocks.Gemcutter.TileEntityGemcutter.updateEntity(TileEntityGemcutter.java:195)
at net.minecraft.world.World.updateEntities(World.java:2197)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:546)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:652)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:571)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:127)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:469)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at Mod_Ores.Blocks.Gemcutter.TileEntityGemcutter.canCut(TileEntityGemcutter.java:260)
at Mod_Ores.Blocks.Gemcutter.TileEntityGemcutter.updateEntity(TileEntityGemcutter.java:195)

-- Tile entity being ticked --
Details:
Name: Gemcutter // Mod_Ores.Blocks.Gemcutter.TileEntityGemcutter
Block type: ID #3461 (tile.gemcutterBench // Mod_Ores.Blocks.Gemcutter.BlockGemcutterBench)
Block data value: 4 / 0x4 / 0b0100
Block location: World: (238,69,214), Chunk: (at 14,4,6 in 14,13; contains blocks 224,0,208 to 239,255,223), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
Actual block type: ID #3461 (tile.gemcutterBench // Mod_Ores.Blocks.Gemcutter.BlockGemcutterBench)
Actual block data value: 4 / 0x4 / 0b0100
Stacktrace:
at net.minecraft.world.World.updateEntities(World.java:2197)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:546)

-- Affected level --
Details:
Level name: Gems
All players: 0 total; []
Chunk stats: ServerChunkCache: 625 Drop: 0
Level seed: -44315800909560583
Level generator: ID 00 - default, ver 1. Features enabled: true
Level generator options: 
Level spawn location: World: (240,64,220), Chunk: (at 0,4,12 in 15,13; contains blocks 240,0,208 to 255,255,223), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
Level time: 806 game time, 806 day time
Level dimension: 0
Level storage version: 0x04ABD - Anvil
Level weather: Rain time: 139697 (now: false), thunder time: 129307 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:652)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:571)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:127)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:469)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)

-- System Details --
Details:
Minecraft Version: 1.5.2
Operating System: Windows 7 (x86) version 6.1
Java Version: 1.7.0_17, Oracle Corporation
Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation
Memory: 944902608 bytes (901 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 3000 (168000 bytes; 0 MB) allocated, 3000 (168000 bytes; 0 MB) used
Suspicious classes: FML and Forge are installed
IntCache: cache: 0, tcache: 0, allocated: 1, tallocated: 63
FML: MCP v7.51 FML v5.2.5.686 Minecraft Forge 7.8.0.686 4 mods loaded, 4 mods active
mcp{7.44} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{5.2.5.686} [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{7.8.0.686} [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
myOresMod{1.8} [soul Forest Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 915 (51240 bytes; 0 MB) allocated, 915 (51240 bytes; 0 MB) used
Player Count: 0 / 8; []
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

 

 

First i will give the file where the error occurs which is the TileEntityGemcutter :

 

 

package Mod_Ores.Blocks.Gemcutter;

import Mod_Ores.mod_Ores;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ForgeDummyContainer;

public class TileEntityGemcutter extends TileEntity implements net.minecraftforge.common.ISidedInventory
{
    private ItemStack[] gemcutterItemStacks = new ItemStack[4];
    
    public static final int input_slot_1_index = 0;
    public static final int input_slot_2_index = 1;
    public static final int fuel_inventory_index = 2;
    public static final int output_inventory_index = 3;

    public int currentGemItemBurnTime = 0;
    public int gemcutterBurnTime = 0;
    public int gemcutterCookTime = 0;

    @Override
    public String getInvName()
    {
        return "Gemcutter";
    }
    
    @Override
    public boolean isInvNameLocalized()
    {
        return false;
    }
    
    @Override
    public int getInventoryStackLimit()
    {
        return 64;
    }
    
    @Override
    public int getSizeInventory()
    {
        return this.gemcutterItemStacks.length;
    }

    @Override
    public ItemStack getStackInSlot(int slot)
    {
        return this.gemcutterItemStacks[slot];
    }

    @SuppressWarnings("null")
    @Override
    public ItemStack decrStackSize(int slot, int ammount)
    {
    	ItemStack itemstack = getStackInSlot(slot);
    	if(itemstack != null)
    	{
    		setInventorySlotContents(slot, null);	
    	}
    	else
    	{
    		itemstack = itemstack.splitStack(ammount);
    		if(itemstack.stackSize == 0)
    		{
    			setInventorySlotContents(slot, null);
    		}
    	}

        return itemstack;
    }

    @Override
    public ItemStack getStackInSlotOnClosing(int slot)
    {
    	ItemStack itemstack = getStackInSlot(slot);
    	if(itemstack != null)
    	{
    		setInventorySlotContents(slot, null);
    	}
    	
        return itemstack;
    }

    @Override
    public void setInventorySlotContents(int slot, ItemStack itemStack)
    {
        this.gemcutterItemStacks[slot] = itemStack;
        if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit())
        {
        	itemStack.stackSize = this.getInventoryStackLimit();
        }
    }

    @Override
    public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items");
        this.gemcutterItemStacks = new ItemStack[this.getSizeInventory()];

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
            byte slot = nbttagcompound1.getByte("Slot");

            if (slot >= 0 && slot < this.gemcutterItemStacks.length)
            {
                this.gemcutterItemStacks[slot] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
            }
        }

        this.gemcutterBurnTime = par1NBTTagCompound.getShort("BurnTime");
        this.gemcutterCookTime = par1NBTTagCompound.getShort("CookTime");
        this.currentGemItemBurnTime = getItemBurnTime(this.gemcutterItemStacks[1]);
    }

    @Override
    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
        par1NBTTagCompound.setShort("BurnTime", (short)this.gemcutterBurnTime);
        par1NBTTagCompound.setShort("CookTime", (short)this.gemcutterCookTime);
        NBTTagList nbttaglist = new NBTTagList();

        for (int currentindex = 0; currentindex < this.gemcutterItemStacks.length; ++currentindex)
        {
            if (this.gemcutterItemStacks[currentindex] != null)
            {
                NBTTagCompound nbttagcompound = new NBTTagCompound();
                nbttagcompound.setByte("Slot", (byte)currentindex);
                this.gemcutterItemStacks[currentindex].writeToNBT(nbttagcompound);
                nbttaglist.appendTag(nbttagcompound);
            }
        }

        par1NBTTagCompound.setTag("Items", nbttaglist);
    }

    @SideOnly(Side.CLIENT)

    public int getCookProgressScaled(int par1)
    {
        return this.gemcutterCookTime * par1 / 200;
    }

    @SideOnly(Side.CLIENT)

    public int getBurnTimeRemainingScaled(int par1)
    {
        if (this.currentGemItemBurnTime == 0)
        {
            this.currentGemItemBurnTime = 200;
        }

        return this.gemcutterBurnTime * par1 / this.currentGemItemBurnTime;
    }

    public boolean isBurning()
    {
        return this.gemcutterBurnTime > 0;
    }

    @Override
    public void updateEntity()
    {
        boolean flag = this.gemcutterBurnTime > 0;
        boolean flag1 = false;

        if (this.gemcutterBurnTime > 0)
        {
            --this.gemcutterBurnTime;
        }

        if (!this.worldObj.isRemote)
        {
            if (this.gemcutterBurnTime == 0)
            {
            	if(this.canCut())
            	{
                    this.currentGemItemBurnTime = this.gemcutterBurnTime = getItemBurnTime(this.gemcutterItemStacks[2]);
                    
                    if (this.gemcutterBurnTime > 0)
                    {
                        flag1 = true;

                        if (this.gemcutterItemStacks[2] != null)
                        {
                            --this.gemcutterItemStacks[2].stackSize;

                            if (this.gemcutterItemStacks[2].stackSize == 0)
                            {
                                this.gemcutterItemStacks[2] = this.gemcutterItemStacks[2].getItem().getContainerItemStack(gemcutterItemStacks[2]);
                            }
                        }
                    }
            	}              
            }

            if (this.isBurning() && this.canCut())
            {
                ++this.gemcutterCookTime;

                if (this.gemcutterCookTime == 200)
                {
                    this.gemcutterCookTime = 0;
                    this.cutItem();
                    flag1 = true;
                }
            }
            else
            {
                this.gemcutterCookTime = 0;
            }

            if (flag != this.gemcutterBurnTime > 0)
            {
                flag1 = true;                
            }
            
            if(flag1)
            {
            	this.onInventoryChanged();
            	BlockGemcutterBench.updateGemcutterBlockState(this.gemcutterBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
            }
        }
    }

    private boolean canCut()
    {
        if (this.gemcutterItemStacks[0] == null)
        {
            return false;
        }      
        else if (this.gemcutterItemStacks[1] == null)
        {
            return false;
        }
        else
        {
            ItemStack itemstack = GemcutterRecipes.smelting().getGemcutterSmeltingResult(this.gemcutterItemStacks[0], this.gemcutterItemStacks[1]);
            
            if (itemstack == null) return false;
            if(this.gemcutterItemStacks[0].stackSize < GemcutterRecipes.smelting().getSlot1ReduceAmount(this.gemcutterItemStacks[0]).stackSize) return false;
            if(this.gemcutterItemStacks[1].stackSize < GemcutterRecipes.smelting().getSlot2ReduceAmount(this.gemcutterItemStacks[1]).stackSize) return false;
            if (this.gemcutterItemStacks[3] == null) return true;
            if (!this.gemcutterItemStacks[3].isItemEqual(itemstack)) return false;
            int result = gemcutterItemStacks[3].stackSize + itemstack.stackSize;
            return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
        }
    }

    public void cutItem()
    {
        if (this.canCut())
        {
            ItemStack itemstack = GemcutterRecipes.smelting().getGemcutterSmeltingResult(this.gemcutterItemStacks[0], this.gemcutterItemStacks[1]);
            
            if (this.gemcutterItemStacks[3] == null)
            {
                this.gemcutterItemStacks[3] = itemstack.copy();
            }
            else if (this.gemcutterItemStacks[3].isItemEqual(itemstack))
            {
                gemcutterItemStacks[3].stackSize += itemstack.stackSize;
            }

            this.gemcutterItemStacks[0].stackSize -= GemcutterRecipes.smelting().getSlot1ReduceAmount(this.gemcutterItemStacks[0]).stackSize; // ON THIS LINE the error occured
            this.gemcutterItemStacks[1].stackSize -= GemcutterRecipes.smelting().getSlot2ReduceAmount(this.gemcutterItemStacks[1]).stackSize;

            if (this.gemcutterItemStacks[0].stackSize <= 0)
            {
                this.gemcutterItemStacks[0] = null;
            }
            
            if (this.gemcutterItemStacks[1].stackSize <= 0)
            {
                this.gemcutterItemStacks[1] = null;
            }
        }
    }

    public static int getItemBurnTime(ItemStack itemStack)
    {
        if (itemStack == null)
        {
            return 0;
        }
        else
        {
            int i = itemStack.getItem().itemID;
            Item item = itemStack.getItem();

            if (itemStack.getItem() instanceof ItemBlock && Block.blocksList[i] != null)
            {
                Block block = Block.blocksList[i];
            }

            //if (i == mod_Ores.PolisherTowel.itemID) return 800;
            if (i == mod_Ores.Polisher.itemID) return 1600;
            //if (i == mod_Ores.UraniumLiquid.itemID) return 1600;
            //if (i == Item.coal.itemID) return 1600;
            return GameRegistry.getFuelValue(itemStack);
        }
    }

    public static boolean isItemFuel(ItemStack par0ItemStack)
    {
        return getItemBurnTime(par0ItemStack) > 0;
    }


    @Override
    public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
    {
        return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
    }

    public void openChest() {}

    public void closeChest() {}

    public boolean isStackValidForSlot(int i, ItemStack itemStack)
    {
    	if(i == 3)
    	{
    		return false;
    	}
    	else
    	{
    		return true;
    	}
    }


    /***********************************************************************************
     * This function is here for compatibilities sake, Modders should Check for
     * Sided before ContainerWorldly, Vanilla Minecraft does not follow the sided standard
     * that Modding has for a while.
     *
     * In vanilla:
     *
     *   Top: Ores
     *   Sides: Fuel
     *   Bottom: Output
     *
     * Standard Modding:
     *   Top: Ores
     *   Sides: Output
     *   Bottom: Fuel
     *
     * The Modding one is designed after the GUI, the vanilla one is designed because its
     * intended use is for the hopper, which logically would take things in from the top.
     *
     * This will possibly be removed in future updates, and make vanilla the definitive
     * standard.
     */

    @Override
    public int getStartInventorySide(ForgeDirection side)
    {
        if (ForgeDummyContainer.legacyFurnaceSides)
        {
            if (side == ForgeDirection.DOWN) return 1;
            if (side == ForgeDirection.UP) return 0;
            return 2;
        }
        else
        {
            if (side == ForgeDirection.DOWN) return 2;
            if (side == ForgeDirection.UP) return 0;
            return 1;
        }
    }

    @Override
    public int getSizeInventorySide(ForgeDirection side)
    {
        return 1;
    }
}

 

 

 

The GemcutterRecipes :

 

 

package Mod_Ores.Blocks.Gemcutter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import Mod_Ores.mod_Ores;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class GemcutterRecipes
{
    private static final GemcutterRecipes gemcutterBase = new GemcutterRecipes();

    /** The list of smelting results. */
    private Map gemcutterList = new HashMap();
    private Map experienceList = new HashMap();
    private HashMap<List<Integer>, ItemStack> gemcutterSmeltingList1 = new HashMap<List<Integer>, ItemStack>();
    private HashMap<List<Integer>, ItemStack> gemcutterSmeltingList2 = new HashMap<List<Integer>, ItemStack>();
    private HashMap<List<Integer>, ItemStack> gemcutterSmeltingCheckList1 = new HashMap<List<Integer>, ItemStack>();
    private HashMap<List<Integer>, ItemStack> gemcutterSmeltingCheckList2 = new HashMap<List<Integer>, ItemStack>();
    private HashMap<List<Integer>, Float> metaExperience = new HashMap<List<Integer>, Float>();

    public static final GemcutterRecipes smelting()
    {
        return gemcutterBase;
    }

    private GemcutterRecipes()
    {
        this.addGemcutterSmelting(new ItemStack(mod_Ores.AmazoniteUncut), new ItemStack(mod_Ores.PolisherTowel), new ItemStack(mod_Ores.AmazoniteGem));
    }

    /**
     * Adds a smelting recipe.
     */
    public void addGemcutterSmelting(ItemStack input1, ItemStack input2, ItemStack output)
    {
    	this.gemcutterSmeltingList1.put(Arrays.asList(input1.itemID, input1.getItemDamage()), output);
    	this.gemcutterSmeltingList2.put(Arrays.asList(input2.itemID, input2.getItemDamage()), output);
    	this.gemcutterSmeltingCheckList1.put(Arrays.asList(input2.itemID, input2.getItemDamage()), input1);
    	this.gemcutterSmeltingCheckList2.put(Arrays.asList(input2.itemID, input2.getItemDamage()), input2);
    }

    public ItemStack getGemcutterSmeltingResult(ItemStack item1, ItemStack item2)
    {
    	if(item1 == null){return null;}
    	if(item2 == null){return null;}
    	
    	if(item1.itemID == mod_Ores.AmazoniteUncut.itemID && item2.itemID == mod_Ores.PolisherTowel.itemID || item2.itemID == mod_Ores.AmazoniteUncut.itemID && item1.itemID == mod_Ores.PolisherTowel.itemID)
    	{
    		return new ItemStack(mod_Ores.AmazoniteGem);
    	}

    	return null;
    }

    public ItemStack getSlot1ReduceAmount(ItemStack input)
    {
    	return (ItemStack) this.gemcutterSmeltingList1.get(Arrays.asList(input.itemID, input.getItemDamage()));
    }
    
    public ItemStack getSlot2ReduceAmount(ItemStack input)
    {
    	return (ItemStack) this.gemcutterSmeltingList1.get(Arrays.asList(input.itemID, input.getItemDamage()));
    }
    
    /*public Map getSmeltingList()
    {
        return this.gemcutterList;
    }

    @Deprecated //In favor of ItemStack sensitive version
    public float getExperience(int par1)
    {
        return this.experienceList.containsKey(Integer.valueOf(par1)) ? ((Float)this.experienceList.get(Integer.valueOf(par1))).floatValue() : 0.0F;
    }

    public void addSmelting(int itemID, int metadata, ItemStack itemstack, float experience)
    {
    	gemcutterSmeltingList.put(Arrays.asList(itemID, metadata), itemstack);
        metaExperience.put(Arrays.asList(itemID, metadata), experience);
    }

    public ItemStack getSmeltingResult(ItemStack item, ItemStack item2) 
    {
        if (item == null || item2 == null)
        {
            return null;
        }
        ItemStack ret = (ItemStack)gemcutterSmeltingList.get(Arrays.asList(item.itemID, item.getItemDamage(), item2.itemID, item2.getItemDamage()));
        if (ret != null) 
        {
            return ret;
        }
        return (ItemStack)gemcutterList.get(Integer.valueOf(item.itemID));
    }

    public float getExperience(ItemStack item)
    {
        if (item == null || item.getItem() == null)
        {
            return 0;
        }
        float ret = item.getItem().getSmeltingExperience(item);
        if (ret < 0 && metaExperience.containsKey(Arrays.asList(item.itemID, item.getItemDamage())))
        {
            ret = metaExperience.get(Arrays.asList(item.itemID, item.getItemDamage()));
        }
        if (ret < 0 && experienceList.containsKey(item.itemID))
        {
            ret = ((Float)experienceList.get(item.itemID)).floatValue();
        }
        return (ret < 0 ? 0 : ret);
    }

    public Map<List<Integer>, ItemStack> getMetaSmeltingList()
    {
        return gemcutterSmeltingList;
    }*/
}

 

 

 

The ContainerGemcutter :

 

 

package Mod_Ores.Blocks.Gemcutter;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;

public class ContainerGemcutter extends Container
{
    private TileEntityGemcutter gemcutter;
    private int lastGemCookTime = 0;
    private int lastGemBurnTime = 0;
    private int lastGemItemBurnTime = 0;

    public ContainerGemcutter(InventoryPlayer par1InventoryPlayer, TileEntityGemcutter par2TileEntityGemcutter)
    {
        this.gemcutter = par2TileEntityGemcutter;
        this.addSlotToContainer(new Slot(par2TileEntityGemcutter, TileEntityGemcutter.input_slot_1_index, 56, 17));
        this.addSlotToContainer(new Slot(par2TileEntityGemcutter, TileEntityGemcutter.input_slot_2_index, 65, 53));
        this.addSlotToContainer(new Slot(par2TileEntityGemcutter, TileEntityGemcutter.fuel_inventory_index, 46, 53));
        this.addSlotToContainer(new Slot(par2TileEntityGemcutter, TileEntityGemcutter.output_inventory_index, 116, 35));
        //this.addSlotToContainer(new SlotGemcutter(par1InventoryPlayer.player, par2TileEntityGemcutter, 2, 116, 35));

        for (int invRow = 0; invRow < 3; ++invRow)
        {
            for (int invCol = 0; invCol < 9; ++invCol)
            {
                this.addSlotToContainer(new Slot(par1InventoryPlayer, invCol + invRow * 9 + 9, 8 + invCol * 18, 84 + invRow * 18));
            }
        }

        for (int actionBar = 0; actionBar < 9; ++actionBar)
        {
            this.addSlotToContainer(new Slot(par1InventoryPlayer, actionBar, 8 + actionBar * 18, 142));
        }
    }

    @Override
    public void addCraftingToCrafters(ICrafting par1ICrafting)
    {
        super.addCraftingToCrafters(par1ICrafting);
        par1ICrafting.sendProgressBarUpdate(this, 0, this.gemcutter.gemcutterCookTime);
        par1ICrafting.sendProgressBarUpdate(this, 1, this.gemcutter.gemcutterBurnTime);
        par1ICrafting.sendProgressBarUpdate(this, 2, this.gemcutter.currentGemItemBurnTime);
    }

    @Override
    public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

        for (int i = 0; i < this.crafters.size(); ++i)
        {
            ICrafting icrafting = (ICrafting)this.crafters.get(i);

            if (this.lastGemCookTime != this.gemcutter.gemcutterCookTime)
            {
                icrafting.sendProgressBarUpdate(this, 0, this.gemcutter.gemcutterCookTime);
            }

            if (this.lastGemBurnTime != this.gemcutter.gemcutterBurnTime)
            {
                icrafting.sendProgressBarUpdate(this, 1, this.gemcutter.gemcutterBurnTime);
            }

            if (this.lastGemItemBurnTime != this.gemcutter.currentGemItemBurnTime)
            {
                icrafting.sendProgressBarUpdate(this, 2	, this.gemcutter.currentGemItemBurnTime);
            }
        }

        this.lastGemCookTime = this.gemcutter.gemcutterCookTime;
        this.lastGemBurnTime = this.gemcutter.gemcutterBurnTime;
        this.lastGemItemBurnTime = this.gemcutter.currentGemItemBurnTime;
    }

    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int par1, int par2)
    {
        if (par1 == 0)
        {
            this.gemcutter.gemcutterCookTime = par2;
        }

        if (par1 == 1)
        {
            this.gemcutter.gemcutterBurnTime = par2;
        }

        if (par1 == 2)
        {
            this.gemcutter.currentGemItemBurnTime = par2;
        }
    }
    
    @Override
    public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    {
        return true;
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(par2);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();
            
            if (par2 == 2)
            {
                if (!this.mergeItemStack(itemstack1, 3, 39, true))
                {
                    return null;
                }

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (par2 != 1 && par2 != 0)
            {
                if (GemcutterRecipes.smelting().getGemcutterSmeltingResult(itemstack1, itemstack1) != null)
                {
                    if (!this.mergeItemStack(itemstack1, 0, 1, false))
                    {
                        return null;
                    }
                }
                else if (TileEntityGemcutter.isItemFuel(itemstack1))
                {
                    if (!this.mergeItemStack(itemstack1, 1, 2, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 3 && par2 < 30)
                {
                    if (!this.mergeItemStack(itemstack1, 30, 39, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 3, 39, false))
            {
                return null;
            }

            if (itemstack1.stackSize == 0)
            {
                slot.putStack((ItemStack)null);
            }
            else
            {
                slot.onSlotChanged();
            }

            if (itemstack1.stackSize == itemstack.stackSize)
            {
                return null;
            }

            slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
        }
     	
        return itemstack;
    }
}

 

 

 

And last but not least the BlockGemcutterBench :

 

 

package Mod_Ores.Blocks.Gemcutter;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;

public class ContainerGemcutter extends Container
{
    private TileEntityGemcutter gemcutter;
    private int lastGemCookTime = 0;
    private int lastGemBurnTime = 0;
    private int lastGemItemBurnTime = 0;

    public ContainerGemcutter(InventoryPlayer par1InventoryPlayer, TileEntityGemcutter par2TileEntityGemcutter)
    {
        this.gemcutter = par2TileEntityGemcutter;
        this.addSlotToContainer(new Slot(par2TileEntityGemcutter, TileEntityGemcutter.input_slot_1_index, 56, 17));
        this.addSlotToContainer(new Slot(par2TileEntityGemcutter, TileEntityGemcutter.input_slot_2_index, 65, 53));
        this.addSlotToContainer(new Slot(par2TileEntityGemcutter, TileEntityGemcutter.fuel_inventory_index, 46, 53));
        this.addSlotToContainer(new Slot(par2TileEntityGemcutter, TileEntityGemcutter.output_inventory_index, 116, 35));
        //this.addSlotToContainer(new SlotGemcutter(par1InventoryPlayer.player, par2TileEntityGemcutter, 2, 116, 35));

        for (int invRow = 0; invRow < 3; ++invRow)
        {
            for (int invCol = 0; invCol < 9; ++invCol)
            {
                this.addSlotToContainer(new Slot(par1InventoryPlayer, invCol + invRow * 9 + 9, 8 + invCol * 18, 84 + invRow * 18));
            }
        }

        for (int actionBar = 0; actionBar < 9; ++actionBar)
        {
            this.addSlotToContainer(new Slot(par1InventoryPlayer, actionBar, 8 + actionBar * 18, 142));
        }
    }

    @Override
    public void addCraftingToCrafters(ICrafting par1ICrafting)
    {
        super.addCraftingToCrafters(par1ICrafting);
        par1ICrafting.sendProgressBarUpdate(this, 0, this.gemcutter.gemcutterCookTime);
        par1ICrafting.sendProgressBarUpdate(this, 1, this.gemcutter.gemcutterBurnTime);
        par1ICrafting.sendProgressBarUpdate(this, 2, this.gemcutter.currentGemItemBurnTime);
    }

    @Override
    public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

        for (int i = 0; i < this.crafters.size(); ++i)
        {
            ICrafting icrafting = (ICrafting)this.crafters.get(i);

            if (this.lastGemCookTime != this.gemcutter.gemcutterCookTime)
            {
                icrafting.sendProgressBarUpdate(this, 0, this.gemcutter.gemcutterCookTime);
            }

            if (this.lastGemBurnTime != this.gemcutter.gemcutterBurnTime)
            {
                icrafting.sendProgressBarUpdate(this, 1, this.gemcutter.gemcutterBurnTime);
            }

            if (this.lastGemItemBurnTime != this.gemcutter.currentGemItemBurnTime)
            {
                icrafting.sendProgressBarUpdate(this, 2	, this.gemcutter.currentGemItemBurnTime);
            }
        }

        this.lastGemCookTime = this.gemcutter.gemcutterCookTime;
        this.lastGemBurnTime = this.gemcutter.gemcutterBurnTime;
        this.lastGemItemBurnTime = this.gemcutter.currentGemItemBurnTime;
    }

    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int par1, int par2)
    {
        if (par1 == 0)
        {
            this.gemcutter.gemcutterCookTime = par2;
        }

        if (par1 == 1)
        {
            this.gemcutter.gemcutterBurnTime = par2;
        }

        if (par1 == 2)
        {
            this.gemcutter.currentGemItemBurnTime = par2;
        }
    }
    
    @Override
    public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    {
        return true;
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(par2);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();
            
            if (par2 == 2)
            {
                if (!this.mergeItemStack(itemstack1, 3, 39, true))
                {
                    return null;
                }

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (par2 != 1 && par2 != 0)
            {
                if (GemcutterRecipes.smelting().getGemcutterSmeltingResult(itemstack1, itemstack1) != null)
                {
                    if (!this.mergeItemStack(itemstack1, 0, 1, false))
                    {
                        return null;
                    }
                }
                else if (TileEntityGemcutter.isItemFuel(itemstack1))
                {
                    if (!this.mergeItemStack(itemstack1, 1, 2, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 3 && par2 < 30)
                {
                    if (!this.mergeItemStack(itemstack1, 30, 39, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 3, 39, false))
            {
                return null;
            }

            if (itemstack1.stackSize == 0)
            {
                slot.putStack((ItemStack)null);
            }
            else
            {
                slot.onSlotChanged();
            }

            if (itemstack1.stackSize == itemstack.stackSize)
            {
                return null;
            }

            slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
        }
     	
        return itemstack;
    }
}

 

 

 

I hope that someone can help me trace the error to what the problem is that is causing this error as i haven't found it yet.

 

Thanks for your effort and time.

Link to comment
Share on other sites

Line 260 of TileEntityGemCutter is:

if(this.gemcutterItemStacks[0].stackSize < GemcutterRecipes.smelting().getSlot1ReduceAmount(this.gemcutterItemStacks[0]).stackSize) return false;       

 

Probably that: getSlot1ReduceAmount() returns a null (because gemcutterItemStacks[0] wasn't in gemcutterSmeltingList1).

 

Possible solutions:

-make a global try/catch for NullPointerException (and return false inside catch block) in canCut() and remove every null check (lazy)

-use a null check for this case in the TileEntity canCut() method (simple)

-perform a check of the given itemstack to be within the list before getting it (less simple, but re-useable)

Link to comment
Share on other sites

I have tried to do what you sayd although i am not completely sure if this is the way to do it:

 

 

public void cutItem()
    {
        if (this.canCut())
        {
            ItemStack itemstack = GemcutterRecipes.smelting().getGemcutterSmeltingResult(this.gemcutterItemStacks[0], this.gemcutterItemStacks[1]);
            
            if (this.gemcutterItemStacks[3] == null)
            {
                this.gemcutterItemStacks[3] = itemstack.copy();
            }
            else if (this.gemcutterItemStacks[3].isItemEqual(itemstack))
            {
                gemcutterItemStacks[3].stackSize += itemstack.stackSize;
            }
            
            if(GemcutterRecipes.gemcutterSmeltingList1.containsValue(this.gemcutterItemStacks[0]) || GemcutterRecipes.gemcutterSmeltingList1.containsValue(this.gemcutterItemStacks[1]))
            {
            	if(GemcutterRecipes.gemcutterSmeltingList2.containsValue(this.gemcutterItemStacks[0]) || GemcutterRecipes.gemcutterSmeltingList2.containsValue(this.gemcutterItemStacks[1]))
            	{
                    this.gemcutterItemStacks[0].stackSize -= GemcutterRecipes.smelting().getSlot1ReduceAmount(this.gemcutterItemStacks[0]).stackSize;
                    this.gemcutterItemStacks[1].stackSize -= GemcutterRecipes.smelting().getSlot2ReduceAmount(this.gemcutterItemStacks[1]).stackSize;
            	}
            	
            	this.gemcutterItemStacks[0] = null;
            }
            else
            {
            	this.gemcutterItemStacks[0] = null;
            }

            if (this.gemcutterItemStacks[0].stackSize <= 0)
            {
                this.gemcutterItemStacks[0] = null;
            }
            
            if (this.gemcutterItemStacks[1].stackSize <= 0)
            {
                this.gemcutterItemStacks[1] = null;
            }
        }
    }

 

 

 

But it still gives out a nullpointer this time in addGemcutterRecipe()

 

this is where this error occurs :

public void addGemcutterSmelting(ItemStack input1, ItemStack input2, ItemStack output)
{
    	this.gemcutterSmeltingList1.put(Arrays.asList(input1.itemID, input1.getItemDamage()), output);
    	this.gemcutterSmeltingList2.put(Arrays.asList(input2.itemID, input2.getItemDamage()), output);
    	this.gemcutterSmeltingCheckList1.put(Arrays.asList(input2.itemID, input2.getItemDamage()), input1);
    	this.gemcutterSmeltingCheckList2.put(Arrays.asList(input2.itemID, input2.getItemDamage()), input2);
}

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.