Jump to content

[SOLVED] [1.11] Shapeless and Shaped Recipes Issues, crashing game


SirJoseph

Recommended Posts

Hey guys! I just updated my mod and realized that whenever I craft an item the game crashes. It happens to all my 1.11 mods and it was all working on 1.10.2. If anyone else has this problem I hope we can figure out whats wrong.

 

Here is the crash report,

 

 

---- Minecraft Crash Report ----

// There are four lights!

 

Time: 11/18/16 3:54 PM

Description: Updating screen events

 

java.lang.NullPointerException: The validated object is null

at org.apache.commons.lang3.Validate.notNull(Validate.java:222)

at org.apache.commons.lang3.Validate.notNull(Validate.java:203)

at net.minecraft.util.NonNullList.set(NonNullList.java:48)

at net.minecraft.item.crafting.ShapelessRecipes.getRemainingItems(ShapelessRecipes.java:34)

at net.minecraft.item.crafting.CraftingManager.getRemainingItems(CraftingManager.java:347)

at net.minecraft.inventory.SlotCrafting.func_190901_a(SlotCrafting.java:136)

at net.minecraft.inventory.Container.slotClick(Container.java:320)

at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:594)

at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:687)

at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:429)

at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:608)

at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:574)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1790)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1117)

at net.minecraft.client.Minecraft.run(Minecraft.java:405)

at net.minecraft.client.main.Main.main(Main.java:118)

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:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

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.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)

at GradleStart.main(GradleStart.java:26)

 

 

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

---------------------------------------------------------------------------------------

 

-- Head --

Thread: Client thread

Stacktrace:

at org.apache.commons.lang3.Validate.notNull(Validate.java:222)

at org.apache.commons.lang3.Validate.notNull(Validate.java:203)

at net.minecraft.util.NonNullList.set(NonNullList.java:48)

at net.minecraft.item.crafting.ShapelessRecipes.getRemainingItems(ShapelessRecipes.java:34)

at net.minecraft.item.crafting.CraftingManager.getRemainingItems(CraftingManager.java:347)

at net.minecraft.inventory.SlotCrafting.func_190901_a(SlotCrafting.java:136)

at net.minecraft.inventory.Container.slotClick(Container.java:320)

at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:594)

at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:687)

at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:429)

at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:608)

at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:574)

 

-- Affected screen --

Details:

Screen name: net.minecraft.client.gui.inventory.GuiCrafting

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityPlayerSP['Player801'/176, l='MpServer', x=-236.66, y=64.00, z=194.98]]

Chunk stats: MultiplayerChunkCache: 564, 564

Level seed: 0

Level generator: ID 00 - default, ver 1. Features enabled: false

Level generator options:

Level spawn location: World: (-241,64,195), Chunk: (at 15,4,3 in -16,12; contains blocks -256,0,192 to -241,255,207), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)

Level time: 2261 game time, 2261 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: 84 total; [EntitySquid['Squid'/128, l='MpServer', x=-203.19, y=57.38, z=144.94], EntitySquid['Squid'/129, l='MpServer', x=-198.21, y=59.50, z=175.13], EntitySquid['Squid'/130, l='MpServer', x=-196.80, y=55.95, z=178.63], EntitySquid['Squid'/131, l='MpServer', x=-196.82, y=58.07, z=199.73], EntitySquid['Squid'/132, l='MpServer', x=-179.01, y=51.55, z=176.30], EntitySquid['Squid'/133, l='MpServer', x=-183.34, y=55.78, z=178.32], EntityBat['Bat'/134, l='MpServer', x=-172.46, y=29.10, z=197.25], EntityCreeper['Creeper'/135, l='MpServer', x=-191.50, y=27.00, z=214.50], EntityCreeper['Creeper'/141, l='MpServer', x=-168.50, y=23.00, z=211.50], EntityZombie['Zombie'/142, l='MpServer', x=-167.50, y=45.00, z=225.50], EntityZombie['Zombie'/145, l='MpServer', x=-162.24, y=28.00, z=135.50], EntityEnderman['Enderman'/275, l='MpServer', x=-161.48, y=30.00, z=171.55], EntityEnderman['Enderman'/277, l='MpServer', x=-171.44, y=30.00, z=176.51], EntitySkeleton['Skeleton'/27, l='MpServer', x=-310.50, y=37.00, z=128.50], EntityPig['Pig'/30, l='MpServer', x=-300.70, y=70.00, z=234.52], EntityWolf['Wolf'/31, l='MpServer', x=-306.50, y=66.00, z=238.50], EntityPig['Pig'/32, l='MpServer', x=-302.50, y=69.00, z=237.25], EntityWolf['Wolf'/33, l='MpServer', x=-311.50, y=64.00, z=239.71], EntityPig['Pig'/34, l='MpServer', x=-309.25, y=64.00, z=232.48], EntityWolf['Wolf'/35, l='MpServer', x=-308.73, y=65.00, z=242.61], EntityWolf['Wolf'/36, l='MpServer', x=-307.30, y=66.00, z=243.45], EntitySkeleton['Skeleton'/38, l='MpServer', x=-303.50, y=24.00, z=117.50], EntitySkeleton['Skeleton'/39, l='MpServer', x=-300.50, y=24.00, z=117.50], EntitySkeleton['Skeleton'/40, l='MpServer', x=-295.21, y=47.00, z=136.49], EntitySpider['Spider'/41, l='MpServer', x=-290.77, y=46.00, z=136.14], EntitySpider['Spider'/42, l='MpServer', x=-296.30, y=47.00, z=137.76], EntitySquid['Squid'/43, l='MpServer', x=-295.96, y=62.54, z=143.68], EntityPig['Pig'/44, l='MpServer', x=-296.68, y=71.00, z=231.19], EntityBat['Bat'/46, l='MpServer', x=-292.47, y=16.10, z=274.75], EntityBat['Bat'/51, l='MpServer', x=-281.25, y=48.95, z=135.04], EntityWolf['Wolf'/52, l='MpServer', x=-274.52, y=74.00, z=251.59], EntityPlayerSP['Player801'/176, l='MpServer', x=-236.66, y=64.00, z=194.98], EntityCreeper['Creeper'/53, l='MpServer', x=-283.54, y=27.00, z=266.80], EntityCreeper['Creeper'/54, l='MpServer', x=-285.50, y=40.00, z=266.50], EntityZombie['Zombie'/55, l='MpServer', x=-275.26, y=40.00, z=261.50], EntityCreeper['Creeper'/56, l='MpServer', x=-275.50, y=39.00, z=265.50], EntityCreeper['Creeper'/57, l='MpServer', x=-275.50, y=39.00, z=266.50], EntityZombie['Zombie'/58, l='MpServer', x=-276.05, y=39.00, z=267.56], EntityZombie['Zombie'/59, l='MpServer', x=-276.70, y=39.00, z=267.45], EntityBat['Bat'/73, l='MpServer', x=-265.25, y=27.10, z=120.54], EntityWolf['Wolf'/74, l='MpServer', x=-263.50, y=70.00, z=223.50], EntityWolf['Wolf'/75, l='MpServer', x=-263.50, y=70.00, z=223.50], EntityWolf['Wolf'/76, l='MpServer', x=-262.50, y=70.00, z=223.50], EntityCreeper['Creeper'/77, l='MpServer', x=-260.48, y=43.00, z=258.84], EntitySpider['Spider'/78, l='MpServer', x=-271.50, y=42.00, z=262.50], EntityCreeper['Creeper'/79, l='MpServer', x=-257.50, y=35.00, z=262.50], EntityBat['Bat'/80, l='MpServer', x=-264.25, y=42.10, z=261.25], EntityWolf['Wolf'/81, l='MpServer', x=-269.32, y=75.00, z=259.50], EntityWolf['Wolf'/82, l='MpServer', x=-264.50, y=77.00, z=259.50], EntityWolf['Wolf'/83, l='MpServer', x=-267.33, y=74.00, z=268.50], EntitySquid['Squid'/88, l='MpServer', x=-251.45, y=51.65, z=134.60], EntitySkeleton['Skeleton'/89, l='MpServer', x=-251.49, y=19.00, z=204.75], EntityWolf['Wolf'/90, l='MpServer', x=-252.64, y=69.00, z=228.50], EntityWolf['Wolf'/91, l='MpServer', x=-240.49, y=70.00, z=260.72], EntityWolf['Wolf'/92, l='MpServer', x=-241.70, y=68.00, z=268.78], EntityWolf['Wolf'/93, l='MpServer', x=-244.50, y=69.00, z=272.50], EntityWolf['Wolf'/94, l='MpServer', x=-251.46, y=73.00, z=277.30], EntityBat['Bat'/99, l='MpServer', x=-240.45, y=42.88, z=157.29], EntityCreeper['Creeper'/100, l='MpServer', x=-220.49, y=59.00, z=183.17], EntityZombie['Zombie'/101, l='MpServer', x=-238.26, y=30.00, z=209.52], EntityZombie['Zombie'/102, l='MpServer', x=-233.40, y=21.00, z=217.54], EntitySpider['Spider'/103, l='MpServer', x=-235.70, y=28.00, z=239.00], EntitySkeleton['Skeleton'/104, l='MpServer', x=-237.50, y=28.00, z=241.50], EntityCreeper['Creeper'/105, l='MpServer', x=-233.54, y=44.00, z=267.19], EntityZombie['Zombie'/106, l='MpServer', x=-233.63, y=35.00, z=269.30], EntityCreeper['Creeper'/107, l='MpServer', x=-234.50, y=35.00, z=260.50], EntityWitch['Witch'/108, l='MpServer', x=-209.50, y=39.00, z=143.50], EntitySkeleton['Skeleton'/109, l='MpServer', x=-217.50, y=36.00, z=140.18], EntityBat['Bat'/110, l='MpServer', x=-214.62, y=37.98, z=135.48], EntitySkeleton['Skeleton'/111, l='MpServer', x=-209.50, y=39.00, z=144.50], EntitySquid['Squid'/112, l='MpServer', x=-212.39, y=56.82, z=147.40], EntityBat['Bat'/113, l='MpServer', x=-215.61, y=27.10, z=214.50], EntityCreeper['Creeper'/114, l='MpServer', x=-216.50, y=42.00, z=217.50], EntityZombie['Zombie'/115, l='MpServer', x=-217.50, y=36.00, z=220.50], EntityZombie['Zombie'/116, l='MpServer', x=-218.50, y=36.00, z=220.50], EntityBat['Bat'/117, l='MpServer', x=-217.51, y=47.10, z=219.09], EntitySkeleton['Skeleton'/118, l='MpServer', x=-210.50, y=42.00, z=215.50], EntityBat['Bat'/119, l='MpServer', x=-222.49, y=29.03, z=223.75], EntityBat['Bat'/120, l='MpServer', x=-215.98, y=32.06, z=220.76], EntityZombie['Zombie'/121, l='MpServer', x=-221.30, y=25.90, z=238.70], EntityBat['Bat'/122, l='MpServer', x=-213.40, y=22.96, z=226.30], EntityZombie['Zombie'/123, l='MpServer', x=-217.50, y=49.00, z=229.50], EntityZombie['Zombie'/124, l='MpServer', x=-215.48, y=27.00, z=237.74], EntitySquid['Squid'/127, l='MpServer', x=-199.04, y=55.99, z=139.94]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:451)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2772)

at net.minecraft.client.Minecraft.run(Minecraft.java:426)

at net.minecraft.client.main.Main.main(Main.java:118)

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:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

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.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)

at GradleStart.main(GradleStart.java:26)

 

-- System Details --

Details:

Minecraft Version: 1.11

Operating System: Windows 7 (amd64) version 6.1

Java Version: 1.8.0_101, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 474998632 bytes (452 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94

FML: MCP 9.35 Powered by Forge 13.19.0.2130 4 mods loaded, 4 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UCHIJAAAA mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)

UCHIJAAAA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.11-13.19.0.2130.jar)

UCHIJAAAA forge{13.19.0.2130} [Minecraft Forge] (forgeSrc-1.11-13.19.0.2130.jar)

UCHIJAAAA sushimod{1.0} [sushi Mod] (bin)

Loaded coremods (and transformers):

GL info: ' Vendor: 'ATI Technologies Inc.' Version: '4.2.11476 Compatibility Profile Context' Renderer: 'AMD Radeon HD 7660G'

Launched Version: 1.11

LWJGL: 2.9.4

OpenGL: AMD Radeon HD 7660G GL version 4.2.11476 Compatibility Profile Context, ATI Technologies Inc.

GL Caps: Using GL 1.3 multitexturing.

Using GL 1.3 texture combiners.

Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.

Shaders are available because OpenGL 2.1 is supported.

VBOs are available because OpenGL 1.5 is supported.

 

Using VBOs: Yes

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)

CPU: 4x AMD A10-4600M APU with Radeon HD Graphics

 

 

 

I tried this with all my custom recipes and it doesn't even work for vanilla items. It crashes every time I try to make an item with a custom recipe. It crashes with shaped recipes and shapeless recipes.

 

Here is one of my recipes, it is in the init() method of my main mod class.

GameRegistry.addShapelessRecipe(new ItemStack(ModItems.riceball ,1), ModItems.nori, ModItems.rice, ModItems.rice, ModItems.rice);

 

Everything else in my mod works, i can eat the riceball and i can put the items on the crafting table and it appears on the crafting result slot, but as soon as i click on it the game crashes.

 

sorry if this ends up being something stupid  :P

Link to comment
Share on other sites

Post your main class

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

here is the main class,

 

package com.exline.sushimod;

import com.exline.sushimod.block.ModBlocks;
import com.exline.sushimod.proxy.CommonProxy;

import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = SushiMod.MODID, version = SushiMod.VERSION)
public class SushiMod 
{
public static final String MODID = "sushimod";
public static final String VERSION = "1.0";

@Mod.Instance(MODID)
public static SushiMod instance;

@SidedProxy(serverSide = "com.exline.sushimod.proxy.CommonProxy", clientSide = "com.exline.sushimod.proxy.ClientProxy")
public static CommonProxy proxy;


@EventHandler
public void preInit(FMLPreInitializationEvent event) 
{
	ModBlocks.init();
	ModSeeds.init();
	ModCucumberSeeds.init();
	ModItems.init();
}

@EventHandler
public void init(FMLInitializationEvent event) 
{
	// recipes here
	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.fishroll ,1), Items.CARROT, ModItems.cucumber, Items.FISH, ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);
	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.salmonroll ,1), Items.CARROT, ModItems.cucumber, (new ItemStack(Items.FISH, 1, 1)), ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);
	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.pufferfishroll ,1), Items.CARROT, ModItems.cucumber, (new ItemStack(Items.FISH, 1, 3)), ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);
	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.cucumberroll ,1), ModItems.cucumber, ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);
	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.mushroomroll ,1), Blocks.BROWN_MUSHROOM, Blocks.BROWN_MUSHROOM, Blocks.BROWN_MUSHROOM, ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);
	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.clownfishroll ,1), Items.CARROT, ModItems.cucumber, (new ItemStack(Items.FISH, 1, 2)), ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);
	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.rainbowroll ,1),(new ItemStack(Items.FISH, 1, 3)),(new ItemStack(Items.FISH, 1, 0)),(new ItemStack(Items.FISH, 1, 1)), ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);
	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.rainbowroll ,1),(new ItemStack(Items.FISH, 1, 3)),(new ItemStack(Items.FISH, 1, 0)),(new ItemStack(Items.FISH, 1, 2)), ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);
	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.rainbowroll ,1),(new ItemStack(Items.FISH, 1, 3)),(new ItemStack(Items.FISH, 1, 1)),(new ItemStack(Items.FISH, 1, 2)), ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);

	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.sashimi ,1), (new ItemStack(Items.FISH, 1, 0)), ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);
	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.clownfishsashimi ,1), (new ItemStack(Items.FISH, 1, 2)), ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);
	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.salmonsashimi ,1),(new ItemStack(Items.FISH, 1, 1)), ModItems.rice, ModItems.rice, ModItems.rice, ModItems.nori);

	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.riceball, 1), ModItems.nori, ModItems.rice, ModItems.rice, ModItems.rice);

	GameRegistry.addShapelessRecipe(new ItemStack(ModCucumberSeeds.cucumberseeds ,2), ModItems.cucumber);

	GameRegistry.addShapelessRecipe(new ItemStack(ModItems.nori ,3), Blocks.WATERLILY);

	GameRegistry.addSmelting(ModSeeds.riceseeds, new ItemStack(ModItems.rice), 0.0f);

	MinecraftForge.EVENT_BUS.register(new TallGrassEventHandler());
}
}

Link to comment
Share on other sites

Also here is the new class for the ItemStack class, i was thinking this may help solve the problem. Im looking at it now.

package net.minecraft.item;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Random;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentDurability;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.BlockEntityTag;
import net.minecraft.util.datafix.walkers.EntityTag;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.HoverEvent;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public final class ItemStack implements net.minecraftforge.common.capabilities.ICapabilitySerializable<NBTTagCompound>
{
    public static final ItemStack field_190927_a = new ItemStack((Item)null);
    public static final DecimalFormat DECIMALFORMAT = new DecimalFormat("#.##");
    /** Size of the stack. */
    private int stackSize;
    /** Number of animation frames to go when receiving an item (by walking into it, for example). */
    private int animationsToGo;
    private final Item item;
    /** A NBTTagMap containing data about an ItemStack. Can only be used for non stackable items */
    private NBTTagCompound stackTagCompound;
    private boolean field_190928_g;
    int itemDamage;
    /** Item frame this stack is on, or null if not on an item frame. */
    private EntityItemFrame itemFrame;
    private Block canDestroyCacheBlock;
    private boolean canDestroyCacheResult;
    private Block canPlaceOnCacheBlock;
    private boolean canPlaceOnCacheResult;

    private net.minecraftforge.fml.common.registry.RegistryDelegate<Item> delegate;
    private net.minecraftforge.common.capabilities.CapabilityDispatcher capabilities;
    private NBTTagCompound capNBT;

    public ItemStack(Block blockIn)
    {
        this((Block)blockIn, 1);
    }

    public ItemStack(Block blockIn, int amount)
    {
        this((Block)blockIn, amount, 0);
    }

    public ItemStack(Block blockIn, int amount, int meta)
    {
        this(Item.getItemFromBlock(blockIn), amount, meta);
    }

    public ItemStack(Item itemIn)
    {
        this((Item)itemIn, 1);
    }

    public ItemStack(Item itemIn, int amount)
    {
        this((Item)itemIn, amount, 0);
    }

    public ItemStack(Item itemIn, int amount, int meta){ this(itemIn, amount, meta, null); }
    public ItemStack(Item itemIn, int amount, int meta, NBTTagCompound capNBT)
    {
        this.capNBT = capNBT;
        this.item = itemIn;
        this.itemDamage = meta;
        this.stackSize = amount;

        if (this.itemDamage < 0)
        {
            this.itemDamage = 0;
        }

        this.func_190923_F();
    }

    private void func_190923_F()
    {
        this.field_190928_g = this.func_190926_b();
        this.delegate = this.item != null ? this.item.delegate : null;
    }

    public ItemStack(NBTTagCompound p_i47263_1_)
    {
        this.capNBT = p_i47263_1_.hasKey("ForgeCaps") ? p_i47263_1_.getCompoundTag("ForgeCaps") : null;
        this.item = Item.getByNameOrId(p_i47263_1_.getString("id"));
        this.stackSize = p_i47263_1_.getByte("Count");
        this.itemDamage = Math.max(0, p_i47263_1_.getShort("Damage"));

        if (p_i47263_1_.hasKey("tag", 10))
        {
            this.stackTagCompound = p_i47263_1_.getCompoundTag("tag");

            if (this.item != null)
            {
                this.item.updateItemStackNBT(p_i47263_1_);
            }
        }

        this.func_190923_F();
    }

    public boolean func_190926_b()
    {
        return this == field_190927_a ? true : (this.item != null && this.item != Item.getItemFromBlock(Blocks.AIR) ? (this.stackSize <= 0 ? true : this.itemDamage < -32768 || this.itemDamage > 65535) : true);
    }

    public static void registerFixes(DataFixer fixer)
    {
        fixer.registerWalker(FixTypes.ITEM_INSTANCE, new BlockEntityTag());
        fixer.registerWalker(FixTypes.ITEM_INSTANCE, new EntityTag());
    }

    /**
     * Splits off a stack of the given amount of this stack and reduces this stack by the amount.
     */
    public ItemStack splitStack(int amount)
    {
        int i = Math.min(amount, this.stackSize);
        ItemStack itemstack = this.copy();
        itemstack.func_190920_e(i);
        this.func_190918_g(i);
        return itemstack;
    }

    /**
     * Returns the object corresponding to the stack.
     */
    public Item getItem()
    {
        return this.field_190928_g || this.delegate == null ? Item.getItemFromBlock(Blocks.AIR) : this.delegate.get();
    }

    /**
     * Called when the player uses this ItemStack on a Block (right-click). Places blocks, etc. (Legacy name:
     * tryPlaceItemIntoWorld)
     */
    public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        if (!worldIn.isRemote) return net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(this, playerIn, worldIn, pos, side, hitX, hitY, hitZ, hand);
        EnumActionResult enumactionresult = this.getItem().onItemUse(playerIn, worldIn, pos, hand, side, hitX, hitY, hitZ);

        if (enumactionresult == EnumActionResult.SUCCESS)
        {
            playerIn.addStat(StatList.getObjectUseStats(this.item));
        }

        return enumactionresult;
    }

    public EnumActionResult onItemUseFirst(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        // copy of onitemuse but for onitemusefirst
        EnumActionResult enumactionresult = this.getItem().onItemUseFirst(playerIn, worldIn, pos, side, hitX, hitY, hitZ, hand);

        if (enumactionresult == EnumActionResult.SUCCESS)
        {
            playerIn.addStat(StatList.getObjectUseStats(this.item));
        }

        return enumactionresult;
    }

    public float getStrVsBlock(IBlockState blockIn)
    {
        return this.getItem().getStrVsBlock(this, blockIn);
    }

    public ActionResult<ItemStack> useItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand)
    {
        return this.getItem().onItemRightClick(worldIn, playerIn, hand);
    }

    /**
     * Called when the item in use count reach 0, e.g. item food eaten. Return the new ItemStack. Args : world, entity
     */
    public ItemStack onItemUseFinish(World worldIn, EntityLivingBase entityLiving)
    {
        return this.getItem().onItemUseFinish(this, worldIn, entityLiving);
    }

    /**
     * Write the stack fields to a NBT object. Return the new NBT object.
     */
    public NBTTagCompound writeToNBT(NBTTagCompound nbt)
    {
        ResourceLocation resourcelocation = (ResourceLocation)Item.REGISTRY.getNameForObject(this.item);
        nbt.setString("id", resourcelocation == null ? "minecraft:air" : resourcelocation.toString());
        nbt.setByte("Count", (byte)this.stackSize);
        nbt.setShort("Damage", (short)this.itemDamage);

        if (this.stackTagCompound != null)
        {
            nbt.setTag("tag", this.stackTagCompound);
        }

        if (this.capabilities != null)
        {
            NBTTagCompound cnbt = this.capabilities.serializeNBT();
            if (!cnbt.hasNoTags()) nbt.setTag("ForgeCaps", cnbt);
        }

        return nbt;
    }

    /**
     * Returns maximum size of the stack.
     */
    public int getMaxStackSize()
    {
        return this.getItem().getItemStackLimit(this);
    }

    /**
     * Returns true if the ItemStack can hold 2 or more units of the item.
     */
    public boolean isStackable()
    {
        return this.getMaxStackSize() > 1 && (!this.isItemStackDamageable() || !this.isItemDamaged());
    }

    /**
     * true if this itemStack is damageable
     */
    public boolean isItemStackDamageable()
    {
        return this.field_190928_g ? false : (this.item.getMaxDamage(this) <= 0 ? false : !this.hasTagCompound() || !this.getTagCompound().getBoolean("Unbreakable"));
    }

    public boolean getHasSubtypes()
    {
        return this.getItem().getHasSubtypes();
    }

    /**
     * returns true when a damageable item is damaged
     */
    public boolean isItemDamaged()
    {
        return this.isItemStackDamageable() && getItem().isDamaged(this);
    }

    public int getItemDamage()
    {
        /**
         * Returns the object corresponding to the stack.
         */
        return getItem().getDamage(this);
    }

    public int getMetadata()
    {
        /**
         * Returns the object corresponding to the stack.
         */
        return getItem().getMetadata(this);
    }

    public void setItemDamage(int meta)
    {
        getItem().setDamage(this, meta);
    }

    /**
     * Returns the max damage an item in the stack can take.
     */
    public int getMaxDamage()
    {
        return this.getItem().getMaxDamage(this);
    }

    /**
     * Attempts to damage the ItemStack with par1 amount of damage, If the ItemStack has the Unbreaking enchantment
     * there is a chance for each point of damage to be negated. Returns true if it takes more damage than
     * getMaxDamage(). Returns false otherwise or if the ItemStack can't be damaged or if all points of damage are
     * negated.
     */
    public boolean attemptDamageItem(int amount, Random rand)
    {
        if (!this.isItemStackDamageable())
        {
            return false;
        }
        else
        {
            if (amount > 0)
            {
                int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, this);
                int j = 0;

                for (int k = 0; i > 0 && k < amount; ++k)
                {
                    if (EnchantmentDurability.negateDamage(this, i, rand))
                    {
                        ++j;
                    }
                }

                amount -= j;

                if (amount <= 0)
                {
                    return false;
                }
            }

            setItemDamage(getItemDamage() + amount); //Redirect through Item's callback if applicable.
            return getItemDamage() > getMaxDamage();
        }
    }

    /**
     * Damages the item in the ItemStack
     */
    public void damageItem(int amount, EntityLivingBase entityIn)
    {
        if (!(entityIn instanceof EntityPlayer) || !((EntityPlayer)entityIn).capabilities.isCreativeMode)
        {
            if (this.isItemStackDamageable())
            {
                if (this.attemptDamageItem(amount, entityIn.getRNG()))
                {
                    entityIn.renderBrokenItemStack(this);
                    this.func_190918_g(1);

                    if (entityIn instanceof EntityPlayer)
                    {
                        EntityPlayer entityplayer = (EntityPlayer)entityIn;
                        entityplayer.addStat(StatList.getObjectBreakStats(this.item));
                    }

                    this.itemDamage = 0;
                }
            }
        }
    }

    /**
     * Calls the delegated method to the Item to damage the incoming Entity, and if necessary, triggers a stats
     * increase.
     */
    public void hitEntity(EntityLivingBase entityIn, EntityPlayer playerIn)
    {
        boolean flag = this.item.hitEntity(this, entityIn, playerIn);

        if (flag)
        {
            playerIn.addStat(StatList.getObjectUseStats(this.item));
        }
    }

    /**
     * Called when a Block is destroyed using this ItemStack
     */
    public void onBlockDestroyed(World worldIn, IBlockState blockIn, BlockPos pos, EntityPlayer playerIn)
    {
        boolean flag = this.getItem().onBlockDestroyed(this, worldIn, blockIn, pos, playerIn);

        if (flag)
        {
            playerIn.addStat(StatList.getObjectUseStats(this.item));
        }
    }

    /**
     * Check whether the given Block can be harvested using this ItemStack.
     */
    public boolean canHarvestBlock(IBlockState blockIn)
    {
        return this.getItem().canHarvestBlock(blockIn, this);
    }

    public boolean interactWithEntity(EntityPlayer playerIn, EntityLivingBase entityIn, EnumHand hand)
    {
        return this.getItem().itemInteractionForEntity(this, playerIn, entityIn, hand);
    }

    /**
     * Returns a new stack with the same properties.
     */
    public ItemStack copy()
    {
        ItemStack itemstack = new ItemStack(this.item, this.stackSize, this.itemDamage, this.capabilities != null ? this.capabilities.serializeNBT() : null);

        if (this.stackTagCompound != null)
        {
            itemstack.stackTagCompound = this.stackTagCompound.copy();
        }

        return itemstack;
    }

    public static boolean areItemStackTagsEqual(ItemStack stackA, ItemStack stackB)
    {
        return stackA.func_190926_b() && stackB.func_190926_b() ? true : (!stackA.func_190926_b() && !stackB.func_190926_b() ? (stackA.stackTagCompound == null && stackB.stackTagCompound != null ? false : stackA.stackTagCompound == null || stackA.stackTagCompound.equals(stackB.stackTagCompound)) : false);
    }

    /**
     * compares ItemStack argument1 with ItemStack argument2; returns true if both ItemStacks are equal
     */
    public static boolean areItemStacksEqual(ItemStack stackA, ItemStack stackB)
    {
        return stackA.func_190926_b() && stackB.func_190926_b() ? true : (!stackA.func_190926_b() && !stackB.func_190926_b() ? stackA.isItemStackEqual(stackB) : false);
    }

    /**
     * compares ItemStack argument to the instance ItemStack; returns true if both ItemStacks are equal
     */
    private boolean isItemStackEqual(ItemStack other)
    {
        return this.stackSize != other.stackSize ? false : (this.getItem() != other.getItem() ? false : (this.itemDamage != other.itemDamage ? false : (this.stackTagCompound == null && other.stackTagCompound != null ? false : this.stackTagCompound == null || this.stackTagCompound.equals(other.stackTagCompound))));
    }

    /**
     * Compares Item and damage value of the two stacks
     */
    public static boolean areItemsEqual(ItemStack stackA, ItemStack stackB)
    {
        return stackA == stackB ? true : (!stackA.func_190926_b() && !stackB.func_190926_b() ? stackA.isItemEqual(stackB) : false);
    }

    public static boolean areItemsEqualIgnoreDurability(ItemStack stackA, ItemStack stackB)
    {
        return stackA == stackB ? true : (!stackA.func_190926_b() && !stackB.func_190926_b() ? stackA.isItemEqualIgnoreDurability(stackB) : false);
    }

    /**
     * compares ItemStack argument to the instance ItemStack; returns true if the Items contained in both ItemStacks are
     * equal
     */
    public boolean isItemEqual(ItemStack other)
    {
        return !other.func_190926_b() && this.item == other.item && this.itemDamage == other.itemDamage;
    }

    public boolean isItemEqualIgnoreDurability(ItemStack stack)
    {
        return !this.isItemStackDamageable() ? this.isItemEqual(stack) : !stack.func_190926_b() && this.item == stack.item;
    }

    public String getUnlocalizedName()
    {
        return this.getItem().getUnlocalizedName(this);
    }

    public String toString()
    {
        return this.stackSize + "x" + this.getItem().getUnlocalizedName() + "@" + this.itemDamage;
    }

    /**
     * Called each tick as long the ItemStack in on player inventory. Used to progress the pickup animation and update
     * maps.
     */
    public void updateAnimation(World worldIn, Entity entityIn, int inventorySlot, boolean isCurrentItem)
    {
        if (this.animationsToGo > 0)
        {
            --this.animationsToGo;
        }

        if (this.item != null)
        {
            this.item.onUpdate(this, worldIn, entityIn, inventorySlot, isCurrentItem);
        }
    }

    public void onCrafting(World worldIn, EntityPlayer playerIn, int amount)
    {
        playerIn.addStat(StatList.getCraftStats(this.item), amount);
        this.getItem().onCreated(this, worldIn, playerIn);
    }

    public int getMaxItemUseDuration()
    {
        return this.getItem().getMaxItemUseDuration(this);
    }

    public EnumAction getItemUseAction()
    {
        return this.getItem().getItemUseAction(this);
    }

    /**
     * Called when the player releases the use item button.
     */
    public void onPlayerStoppedUsing(World worldIn, EntityLivingBase entityLiving, int timeLeft)
    {
        this.getItem().onPlayerStoppedUsing(this, worldIn, entityLiving, timeLeft);
    }

    /**
     * Returns true if the ItemStack has an NBTTagCompound. Currently used to store enchantments.
     */
    public boolean hasTagCompound()
    {
        return !this.field_190928_g && this.stackTagCompound != null;
    }

    /**
     * Returns the NBTTagCompound of the ItemStack.
     */
    @Nullable
    public NBTTagCompound getTagCompound()
    {
        return this.stackTagCompound;
    }

    public NBTTagCompound func_190925_c(String p_190925_1_)
    {
        if (this.stackTagCompound != null && this.stackTagCompound.hasKey(p_190925_1_, 10))
        {
            return this.stackTagCompound.getCompoundTag(p_190925_1_);
        }
        else
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            this.setTagInfo(p_190925_1_, nbttagcompound);
            return nbttagcompound;
        }
    }

    /**
     * Get an NBTTagCompound from this stack's NBT data.
     */
    @Nullable
    public NBTTagCompound getSubCompound(String key)
    {
        return this.stackTagCompound != null && this.stackTagCompound.hasKey(key, 10) ? this.stackTagCompound.getCompoundTag(key) : null;
    }

    public void func_190919_e(String p_190919_1_)
    {
        if (this.stackTagCompound != null && this.stackTagCompound.hasKey(p_190919_1_, 10))
        {
            this.stackTagCompound.removeTag(p_190919_1_);
        }
    }

    @Nullable
    public NBTTagList getEnchantmentTagList()
    {
        return this.stackTagCompound == null ? null : this.stackTagCompound.getTagList("ench", 10);
    }

    /**
     * Assigns a NBTTagCompound to the ItemStack, minecraft validates that only non-stackable items can have it.
     */
    public void setTagCompound(@Nullable NBTTagCompound nbt)
    {
        this.stackTagCompound = nbt;
    }

    /**
     * returns the display name of the itemstack
     */
    public String getDisplayName()
    {
        NBTTagCompound nbttagcompound = this.getSubCompound("display");

        if (nbttagcompound != null)
        {
            if (nbttagcompound.hasKey("Name", )
            {
                return nbttagcompound.getString("Name");
            }

            if (nbttagcompound.hasKey("LocName", )
            {
                return I18n.translateToLocal(nbttagcompound.getString("LocName"));
            }
        }

        return this.getItem().getItemStackDisplayName(this);
    }

    public ItemStack func_190924_f(String p_190924_1_)
    {
        this.func_190925_c("display").setString("LocName", p_190924_1_);
        return this;
    }

    public ItemStack setStackDisplayName(String displayName)
    {
        this.func_190925_c("display").setString("Name", displayName);
        return this;
    }

    /**
     * Clear any custom name set for this ItemStack
     */
    public void clearCustomName()
    {
        NBTTagCompound nbttagcompound = this.getSubCompound("display");

        if (nbttagcompound != null)
        {
            nbttagcompound.removeTag("Name");

            if (nbttagcompound.hasNoTags())
            {
                this.func_190919_e("display");
            }
        }

        if (this.stackTagCompound != null && this.stackTagCompound.hasNoTags())
        {
            this.stackTagCompound = null;
        }
    }

    /**
     * Returns true if the itemstack has a display name
     */
    public boolean hasDisplayName()
    {
        NBTTagCompound nbttagcompound = this.getSubCompound("display");
        return nbttagcompound != null && nbttagcompound.hasKey("Name", ;
    }

    @SideOnly(Side.CLIENT)
    public List<String> getTooltip(EntityPlayer playerIn, boolean advanced)
    {
        List<String> list = Lists.<String>newArrayList();
        String s = this.getDisplayName();

        if (this.hasDisplayName())
        {
            s = TextFormatting.ITALIC + s;
        }

        s = s + TextFormatting.RESET;

        if (advanced)
        {
            String s1 = "";

            if (!s.isEmpty())
            {
                s = s + " (";
                s1 = ")";
            }

            int i = Item.getIdFromItem(this.item);

            if (this.getHasSubtypes())
            {
                s = s + String.format("#%04d/%d%s", new Object[] {Integer.valueOf(i), Integer.valueOf(this.itemDamage), s1});
            }
            else
            {
                s = s + String.format("#%04d%s", new Object[] {Integer.valueOf(i), s1});
            }
        }
        else if (!this.hasDisplayName() && this.item == Items.FILLED_MAP)
        {
            s = s + " #" + this.itemDamage;
        }

        list.add(s);
        int i1 = 0;

        if (this.hasTagCompound() && this.stackTagCompound.hasKey("HideFlags", 99))
        {
            i1 = this.stackTagCompound.getInteger("HideFlags");
        }

        if ((i1 & 32) == 0)
        {
            this.getItem().addInformation(this, playerIn, list, advanced);
        }

        if (this.hasTagCompound())
        {
            if ((i1 & 1) == 0)
            {
                NBTTagList nbttaglist = this.getEnchantmentTagList();

                if (nbttaglist != null && !nbttaglist.hasNoTags())
                {
                    for (int j = 0; j < nbttaglist.tagCount(); ++j)
                    {
                        int k = nbttaglist.getCompoundTagAt(j).getShort("id");
                        int l = nbttaglist.getCompoundTagAt(j).getShort("lvl");

                        if (Enchantment.getEnchantmentByID(k) != null)
                        {
                            list.add(Enchantment.getEnchantmentByID(k).getTranslatedName(l));
                        }
                    }
                }
            }

            if (this.stackTagCompound.hasKey("display", 10))
            {
                NBTTagCompound nbttagcompound = this.stackTagCompound.getCompoundTag("display");

                if (nbttagcompound.hasKey("color", 3))
                {
                    if (advanced)
                    {
                        list.add(I18n.translateToLocalFormatted("item.color", new Object[] {String.format("#%06X", new Object[]{Integer.valueOf(nbttagcompound.getInteger("color"))})}));
                    }
                    else
                    {
                        list.add(TextFormatting.ITALIC + I18n.translateToLocal("item.dyed"));
                    }
                }

                if (nbttagcompound.getTagId("Lore") == 9)
                {
                    NBTTagList nbttaglist3 = nbttagcompound.getTagList("Lore", ;

                    if (!nbttaglist3.hasNoTags())
                    {
                        for (int l1 = 0; l1 < nbttaglist3.tagCount(); ++l1)
                        {
                            list.add(TextFormatting.DARK_PURPLE + "" + TextFormatting.ITALIC + nbttaglist3.getStringTagAt(l1));
                        }
                    }
                }
            }
        }

        for (EntityEquipmentSlot entityequipmentslot : EntityEquipmentSlot.values())
        {
            Multimap<String, AttributeModifier> multimap = this.getAttributeModifiers(entityequipmentslot);

            if (!multimap.isEmpty() && (i1 & 2) == 0)
            {
                list.add("");
                list.add(I18n.translateToLocal("item.modifiers." + entityequipmentslot.getName()));

                for (Entry<String, AttributeModifier> entry : multimap.entries())
                {
                    AttributeModifier attributemodifier = (AttributeModifier)entry.getValue();
                    double d0 = attributemodifier.getAmount();
                    boolean flag = false;

                    if (attributemodifier.getID() == Item.ATTACK_DAMAGE_MODIFIER)
                    {
                        d0 = d0 + playerIn.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getBaseValue();
                        d0 = d0 + (double)EnchantmentHelper.getModifierForCreature(this, EnumCreatureAttribute.UNDEFINED);
                        flag = true;
                    }
                    else if (attributemodifier.getID() == Item.ATTACK_SPEED_MODIFIER)
                    {
                        d0 += playerIn.getEntityAttribute(SharedMonsterAttributes.ATTACK_SPEED).getBaseValue();
                        flag = true;
                    }

                    double d1;

                    if (attributemodifier.getOperation() != 1 && attributemodifier.getOperation() != 2)
                    {
                        d1 = d0;
                    }
                    else
                    {
                        d1 = d0 * 100.0D;
                    }

                    if (flag)
                    {
                        list.add(" " + I18n.translateToLocalFormatted("attribute.modifier.equals." + attributemodifier.getOperation(), new Object[] {DECIMALFORMAT.format(d1), I18n.translateToLocal("attribute.name." + (String)entry.getKey())}));
                    }
                    else if (d0 > 0.0D)
                    {
                        list.add(TextFormatting.BLUE + " " + I18n.translateToLocalFormatted("attribute.modifier.plus." + attributemodifier.getOperation(), new Object[] {DECIMALFORMAT.format(d1), I18n.translateToLocal("attribute.name." + (String)entry.getKey())}));
                    }
                    else if (d0 < 0.0D)
                    {
                        d1 = d1 * -1.0D;
                        list.add(TextFormatting.RED + " " + I18n.translateToLocalFormatted("attribute.modifier.take." + attributemodifier.getOperation(), new Object[] {DECIMALFORMAT.format(d1), I18n.translateToLocal("attribute.name." + (String)entry.getKey())}));
                    }
                }
            }
        }

        if (this.hasTagCompound() && this.getTagCompound().getBoolean("Unbreakable") && (i1 & 4) == 0)
        {
            list.add(TextFormatting.BLUE + I18n.translateToLocal("item.unbreakable"));
        }

        if (this.hasTagCompound() && this.stackTagCompound.hasKey("CanDestroy", 9) && (i1 &  == 0)
        {
            NBTTagList nbttaglist1 = this.stackTagCompound.getTagList("CanDestroy", ;

            if (!nbttaglist1.hasNoTags())
            {
                list.add("");
                list.add(TextFormatting.GRAY + I18n.translateToLocal("item.canBreak"));

                for (int j1 = 0; j1 < nbttaglist1.tagCount(); ++j1)
                {
                    Block block = Block.getBlockFromName(nbttaglist1.getStringTagAt(j1));

                    if (block != null)
                    {
                        list.add(TextFormatting.DARK_GRAY + block.getLocalizedName());
                    }
                    else
                    {
                        list.add(TextFormatting.DARK_GRAY + "missingno");
                    }
                }
            }
        }

        if (this.hasTagCompound() && this.stackTagCompound.hasKey("CanPlaceOn", 9) && (i1 & 16) == 0)
        {
            NBTTagList nbttaglist2 = this.stackTagCompound.getTagList("CanPlaceOn", ;

            if (!nbttaglist2.hasNoTags())
            {
                list.add("");
                list.add(TextFormatting.GRAY + I18n.translateToLocal("item.canPlace"));

                for (int k1 = 0; k1 < nbttaglist2.tagCount(); ++k1)
                {
                    Block block1 = Block.getBlockFromName(nbttaglist2.getStringTagAt(k1));

                    if (block1 != null)
                    {
                        list.add(TextFormatting.DARK_GRAY + block1.getLocalizedName());
                    }
                    else
                    {
                        list.add(TextFormatting.DARK_GRAY + "missingno");
                    }
                }
            }
        }

        if (advanced)
        {
            if (this.isItemDamaged())
            {
                list.add(I18n.translateToLocalFormatted("item.durability", new Object[] {Integer.valueOf(this.getMaxDamage() - this.getItemDamage()), Integer.valueOf(this.getMaxDamage())}));
            }

            list.add(TextFormatting.DARK_GRAY + ((ResourceLocation)Item.REGISTRY.getNameForObject(this.item)).toString());

            if (this.hasTagCompound())
            {
                list.add(TextFormatting.DARK_GRAY + I18n.translateToLocalFormatted("item.nbt_tags", new Object[] {Integer.valueOf(this.getTagCompound().getKeySet().size())}));
            }
        }

        net.minecraftforge.event.ForgeEventFactory.onItemTooltip(this, playerIn, list, advanced);
        return list;
    }

    @SideOnly(Side.CLIENT)
    public boolean hasEffect()
    {
        return this.getItem().hasEffect(this);
    }

    public EnumRarity getRarity()
    {
        return this.getItem().getRarity(this);
    }

    /**
     * True if it is a tool and has no enchantments to begin with
     */
    public boolean isItemEnchantable()
    {
        return !this.getItem().isItemTool(this) ? false : !this.isItemEnchanted();
    }

    /**
     * Adds an enchantment with a desired level on the ItemStack.
     */
    public void addEnchantment(Enchantment ench, int level)
    {
        if (this.stackTagCompound == null)
        {
            this.setTagCompound(new NBTTagCompound());
        }

        if (!this.stackTagCompound.hasKey("ench", 9))
        {
            this.stackTagCompound.setTag("ench", new NBTTagList());
        }

        NBTTagList nbttaglist = this.stackTagCompound.getTagList("ench", 10);
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        nbttagcompound.setShort("id", (short)Enchantment.getEnchantmentID(ench));
        nbttagcompound.setShort("lvl", (short)((byte)level));
        nbttaglist.appendTag(nbttagcompound);
    }

    /**
     * True if the item has enchantment data
     */
    public boolean isItemEnchanted()
    {
        return this.stackTagCompound != null && this.stackTagCompound.hasKey("ench", 9) ? !this.stackTagCompound.getTagList("ench", 10).hasNoTags() : false;
    }

    public void setTagInfo(String key, NBTBase value)
    {
        if (this.stackTagCompound == null)
        {
            this.setTagCompound(new NBTTagCompound());
        }

        this.stackTagCompound.setTag(key, value);
    }

    public boolean canEditBlocks()
    {
        return this.getItem().canItemEditBlocks();
    }

    /**
     * Return whether this stack is on an item frame.
     */
    public boolean isOnItemFrame()
    {
        return this.itemFrame != null;
    }

    /**
     * Set the item frame this stack is on.
     */
    public void setItemFrame(EntityItemFrame frame)
    {
        this.itemFrame = frame;
    }

    /**
     * Return the item frame this stack is on. Returns null if not on an item frame.
     */
    @Nullable
    public EntityItemFrame getItemFrame()
    {
        return this.field_190928_g ? null : this.itemFrame;
    }

    /**
     * Get this stack's repair cost, or 0 if no repair cost is defined.
     */
    public int getRepairCost()
    {
        return this.hasTagCompound() && this.stackTagCompound.hasKey("RepairCost", 3) ? this.stackTagCompound.getInteger("RepairCost") : 0;
    }

    /**
     * Set this stack's repair cost.
     */
    public void setRepairCost(int cost)
    {
        if (!this.hasTagCompound())
        {
            this.stackTagCompound = new NBTTagCompound();
        }

        this.stackTagCompound.setInteger("RepairCost", cost);
    }

    public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot equipmentSlot)
    {
        Multimap<String, AttributeModifier> multimap;

        if (this.hasTagCompound() && this.stackTagCompound.hasKey("AttributeModifiers", 9))
        {
            multimap = HashMultimap.<String, AttributeModifier>create();
            NBTTagList nbttaglist = this.stackTagCompound.getTagList("AttributeModifiers", 10);

            for (int i = 0; i < nbttaglist.tagCount(); ++i)
            {
                NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
                AttributeModifier attributemodifier = SharedMonsterAttributes.readAttributeModifierFromNBT(nbttagcompound);

                if (attributemodifier != null && (!nbttagcompound.hasKey("Slot",  || nbttagcompound.getString("Slot").equals(equipmentSlot.getName())) && attributemodifier.getID().getLeastSignificantBits() != 0L && attributemodifier.getID().getMostSignificantBits() != 0L)
                {
                    multimap.put(nbttagcompound.getString("AttributeName"), attributemodifier);
                }
            }
        }
        else
        {
            multimap = this.getItem().getAttributeModifiers(equipmentSlot, this);
        }

        return multimap;
    }

    public void addAttributeModifier(String attributeName, AttributeModifier modifier, @Nullable EntityEquipmentSlot equipmentSlot)
    {
        if (this.stackTagCompound == null)
        {
            this.stackTagCompound = new NBTTagCompound();
        }

        if (!this.stackTagCompound.hasKey("AttributeModifiers", 9))
        {
            this.stackTagCompound.setTag("AttributeModifiers", new NBTTagList());
        }

        NBTTagList nbttaglist = this.stackTagCompound.getTagList("AttributeModifiers", 10);
        NBTTagCompound nbttagcompound = SharedMonsterAttributes.writeAttributeModifierToNBT(modifier);
        nbttagcompound.setString("AttributeName", attributeName);

        if (equipmentSlot != null)
        {
            nbttagcompound.setString("Slot", equipmentSlot.getName());
        }

        nbttaglist.appendTag(nbttagcompound);
    }

    /**
     * Get a ChatComponent for this Item's display name that shows this Item on hover
     */
    public ITextComponent getTextComponent()
    {
        TextComponentString textcomponentstring = new TextComponentString(this.getDisplayName());

        if (this.hasDisplayName())
        {
            textcomponentstring.getStyle().setItalic(Boolean.valueOf(true));
        }

        ITextComponent itextcomponent = (new TextComponentString("[")).appendSibling(textcomponentstring).appendText("]");

        if (!this.field_190928_g)
        {
            NBTTagCompound nbttagcompound = this.writeToNBT(new NBTTagCompound());
            itextcomponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new TextComponentString(nbttagcompound.toString())));
            itextcomponent.getStyle().setColor(this.getRarity().rarityColor);
        }

        return itextcomponent;
    }

    public boolean canDestroy(Block blockIn)
    {
        if (blockIn == this.canDestroyCacheBlock)
        {
            return this.canDestroyCacheResult;
        }
        else
        {
            this.canDestroyCacheBlock = blockIn;

            if (this.hasTagCompound() && this.stackTagCompound.hasKey("CanDestroy", 9))
            {
                NBTTagList nbttaglist = this.stackTagCompound.getTagList("CanDestroy", ;

                for (int i = 0; i < nbttaglist.tagCount(); ++i)
                {
                    Block block = Block.getBlockFromName(nbttaglist.getStringTagAt(i));

                    if (block == blockIn)
                    {
                        this.canDestroyCacheResult = true;
                        return true;
                    }
                }
            }

            this.canDestroyCacheResult = false;
            return false;
        }
    }

    public boolean canPlaceOn(Block blockIn)
    {
        if (blockIn == this.canPlaceOnCacheBlock)
        {
            return this.canPlaceOnCacheResult;
        }
        else
        {
            this.canPlaceOnCacheBlock = blockIn;

            if (this.hasTagCompound() && this.stackTagCompound.hasKey("CanPlaceOn", 9))
            {
                NBTTagList nbttaglist = this.stackTagCompound.getTagList("CanPlaceOn", ;

                for (int i = 0; i < nbttaglist.tagCount(); ++i)
                {
                    Block block = Block.getBlockFromName(nbttaglist.getStringTagAt(i));

                    if (block == blockIn)
                    {
                        this.canPlaceOnCacheResult = true;
                        return true;
                    }
                }
            }

            this.canPlaceOnCacheResult = false;
            return false;
        }
    }

    public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing)
    {
        return this.capabilities == null ? false : this.capabilities.hasCapability(capability, facing);
    }

    public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
    {
        return this.capabilities == null ? null : this.capabilities.getCapability(capability, facing);
    }

    public void deserializeNBT(NBTTagCompound nbt)
    {
        // TODO do this better while respecting new rules
        final ItemStack itemStack = new ItemStack(nbt);
        this.stackTagCompound = itemStack.stackTagCompound;
        this.capNBT = itemStack.capNBT;
    }

    public NBTTagCompound serializeNBT()
    {
        NBTTagCompound ret = new NBTTagCompound();
        this.writeToNBT(ret);
        return ret;
    }

    public boolean areCapsCompatible(ItemStack other)
    {
        if (this.capabilities == null)
        {
            if (other.capabilities == null)
            {
                return true;
            }
            else
            {
                return other.capabilities.areCompatible(null);
            }
        }
        else
        {
            return this.capabilities.areCompatible(other.capabilities);
        }
    }

    @SideOnly(Side.CLIENT)
    public int func_190921_D()
    {
        return this.animationsToGo;
    }

    public void func_190915_d(int p_190915_1_)
    {
        this.animationsToGo = p_190915_1_;
    }

    public int func_190916_E()
    {
        return this.field_190928_g ? 0 : this.stackSize;
    }

    public void func_190920_e(int p_190920_1_)
    {
        this.stackSize = p_190920_1_;
        this.func_190923_F();
    }

    public void func_190917_f(int p_190917_1_)
    {
        this.func_190920_e(this.stackSize + p_190917_1_);
    }

    public void func_190918_g(int p_190918_1_)
    {
        this.func_190917_f(-p_190918_1_);
    }
}

 

Here is the constructor method of ItemStack that is called

public ItemStack(Item itemIn, int amount)
    {
        this((Item)itemIn, amount, 0);
    }

Link to comment
Share on other sites

I did not need the ItemStack class, I will however need your ModItems class.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

here is my ModItems class

package com.exline.sushimod;

import com.exline.sushimod.items.FoodBase;
import com.exline.sushimod.items.ItemBase;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ModItems 
{
//declare item here	
public static FoodBase cucumber;
public static FoodBase rice;
public static FoodBase riceball;
public static FoodBase nori;

public static FoodBase fishroll;
public static FoodBase salmonroll;
public static FoodBase pufferfishroll;
public static FoodBase cucumberroll;
public static FoodBase mushroomroll;
public static FoodBase clownfishroll;
public static FoodBase rainbowroll;

public static FoodBase sashimi;
public static FoodBase salmonsashimi;
public static FoodBase clownfishsashimi;

public static void init() 
{
	cucumber = register(new FoodBase("cucumber", 1).setCreativeTab(CreativeTabs.FOOD));
	rice = register(new FoodBase("rice", 1).setCreativeTab(CreativeTabs.FOOD));
	riceball = register(new FoodBase("riceball", 4).setCreativeTab(CreativeTabs.FOOD));
	nori = register(new FoodBase("nori", 1).setCreativeTab(CreativeTabs.FOOD));

	fishroll = register(new FoodBase("fishroll", 10).setCreativeTab(CreativeTabs.FOOD));
	salmonroll = register(new FoodBase("salmonroll", 10).setCreativeTab(CreativeTabs.FOOD));
	pufferfishroll = register(new FoodBase("pufferfishroll", 14).setCreativeTab(CreativeTabs.FOOD));
	cucumberroll = register(new FoodBase("cucumberroll", 6).setCreativeTab(CreativeTabs.FOOD));
	mushroomroll = register(new FoodBase("mushroomroll", .setCreativeTab(CreativeTabs.FOOD));
	clownfishroll = register(new FoodBase("clownfishroll", 10).setCreativeTab(CreativeTabs.FOOD));
	rainbowroll = register(new FoodBase("rainbowroll", 18).setCreativeTab(CreativeTabs.FOOD));

	sashimi = register(new FoodBase("sashimi", 6).setCreativeTab(CreativeTabs.FOOD));
	clownfishsashimi = register(new FoodBase("clownfishsashimi", .setCreativeTab(CreativeTabs.FOOD));
	salmonsashimi = register(new FoodBase("salmonsashimi", 6).setCreativeTab(CreativeTabs.FOOD));
}

private static <T extends Item> T register(T item) 
{
	GameRegistry.register(item);

	if (item instanceof ItemModelProvider) 
	{
		((FoodBase)item).registerItemModel(item);
	}

	return item;
}
}

 

and in case you need it here is FoodBase as well

package com.exline.sushimod.items;

import com.exline.sushimod.ItemModelProvider;
import com.exline.sushimod.SushiMod;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;

public class FoodBase extends ItemFood implements ItemModelProvider
{
protected String name;

public FoodBase(String name, int hunger) 
{
	super(hunger, 0.6f, false);
	this.name = name;
	setUnlocalizedName(name);
	setRegistryName(name);
}

@Override
public void registerItemModel(Item item) 
{
	SushiMod.proxy.registerItemRenderer(this, 0, name);
}

@Override
public FoodBase setCreativeTab(CreativeTabs tab) 
{
	super.setCreativeTab(tab);
	return this;
}

}

Link to comment
Share on other sites

So, none of this relates to your problem, but they're more general "you haven't broken it yet, but it could in the future" sort of things.

1) I would make all of the static FoodBase fields static Item fields. There's no reason to keep them more specific.

2) This:

		if (item instanceof ItemModelProvider) 
	{
		((FoodBase)item).registerItemModel(item);
	}

Don't case to FoodBase, you didn't check to see if the item was FoodBase, you checked to see if it was ItemModelProvider.  Cast to that.  Yes, you can still invoke registerItemModel, as the interface has that method declared.

3) Not sure why you pass the item back to it, and then not use it though (instead you use

this

which would be the same object, so...why?)

4) Why did you define the setCreativeTab method? Isn't one already supplied by the Item class?  Why did you change the return type?  Why do you call this post-constructor, when you call setRegistryName and setUnlocalizedName in the constructor (which also

return this

)?

5) Don't use

protected String name;

the only place you use it is for the item model, which you should be using .getRegistryName() for anyway

 

Anyway, I can't see what's wrong. Looks like something might going sour inside ShapelessRecipes#getRemainingItems that isn't your fault.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Hey! Thanks for the help, sorry i didnt reply earlier. I updated forge and all is well! Also thanks again for the advice. I dont know why i was using all those references to FoodBase instead of just Item. I simplified my code a bit and it works perfect now. I was also thinking of posting the complete source code somewhere on the forum sometime. Thanks again!

 

Oh, and I got rid of the setCreativeTabs for the food items. I should have figured it would be there since it expands the FoodItem anyway, I was just used to setting it for other items. I was following a few different tutorials and they both had different ways of doing things so I definitely have some code that I could go without.

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.

Announcements



×
×
  • Create New...

Important Information

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