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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm developing a dimension, but it's kinda resource intensive so some times during player teleporting it lags behind making the player phase down into the void, so im trying to implement some kind of pregeneration to force the game loading a small set of chunks in the are the player will teleport to. Some of the things i've tried like using ServerLevel and ServerChunkCache methods like getChunk() dont actually trigger chunk generation if the chunk isn't already on persistent storage (already generated) or placing tickets, but that doesn't work either. Ideally i should be able to check when the task has ended too. I've peeked around some pregen engines, but they're too complex for my current understanding of the system of which I have just a basic understanding (how ServerLevel ,ServerChunkCache  and ChunkMap work) of. Any tips or other classes I should be looking into to understand how to do this correctly?
    • https://mclo.gs/4UC49Ao
    • Way back in the Forge 1.17 days, work started for adding JPMS (Java Platform Module Support) to ModLauncher and ForgeModLoader. This has been used internally by Forge and some libraries for a while now, but mods (those with mods.toml specifically) have not been able to take advantage of it. As of Forge 1.21.1 and 1.21.3, this is now possible!   What is JPMS and what does it mean for modders? JPMS is the Java Platform Module System, introduced in Java 9. It allows you to define modules, which are collections of packages and resources that can be exported or hidden from other modules. This allows for much more fine-tuned control over visibility, cleaner syntax for service declarations and support for sealed types across packages. For example, you might have a mod with a module called `com.example.mod` that exports `com.example.mod.api` and `com.example.mod.impl` to other mods, but hides `com.example.mod.internal` from them. This would allow you to have a clean API for other mods to use, while keeping your internal implementation details hidden from IDE hints, helping prevent accidental usage of internals that might break without prior notice. This is particularly useful if you'd like to use public records with module-private constructors or partially module-private record components, as you can create a sealed interface that only your record implements, having the interface be exported and the record hidden. It's also nice for declaring and using services, as you'll get compile-time errors from the Java compiler for typos and the like, rather than deferring to runtime errors. In more advanced cases, you can also have public methods that are only accessible to specific other modules -- handy if you want internal interactions between multiple of your own mods.   How do I bypass it? We understand there may be drama in implementing a system that prevents mods from accessing each other's internals when necessary (like when a mod is abandoned or you need to fix a compat issue) -- after all, we are already modding a game that doesn't have explicit support for Java mods yet. We have already thought of this and are offering APIs from day one to selectively bypass module restrictions. Let me be clear: Forge mods are not required to use JPMS. If you don't want to use it, you don't have to. The default behaviour is to have fully open, fully exported automatic modules. In Java, you can use the `Add-Opens` and `Add-Exports` manifest attributes to selectively bypass module restrictions of other mods at launch time, and we've added explicit support for these when loading your Forge mods. At compile-time, you can use existing solutions such as the extra-java-module-info Gradle plugin to deal with non-modular dependencies and add extra opens and exports to other modules. Here's an example on how to make the internal package `com.example.examplemod.internal` open to your mod in your build.gradle: tasks.named('jar', Jar) { manifest { attributes([ 'Add-Opens' : 'com.example.examplemod/com.example.examplemod.internal' 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors // (...) ]) } } With the above in your mod's jar manifest, you can now reflectively access the classes inside that internal package. Multiple entries are separated with a space, as per Java's official spec. You can also use Add-Exports to directly call without reflection, however you'd need to use the Gradle plugin mentioned earlier to be able to compile. The syntax for Add-Exports is the same as Add-Opens, and instructions for the compile-time step with the Gradle plugin are detailed later in this post. Remember to prefer the opens and exports keywords inside module-info.java for sources you control. The Add-Opens/Add-Exports attributes are only intended for forcing open other mods.   What else is new with module support? Previously, the runtime module name was always forced to the first mod ID in your `mods.toml` file and all packages were forced fully open and exported. Module names are now distinguished from mod IDs, meaning the module name in your module-info.java can be different from the mod ID in your `mods.toml`. This allows you to have a more descriptive module name that doesn't have to be the same as your mod ID, however we strongly recommend including your mod ID as part of your module name to aid troubleshooting. The `Automatic-Module-Name` manifest attribute is now also honoured, allowing you to specify a module name for your mod without needing to create a `module-info.java` file. This is particularly useful for mods that don't care about JPMS features but want to have a more descriptive module name and easier integration with other mods that do use JPMS.   How do I use it? The first step is to create a `module-info.java` file in your mod's source directory. This file should be in the same package as your main mod class, and should look something like this: open module com.example.examplemod { requires net.minecraftforge.eventbus; requires net.minecraftforge.fmlcore; requires net.minecraftforge.forge; requires net.minecraftforge.javafmlmod; requires net.minecraftforge.mergetool.api; requires org.slf4j; requires logging; } For now, we're leaving the whole module open to reflection, which is a good starting point. When we know we want to close something off, we can remove the open modifier from the module and open or export individual packages instead. Remember that you need to be open to Forge (module name net.minecraftforge.forge), otherwise it can't call your mod's constructor. Next is fixing modules in Gradle. While Forge and Java support modules properly, Gradle does not put automatic modules on the module path by default, meaning that the logging module (from com.mojang:logging) is not found. To fix this, add the Gradle plugin and add a compile-time module definition for that Mojang library: plugins { // (...) id 'org.gradlex.extra-java-module-info' version "1.9" } // (...) extraJavaModuleInfo { failOnMissingModuleInfo = false automaticModule("com.mojang:logging", "logging") } The automatic module override specified in your build.gradle should match the runtime one to avoid errors. You can do the same for any library or mod dependency that is missing either a module-info or explicit Automatic-Module-Name, however be aware that you may need to update your mod once said library adds one. That's all you need to get started with module support in your mods. You can learn more about modules and how to use them at dev.java.
    • Faire la mise à jour grâce à ce lien m'a aider personnellement, merci à @Paint_Ninja. https://www.amd.com/en/support 
    • When I came across the 'Exit Code: I got a 1 error in my Minecraft mods, so I decided to figure out what was wrong. First, I took a look at the logs. In the mods folder (usually where you'd find logs or crash reports), I found the latest.log file or the corresponding crash report. I read it through carefully, looking for any lines with errors or warnings. Then I checked the Minecraft Forge support site, where you can often find info on what causes errors and how to fix them. I then disabled half of my mods and tried running the game. If the error disappeared, it meant that the problem was with the disabled mod. I repeated this several times to find the problem mod.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.