Jump to content

[1.8] Item use exception?


deadrecon98

Recommended Posts

I don't even know what's causing this one. It happens whenever I right click an item that I created.

 

Note: It works perfectly the first two times I use it but on the third one it crashes. Also this only seems to pertain to the Skin type.

 

Error

14:22:29] [server thread/FATAL] [FML]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.NullPointerException
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.7.0_79]
at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.7.0_79]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:715) [FMLCommonHandler.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:727) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.7.0_79]
Caused by: java.lang.NullPointerException
at net.minecraft.server.management.ItemInWorldManager.tryUseItem(ItemInWorldManager.java:398) ~[itemInWorldManager.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:607) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:67) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:114) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:24) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.7.0_79]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.7.0_79]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:714) ~[FMLCommonHandler.class:?]

 

Item Class

@Override
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn){
	if (!worldIn.isRemote){
		if(!playerIn.capabilities.isCreativeMode){
			if(PackManager.crackPack(playerIn, type)){
				itemStackIn.stackSize --;
				return null;
			}else{
				playerIn.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "You are out of inventory space!"));
			}
		}else{
			playerIn.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "You must be in survival mode to use this!"));
		}
	}
	return itemStackIn;
}

 

More code that might be helpful.

/**
 * Opens a trail pack for the player.
 * @param player
 */
public static boolean crackPack(EntityPlayer player, EnumPackType type){
	if(!player.worldObj.isRemote){
		switch(type){
		default:
			logger.error("Invalid pack type for type " + type + "!");
			return false;
		case Trail:
			if(player.inventory.hasItem(ItemManager.trailPack)){
				Trail trail = TrailManager.getRandomTrail();

				ItemStack is = new ItemStack(ItemManager.openedTrailPack, 1);
				NBTTagCompound tag = new NBTTagCompound();
				is.setTagCompound(tag);
				tag.setString("Type", EnumPackType.Trail.toString());
				tag.setString("Trail", trail.getName());
				is.setStackDisplayName("" + EnumAppRarity.getColorFromTrail(trail) + trail.getRarity() + EnumChatFormatting.AQUA + " Trail Pack");

				if(player.inventory.addItemStackToInventory(is)){
					player.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "You have cracked a " + EnumAppRarity.getColorFromTrail(trail) + trail.getRarity() + EnumChatFormatting.AQUA + " Trail of " + EnumAppRarity.getColorFromTrail(trail) + trail.getName() + "!"));
					if(trail.getRarity() == EnumAppRarity.Mythic){
						PacketManager.sendPacketToAll(new PacketChatMessage(EnumChatFormatting.GOLD + player.getName() + " just cracked a " + EnumAppRarity.getColorFromTrail(trail) + trail.getRarity() + EnumChatFormatting.GOLD + " Trail of " + EnumAppRarity.getColorFromTrail(trail) + trail.getName() + "!"));
					}
					return true;
				}else{
					return false;
				}
			}
			break;
		case Skin:
			if(player.inventory.hasItem(ItemManager.skinPack)){
				Skin skin = SkinManager.getRandomSkin();

				ItemStack is = new ItemStack(ItemManager.openedSkinPack, 1);
				NBTTagCompound tag = new NBTTagCompound();
				is.setTagCompound(tag);
				tag.setString("Type", EnumPackType.Skin.toString());
				tag.setString("Skin", skin.getName());
				is.setStackDisplayName("" + EnumAppRarity.getColorFromRarity(skin.getRarity()) + skin.getRarity() + EnumChatFormatting.AQUA + " Skin Pack");

				if(player.inventory.addItemStackToInventory(is)){
					player.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + "You have cracked a " + EnumAppRarity.getColorFromRarity(skin.getRarity()) + skin.getRarity() + EnumChatFormatting.AQUA + " Skin of " + EnumAppRarity.getColorFromRarity(skin.getRarity()) + skin.getName() + "!"));
					if(skin.getRarity() == EnumAppRarity.Mythic){
						PacketManager.sendPacketToAll(new PacketChatMessage(EnumChatFormatting.GOLD + player.getName() + " just cracked a " + EnumAppRarity.getColorFromRarity(skin.getRarity()) + skin.getRarity() + EnumChatFormatting.GOLD + " Skin of " + EnumAppRarity.getColorFromRarity(skin.getRarity()) + skin.getName() + "!"));
					}
					return true;
				}else{
					return false;
				}
			}
			break;
		}

	}
	return false;
}

Link to comment
Share on other sites

I think the error is caused by returning null from

Item#onItemRightClick

.

ItemInWorldManager#tryUseItem

expects a non-null

ItemStack

to be returned, even if its

stackSize

is 0 (which it explicitly checks for).

 

Oddly enough, it does check if the returned

ItemStack

is null; but only after checking that the returned

ItemStack

is equal to the original

ItemStack

(which can't possibly be null at that point).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I think the error is caused by returning null from

Item#onItemRightClick

.

ItemInWorldManager#tryUseItem

expects a non-null

ItemStack

to be returned, even if its

stackSize

is 0 (which it explicitly checks for).

 

Oddly enough, it does check if the returned

ItemStack

is null; but only after checking that the returned

ItemStack

is equal to the original

ItemStack

(which can't possibly be null at that point).

 

If I don't return null then for whatever ungodly reason is it starts to give me negative item stack sizes.

 

EDIT: Just for testing purposes I made it return the itemstack regardless but the error is still happening.

EDIT EDIT: Well I take back my last edit, I see your reasoning so I made it return the itemstack and now it crashes without any errors.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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