Jump to content

Recommended Posts

Posted

Made his "furnace" and I want her to make their recipes.

They are the same as the stove and recipes, but instead of getting experience I have while cooking.

But for some reason it does not work and breaks the game.

P.S Sorry for my bad english.

TileEntity:

package agravaine.esoteric.tileentity;

import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemFood;
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.tileentity.TileEntityFurnace;
import agravaine.agravainelib.block.tileentity.TileEntityInventoryBase;
import agravaine.agravainelib.item.crafting.CampfireRecipes;

public class TileEntityCampfire extends TileEntityInventoryBase{

public int fuelBurnTime;
public int currentFoodBurnTime;
public int campfireCookTime1;
public int campfireCookTime2;
public int cookingTime1;
public int cookingTime2;
public static final int FUEL = 1, INPUT_1 = 0, INPUT_2 = 3, OUTPUT_1 = 2, OUTPUT_2 = 4;

public TileEntityCampfire(){
	super("Campfire", false, 5);
	fuelBurnTime = 0;
	currentFoodBurnTime = 0;
	campfireCookTime1 = 0;
	campfireCookTime2 = 0;
	cookingTime1 = CampfireRecipes.cooking().getCookingTime(inventoryContents[iNPUT_1]);
	cookingTime2 = CampfireRecipes.cooking().getCookingTime(inventoryContents[iNPUT_2]);
}

public void writeToNBT(NBTTagCompound nbt){
	super.writeToNBT(nbt);
	nbt.setShort("BurnTime", (short)fuelBurnTime);
	nbt.setShort("CookTime1", (short)campfireCookTime1);
	nbt.setShort("CookTime2", (short)campfireCookTime2);
}

public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);
	fuelBurnTime = nbt.getShort("BurnTime");
	campfireCookTime1 = nbt.getShort("CookTime1");
	campfireCookTime2 = nbt.getShort("CookTime2");
	currentFoodBurnTime = getItemBurnTime(inventoryContents[FUEL]);
}

public int getInventoryStackLimit(){
	return 6;
}

public int getCookProgressScaled(int i, int j){
	if(j == 0){
		return cookingTime1 == 0 ? 0 : (campfireCookTime1 * i) / cookingTime1;
	}else{
		return cookingTime2 == 0 ? 0 : (campfireCookTime2 * i) / cookingTime2;
	}
}

public int getBurnTimeRemainingScaled(int i){
	if(currentFoodBurnTime == 0){
		currentFoodBurnTime = 200;
	}
	return (fuelBurnTime * i) / currentFoodBurnTime;
}

public boolean isBurning(){
	return fuelBurnTime > 0;
}

public void updateEntity(){
	boolean isBurning = fuelBurnTime > 0;
	boolean inventoryChanged = false;
	if(fuelBurnTime > 0){
		fuelBurnTime--;
	}
	if(!worldObj.isRemote){
		if(fuelBurnTime == 0 && (canCook(0, 2) || canCook(3, 4))){
			currentFoodBurnTime = fuelBurnTime = getItemBurnTime(inventoryContents[FUEL]);
			if(fuelBurnTime > 0){
				onInventoryChanged();
				if(inventoryContents[FUEL] != null){
					--inventoryContents[FUEL].stackSize;
					if(inventoryContents[FUEL].stackSize == 0){
						inventoryContents[FUEL] = inventoryContents[FUEL].getItem().getContainerItem(inventoryContents[FUEL]);
					}
				}
			}
		}
		if(isBurning()){
			if(canCook(INPUT_1, OUTPUT_1)){
				campfireCookTime1++;
				if(campfireCookTime1 == cookingTime1){
					campfireCookTime1 = 0;
					cookItem(0, 2);
					onInventoryChanged();
				}
			}else{
				campfireCookTime1 = 0;
			}
			if(canCook(INPUT_2, OUTPUT_2)){
				campfireCookTime2++;
				if(campfireCookTime2 == cookingTime2){
					campfireCookTime2 = 0;
					cookItem(3, 4);
					onInventoryChanged();
				}
			}else{
				campfireCookTime2 = 0;
			}
		}else{
			campfireCookTime1 = 0;
			campfireCookTime2 = 0;
		}
		if(isBurning != (fuelBurnTime > 0)){
			onInventoryChanged();
			//BlockCampfire.updateCampfireState(furnaceBurnTime > 0, worldObj, xCoord, yCoord, zCoord);
		}
	}
}

public boolean canCook(int input, int output){
	if(inventoryContents[input] == null){
		return false;
	}
	ItemStack itemstack = CampfireRecipes.cooking().getCookingResult(inventoryContents[input]);
	if(itemstack == null){
		return false;
	}
	if(inventoryContents[output] == null){
		return true;
	}
	if(!inventoryContents[output].isItemEqual(itemstack)){
		return false;
	}
	if(inventoryContents[output].stackSize + itemstack.stackSize <= getInventoryStackLimit() && inventoryContents[output].stackSize + itemstack.stackSize <= inventoryContents[output].getMaxStackSize()){
		return true;
	}
	return inventoryContents[output].stackSize + itemstack.stackSize <= itemstack.getMaxStackSize();
}

public void cookItem(int input, int output){
	if(!canCook(input, output)){
		return;
	}
	ItemStack itemstack = CampfireRecipes.cooking().getCookingResult(inventoryContents[input]);
	if(inventoryContents[output] == null){
		inventoryContents[output] = itemstack.copy();
	}else if(inventoryContents[output].getItem() == itemstack.getItem()){
		inventoryContents[output].stackSize += itemstack.stackSize;
	}
	--inventoryContents[input].stackSize;
	if(inventoryContents[input].stackSize <= 0){
		inventoryContents[input] = null;
	}
}

public static int getItemBurnTime(ItemStack iStack){
	if(iStack == null){
		return 0;
	}
	Item item = iStack.getItem();
	if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air){
		Block block = Block.getBlockFromItem(item);
		if(block == Blocks.wooden_slab){
			return 250;
		}
		if(block.getMaterial() == Material.wood){
			return 500;
		}
		if(block == Blocks.coal_block){
			return 18000;
		}
	}
	if(item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals("WOOD")){
		return 450;
	}
	if(item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals("WOOD")){
		return 450;
	}
	if(item instanceof ItemHoe && ((ItemHoe)item).getToolMaterialName().equals("WOOD")){
		return 450;
	}
	if(item == Items.stick) return 200;
	if(item == Items.coal) return 2400;
	if(item == Item.getItemFromBlock(Blocks.sapling)){
		return 150;
	}
	if(item == Items.blaze_rod){
		return 2700;
	}
	return GameRegistry.getFuelValue(iStack);
}

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

public boolean isItemValidForSlot(int slotId, ItemStack iStack){
	return slotId == OUTPUT_1 || slotId == OUTPUT_2 ? false : slotId == FUEL ? isItemFuel(iStack) : iStack.getItem() instanceof ItemFood;
}

public int[] getAccessibleSlotsFromSide(int slotId){
	return slotId == 0 || slotId == 3 ? new int[]{2, 1, 4, 3} : (slotId == 1 ? new int[] {0} : new int[] {1});
}

public boolean canInsertItem(int slotId, ItemStack iStack, int side){
	return isItemValidForSlot(slotId, iStack);
}

public boolean canExtractItem(int slotId, ItemStack iStack, int side){
	return false;
}
}

Recipes:

package agravaine.agravainelib.item.crafting;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFishFood;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;

public class CampfireRecipes{

private static final CampfireRecipes instance = new CampfireRecipes();;

private Map<ItemStack, ItemStack> cookingList = new HashMap<ItemStack, ItemStack>();
private Map<ItemStack, Integer> cookingTimeList = new HashMap<ItemStack, Integer>();

public static CampfireRecipes cooking(){
	return instance;
}

private CampfireRecipes(){
	addRecipe(Items.porkchop, new ItemStack(Items.cooked_porkchop), 250);
	addRecipe(Items.beef, new ItemStack(Items.cooked_beef), 250);
	addRecipe(Items.chicken, new ItemStack(Items.cooked_chicken), 300);
	addRecipe(Items.potato, new ItemStack(Items.baked_potato), 200);
	ItemFishFood.FishType[] fishtypes = ItemFishFood.FishType.values();
	for(int j = 0; j < fishtypes.length; ++j){
		ItemFishFood.FishType fishtype = fishtypes[j];
		if(fishtype.func_150973_i()){
			addRecipe(new ItemStack(Items.fish, 1, fishtype.func_150976_a()), new ItemStack(Items.cooked_fished, 1, fishtype.func_150976_a()), 320);
		}
	}
}

public void addRecipe(Item item, ItemStack result, int cookingTime){
	addRecipe(new ItemStack(item, 1, 32767), result, cookingTime);
}

public void addRecipe(ItemStack iStack, ItemStack result, int cookingTime){
	cookingList.put(iStack, result);
	cookingTimeList.put(result, cookingTime);
}

public ItemStack getCookingResult(ItemStack item){
	Iterator iterator = cookingList.entrySet().iterator();
	Entry entry;
	do{
		if(!iterator.hasNext()){
			return null;
		}
		entry = (Entry)iterator.next();
	}while(!areItemStacksEqual(item, (ItemStack)entry.getKey()));
	return (ItemStack)entry.getValue();
}

public int getCookingTime(ItemStack iStack){
        Iterator iterator = cookingTimeList.entrySet().iterator();
        Entry entry;
        do{
            if(!iterator.hasNext()){
                return 0;
            }
            entry = (Entry)iterator.next();
        }while(!areItemStacksEqual(iStack, (ItemStack)entry.getKey()));
        return ((Integer)entry.getValue()).intValue();
    }

private boolean areItemStacksEqual(ItemStack itemStackOne, ItemStack itemStackTwo){
	return itemStackTwo.getItem() == itemStackOne.getItem() && (itemStackTwo.getItemDamage() == 32767 || itemStackTwo.getItemDamage() == itemStackOne.getItemDamage());
}

public Map<ItemStack, ItemStack> getSmeltingList(){
	return cookingList;
}
}

Crash:

java.lang.NullPointerException
at agravaine.agravainelib.item.crafting.CampfireRecipes.areItemStacksEqual(CampfireRecipes.java:75) ~[CampfireRecipes.class:?]
at agravaine.agravainelib.item.crafting.CampfireRecipes.getCookingTime(CampfireRecipes.java:70) ~[CampfireRecipes.class:?]
at agravaine.esoteric.tileentity.TileEntityCampfire.<init>(TileEntityCampfire.java:37) ~[TileEntityCampfire.class:?]
at agravaine.esoteric.block.BlockCampfire.createNewTileEntity(BlockCampfire.java:21) ~[blockCampfire.class:?]
at net.minecraft.block.Block.createTileEntity(Block.java:1770) ~[block.class:?]
at net.minecraft.world.chunk.Chunk.func_150806_e(Chunk.java:939) ~[Chunk.class:?]
at net.minecraft.world.ChunkCache.getTileEntity(ChunkCache.java:103) ~[ChunkCache.class:?]
at net.minecraft.client.renderer.WorldRenderer.updateRenderer(WorldRenderer.java:189) ~[WorldRenderer.class:?]
at net.minecraft.client.renderer.RenderGlobal.updateRenderers(RenderGlobal.java:1616) ~[RenderGlobal.class:?]
at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1262) ~[EntityRenderer.class:?]
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1095) ~[EntityRenderer.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1024) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:912) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:112) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_55]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_55]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]
---- Minecraft Crash Report ----
// I'm sorry, Dave.

Time: 09.06.14 21:05
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
at agravaine.agravainelib.item.crafting.CampfireRecipes.areItemStacksEqual(CampfireRecipes.java:75)
at agravaine.agravainelib.item.crafting.CampfireRecipes.getCookingTime(CampfireRecipes.java:70)
at agravaine.esoteric.tileentity.TileEntityCampfire.<init>(TileEntityCampfire.java:37)
at agravaine.esoteric.block.BlockCampfire.createNewTileEntity(BlockCampfire.java:21)
at net.minecraft.block.Block.createTileEntity(Block.java:1770)
at net.minecraft.world.chunk.Chunk.func_150806_e(Chunk.java:939)
at net.minecraft.world.ChunkCache.getTileEntity(ChunkCache.java:103)
at net.minecraft.client.renderer.WorldRenderer.updateRenderer(WorldRenderer.java:189)
at net.minecraft.client.renderer.RenderGlobal.updateRenderers(RenderGlobal.java:1616)
at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1262)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1095)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1024)
at net.minecraft.client.Minecraft.run(Minecraft.java:912)
at net.minecraft.client.main.Main.main(Main.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)


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

-- Head --
Stacktrace:
at agravaine.agravainelib.item.crafting.CampfireRecipes.areItemStacksEqual(CampfireRecipes.java:75)
at agravaine.agravainelib.item.crafting.CampfireRecipes.getCookingTime(CampfireRecipes.java:70)
at agravaine.esoteric.tileentity.TileEntityCampfire.<init>(TileEntityCampfire.java:37)
at agravaine.esoteric.block.BlockCampfire.createNewTileEntity(BlockCampfire.java:21)
at net.minecraft.block.Block.createTileEntity(Block.java:1770)
at net.minecraft.world.chunk.Chunk.func_150806_e(Chunk.java:939)
at net.minecraft.world.ChunkCache.getTileEntity(ChunkCache.java:103)
at net.minecraft.client.renderer.WorldRenderer.updateRenderer(WorldRenderer.java:189)
at net.minecraft.client.renderer.RenderGlobal.updateRenderers(RenderGlobal.java:1616)
at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1262)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['Player376'/148, l='MpServer', x=-272,64, y=5,62, z=-1090,34]]
Chunk stats: MultiplayerChunkCache: 35, 35
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: World: (-282,4,-1086), Chunk: (at 6,0,2 in -18,-68; contains blocks -288,0,-1088 to -273,255,-1073), Region: (-1,-3; contains chunks -32,-96 to -1,-65, blocks -512,0,-1536 to -1,255,-1025)
Level time: 4264 game time, 4264 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 28 total; [EntityChicken['Chicken'/76, l='MpServer', x=-293,50, y=4,00, z=-1119,50], EntityHorse['Horse'/77, l='MpServer', x=-291,50, y=4,00, z=-1119,50], EntityPig['Pig'/78, l='MpServer', x=-289,50, y=4,00, z=-1119,84], EntityPig['Pig'/79, l='MpServer', x=-300,81, y=4,00, z=-1106,34], EntityChicken['Chicken'/73, l='MpServer', x=-300,69, y=4,00, z=-1123,97], EntityChicken['Chicken'/74, l='MpServer', x=-292,53, y=4,00, z=-1127,53], EntityHorse['Horse'/75, l='MpServer', x=-300,28, y=4,00, z=-1122,88], EntityClientPlayerMP['Player376'/148, l='MpServer', x=-272,64, y=5,62, z=-1090,34], EntityChicken['Chicken'/85, l='MpServer', x=-278,63, y=4,00, z=-1099,41], EntityPig['Pig'/84, l='MpServer', x=-284,78, y=4,00, z=-1119,81], EntityHorse['Horse'/87, l='MpServer', x=-262,50, y=4,00, z=-1115,50], EntityChicken['Chicken'/86, l='MpServer', x=-272,63, y=4,00, z=-1088,44], EntityPig['Pig'/81, l='MpServer', x=-288,88, y=4,00, z=-1115,13], EntityPig['Pig'/80, l='MpServer', x=-289,38, y=4,00, z=-1111,88], EntitySheep['Sheep'/83, l='MpServer', x=-285,63, y=4,00, z=-1134,22], EntityCow['Cow'/93, l='MpServer', x=-247,50, y=4,00, z=-1115,50], EntityCow['Cow'/94, l='MpServer', x=-251,50, y=4,00, z=-1115,81], EntityCow['Cow'/89, l='MpServer', x=-265,13, y=4,00, z=-1107,31], EntityHorse['Horse'/88, l='MpServer', x=-262,97, y=4,00, z=-1118,16], EntityCow['Cow'/90, l='MpServer', x=-258,34, y=4,00, z=-1105,47], EntitySheep['Sheep'/111, l='MpServer', x=-227,81, y=4,00, z=-1086,69], EntitySheep['Sheep'/108, l='MpServer', x=-227,75, y=4,00, z=-1090,03], EntitySheep['Sheep'/109, l='MpServer', x=-233,38, y=4,00, z=-1090,19], EntitySheep['Sheep'/107, l='MpServer', x=-231,81, y=4,00, z=-1088,44], EntitySheep['Sheep'/115, l='MpServer', x=-223,91, y=4,00, z=-1087,94], EntitySheep['Sheep'/114, l='MpServer', x=-238,50, y=4,00, z=-1082,50], EntitySheep['Sheep'/113, l='MpServer', x=-234,50, y=4,00, z=-1082,50], EntitySheep['Sheep'/112, l='MpServer', x=-227,03, y=4,00, z=-1080,09]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:412)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2523)
at net.minecraft.client.Minecraft.run(Minecraft.java:941)
at net.minecraft.client.main.Main.main(Main.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

-- System Details --
Details:
Minecraft Version: 1.7.2
Operating System: Windows XP (x86) version 5.1
Java Version: 1.7.0_55, Oracle Corporation
Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation
Memory: 896474512 bytes (854 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 9254 (518224 bytes; 0 MB) allocated, 2 (112 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.03 FML v7.2.209.1112 Minecraft Forge 10.12.1.1112 5 mods loaded, 5 mods active
mcp{9.03} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.2.209.1112} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.1.1112.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.12.1.1112} [Minecraft Forge] (forgeSrc-1.7.2-10.12.1.1112.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
AgravaineLib{0.12} [AgravaineLib] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Esoteric{Alpha Alpha 0.03} [Esoteric] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Launched Version: 1.6
LWJGL: 2.9.0
OpenGL: GeForce 6100 nForce 405/PCI/SSE2/3DNOW! GL version 2.0.3, NVIDIA Corporation
Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: []
Current Language: English (US)
Profiler Position: N/A (disabled)
Vec3 Pool Size: 33 (1848 bytes; 0 MB) allocated, 26 (1456 bytes; 0 MB) used
Anisotropic Filtering: Off (1)
[21:05:09] [server thread/INFO]: Stopping server
#@!@# Game crashed! Crash report saved to: #@!@# C:\Modding\Forge\eclipse\.\crash-reports\crash-2014-06-09_21.05.09-client.txt
[21:05:09] [Client thread/INFO] [FML]: Waiting for the server to terminate/save.
[21:05:09] [server thread/INFO]: Saving players
[21:05:09] [server thread/INFO]: Saving worlds
[21:05:09] [server thread/INFO]: Saving chunks for level 'New World'/Overworld
[21:05:10] [server thread/INFO]: Saving chunks for level 'New World'/Nether
[21:05:10] [server thread/INFO]: Saving chunks for level 'New World'/The End
[21:05:10] [server thread/INFO] [FML]: Unloading dimension 0
[21:05:10] [server thread/INFO] [FML]: Unloading dimension -1
[21:05:10] [server thread/INFO] [FML]: Unloading dimension 1
[21:05:10] [server thread/INFO] [FML]: Applying holder lookups
[21:05:10] [server thread/INFO] [FML]: Holder lookups applied
[21:05:10] [Client thread/INFO] [FML]: Server terminated.
AL lib: (EE) alc_cleanup: 1 device not closed

Indicates this method:

private boolean areItemStacksEqual(ItemStack itemStackOne, ItemStack itemStackTwo){
	return itemStackTwo.getItem() == itemStackOne.getItem() && (itemStackTwo.getItemDamage() == 32767 || itemStackTwo.getItemDamage() == itemStackOne.getItemDamage()); //<----------------------------
}

Help, please!

Posted

I'm guessing one of your ItemStacks are null.

 

The most understanding point where it's null is where you define Entry.

entry = (Entry)iterator.next();

In other words, check if iterator.next() is not null before you apply it to "Entry."

Posted

Does not work :(

public int getCookingTime(ItemStack iStack){
        Iterator iterator = cookingTimeList.entrySet().iterator();
        Entry entry = null;
        do{
            if(!iterator.hasNext()){
                return 0;
            }
            if(iterator.next() != null){
			entry = (Entry)iterator.next();
		}
        }while(!areItemStacksEqual(iStack, (ItemStack)entry.getKey()));
        return ((Integer)entry.getValue()).intValue();
    }

Posted
public TileEntityCampfire(){
          .....
	cookingTime1 = CampfireRecipes.cooking().getCookingTime(inventoryContents[iNPUT_1]); <--- NULL
	cookingTime2 = CampfireRecipes.cooking().getCookingTime(inventoryContents[iNPUT_2]); <--- also null
}

Posted

Not work...

package agravaine.esoteric.tileentity;

import net.minecraft.init.Items;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import agravaine.agravainelib.block.tileentity.TileEntityInventoryBase;
import agravaine.agravainelib.item.crafting.CampfireRecipes;

public class TileEntityCampfire extends TileEntityInventoryBase{

    public int fuelBurnTime;
    public int currentFoodBurnTime;
    public int campfireCookTime1;
    public int campfireCookTime2;
    public static final int FUEL = 1, INPUT_1 = 0, INPUT_2 = 3, OUTPUT_1 = 2, OUTPUT_2 = 4;

    public TileEntityCampfire(){
        super("Campfire", false, 5);
        fuelBurnTime = 0;
        currentFoodBurnTime = 0;
        campfireCookTime1 = 0;
        campfireCookTime2 = 0;
    }

    public void writeToNBT(NBTTagCompound nbt){
        super.writeToNBT(nbt);
        nbt.setShort("BurnTime", (short)fuelBurnTime);
        nbt.setShort("CookTime1", (short)campfireCookTime1);
        nbt.setShort("CookTime2", (short)campfireCookTime2);
    }

    public void readFromNBT(NBTTagCompound nbt){
        super.readFromNBT(nbt);
        fuelBurnTime = nbt.getShort("BurnTime");
        campfireCookTime1 = nbt.getShort("CookTime1");
        campfireCookTime2 = nbt.getShort("CookTime2");
        currentFoodBurnTime = getItemBurnTime(inventoryContents[FUEL]);
    }

    public int getInventoryStackLimit(){
        return 6;
    }

    public int getCookProgressScaled(int i, int j){
        int cookingTime;
        if(j == 0){
            cookingTime = CampfireRecipes.cooking().getCookingTime(inventoryContents[iNPUT_1]);
            return (campfireCookTime1 * i) / cookingTime;
        }else{
            cookingTime = CampfireRecipes.cooking().getCookingTime(inventoryContents[iNPUT_2]);
            return (campfireCookTime2 * i) / cookingTime;
        }
    }

    public int getBurnTimeRemainingScaled(int i){
        if(currentFoodBurnTime == 0){
            currentFoodBurnTime = 200;
        }
        return (fuelBurnTime * i) / currentFoodBurnTime;
    }

    public boolean isBurning(){
        return fuelBurnTime > 0;
    }

    public void updateEntity(){
        boolean isBurning = fuelBurnTime > 0;
        boolean inventoryChanged = false;
        if(fuelBurnTime > 0){
            fuelBurnTime--;
        }
        if(!worldObj.isRemote){
            if(fuelBurnTime == 0 && (canCook(0, 2) || canCook(3, 4))){
                currentFoodBurnTime = fuelBurnTime = getItemBurnTime(inventoryContents[FUEL]);
                if(fuelBurnTime > 0){
                    onInventoryChanged();
                    if(inventoryContents[FUEL] != null){
                        --inventoryContents[FUEL].stackSize;
                        if(inventoryContents[FUEL].stackSize == 0){
                            inventoryContents[FUEL] = inventoryContents[FUEL].getItem().getContainerItem(inventoryContents[FUEL]);
                        }
                    }
                }
            }
            if(isBurning()){
                if(canCook(INPUT_1, OUTPUT_1)){
                    campfireCookTime1++;
                    int cookingTime = CampfireRecipes.cooking().getCookingTime(inventoryContents[iNPUT_1]);
                    if(campfireCookTime1 == cookingTime){
                        campfireCookTime1 = 0;
                        cookItem(0, 2);
                        onInventoryChanged();
                    }
                }else{
                    campfireCookTime1 = 0;
                }
                if(canCook(INPUT_2, OUTPUT_2)){
                    campfireCookTime2++;
                    int cookingTime = CampfireRecipes.cooking().getCookingTime(inventoryContents[iNPUT_2]);
                    if(campfireCookTime2 == cookingTime){
                        campfireCookTime2 = 0;
                        cookItem(3, 4);
                        onInventoryChanged();
                    }
                }else{
                    campfireCookTime2 = 0;
                }
            }else{
                campfireCookTime1 = 0;
                campfireCookTime2 = 0;
            }
            if(isBurning != (fuelBurnTime > 0)){
                onInventoryChanged();
                //BlockCampfire.updateCampfireState(furnaceBurnTime > 0, worldObj, xCoord, yCoord, zCoord);
            }
        }
    }

    public boolean canCook(int input, int output){
        if(inventoryContents[input] == null){
            return false;
        }
        ItemStack itemstack = CampfireRecipes.cooking().getCookingResult(inventoryContents[input]);
        if(itemstack == null){
            return false;
        }
        if(inventoryContents[output] == null){
            return true;
        }
        if(!inventoryContents[output].isItemEqual(itemstack)){
            return false;
        }
        if(inventoryContents[output].stackSize + itemstack.stackSize <= getInventoryStackLimit() && inventoryContents[output].stackSize + itemstack.stackSize <= inventoryContents[output].getMaxStackSize()){
            return true;
        }
        return inventoryContents[output].stackSize + itemstack.stackSize <= itemstack.getMaxStackSize();
    }

    public void cookItem(int input, int output){
        if(!canCook(input, output)){
            return;
        }
        ItemStack itemstack = CampfireRecipes.cooking().getCookingResult(inventoryContents[input]);
        if(inventoryContents[output] == null){
            inventoryContents[output] = itemstack.copy();
        }else if(inventoryContents[output].getItem() == itemstack.getItem()){
            inventoryContents[output].stackSize += itemstack.stackSize;
        }
        --inventoryContents[input].stackSize;
        if(inventoryContents[input].stackSize <= 0){
            inventoryContents[input] = null;
        }
    }

    public static int getItemBurnTime(ItemStack itemstack){
        return TileEntityFurnace.getItemBurnTime(itemstack);
    }

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

    public boolean isItemValidForSlot(int slotId, ItemStack iStack){
        return slotId == OUTPUT_1 || slotId == OUTPUT_2 ? false : slotId == FUEL ? isItemFuel(iStack) : iStack.getItem() instanceof ItemFood;
    }
    
    public int[] getAccessibleSlotsFromSide(int slotId){
        return slotId == 0 || slotId == 3 ? new int[]{2, 1, 4, 3} : (slotId == 1 ? new int[] {0} : new int[] {1});
    }

    public boolean canInsertItem(int slotId, ItemStack iStack, int side){
        return isItemValidForSlot(slotId, iStack);
    }

    public boolean canExtractItem(int slotId, ItemStack iStack, int side){
        return false;
    }
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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