Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I started to touch NBT and particles, I wanted to have a notebook that randomly got knawlidge (and If I didn't, increased the chances to get knawlidge ) while carrying it in my inventory.

 

If i got knowledge, the next time I would of hold it in my hand it would create particles at my head (I chose enchantement table particles idk y lol XDDDDDDDDDDDDDDDD) and if it was in my hand when I got knowledge it would create the particles at my head.

 

I got an issue though. I can't use or even put my inventory because the item class explodes all teh time...

 

My ItemNoteBook

package mod.TGC1.SoulCraft.Customs.Items;

import java.util.Random;

import mod.TGC1.SoulCraft.init.ModItems;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ItemNoteBook extends Item 
{

public ItemNoteBook()
{
	this.setUnlocalizedName("NoteBook");
	this.setRegistryName("NoteBook");
	this.setCreativeTab(new CreativeTabs("Soul Craft"){
        @SideOnly(Side.CLIENT)
        public Item getTabIconItem()
        {
            return ModItems.NoteBook;
        }
    });
}
@Override
public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn)
{
	NBTTagCompound nbt = new NBTTagCompound();
	nbt.setInteger("knawlidge", 0);
	nbt.setInteger("knaw%", 0);
	nbt.setBoolean("WillSparkle", false);
	if(stack.hasTagCompound() || stack.getTagCompound() == null) stack.setTagCompound(nbt);
}

@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
    {
	int knowledge = 0;
	int knowP = 0;
	NBTTagCompound nbt = stack.getTagCompound(); 
	if(nbt.hasKey("knawlidge") && nbt.hasKey("knaw%")) //Error starts here....
	{
		knowledge = nbt.getInteger("knawlidge");
		knowP = nbt.getInteger("knaw%");
	}
	Random Value = worldIn.rand;
	boolean IsLearning = (Value.nextInt(51) + knowP) >= 100;
	if(IsLearning)
	{
		if(isSelected) 
		{
			worldIn.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, entityIn.posX, entityIn.posY + 1, entityIn.posZ, 0.0, 0.0, 0.0, 1);
			nbt.setBoolean("WillSparkle", false);
		}else
		{
			nbt.setBoolean("WillSparkle", true);
		}
		nbt.setInteger("knawlidge", knowledge + 1);
	}else
	{
		nbt.setInteger("knaw%", knowP + Value.nextInt(11));
	}
    }

}

When they say your code doesn't follow convention but ur edgy so u dont care

d-d-d-dab on them haterz

 

  • Author

The error would be helpful, they're thrown for a reason.

 

If you did had psychic I would of probably asked how I can get some XDDDDDDDD. completely forgot

 

---- Minecraft Crash Report ----
// Oh - I know what I did wrong!

Time: 04/06/16 1:10 AM
Description: Ticking entity

java.lang.NullPointerException: Ticking entity
at mod.TGC1.SoulCraft.Customs.Items.ItemNoteBook.onUpdate(ItemNoteBook.java:49)
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:502)
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:350)
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:611)
at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:912)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1824)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:323)
at net.minecraft.client.entity.EntityPlayerSP.onUpdate(EntityPlayerSP.java:163)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2011)
at net.minecraft.world.World.updateEntity(World.java:1976)
at net.minecraft.world.World.updateEntities(World.java:1805)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2176)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1080)
at net.minecraft.client.Minecraft.run(Minecraft.java:380)
at net.minecraft.client.main.Main.main(Main.java:116)
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 --
Stacktrace:
at mod.TGC1.SoulCraft.Customs.Items.ItemNoteBook.onUpdate(ItemNoteBook.java:49)
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:502)
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:350)
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:611)
at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:912)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1824)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:323)
at net.minecraft.client.entity.EntityPlayerSP.onUpdate(EntityPlayerSP.java:163)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2011)
at net.minecraft.world.World.updateEntity(World.java:1976)

-- Entity being ticked --
Details:
Entity Type: null (net.minecraft.client.entity.EntityPlayerSP)
Entity ID: 126
Entity Name: Player915
Entity's Exact location: 1158.25, 4.00, -1034.20
Entity's Block location: 1158.00,4.00,-1035.00 - World: (1158,4,-1035), Chunk: (at 6,0,5 in 72,-65; contains blocks 1152,0,-1040 to 1167,255,-1025), Region: (2,-3; contains chunks 64,-96 to 95,-65, blocks 1024,0,-1536 to 1535,255,-1025)
Entity's Momentum: 0.00, 0.00, 0.00
Entity's Rider: ~~ERROR~~ NullPointerException: null
Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
at net.minecraft.world.World.updateEntities(World.java:1805)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityPlayerSP['Player915'/126, l='MpServer', x=1158.25, y=4.00, z=-1034.20]]
Chunk stats: MultiplayerChunkCache: 621, 621
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: 1162.00,4.00,-1026.00 - World: (1162,4,-1026), Chunk: (at 10,0,14 in 72,-65; contains blocks 1152,0,-1040 to 1167,255,-1025), Region: (2,-3; contains chunks 64,-96 to 95,-65, blocks 1024,0,-1536 to 1535,255,-1025)
Level time: 2084 game time, 2084 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: 64 total; [EntitySlime['Slime'/18, l='MpServer', x=1087.00, y=4.47, z=-991.22], EntitySlime['Slime'/19, l='MpServer', x=1087.25, y=4.00, z=-979.50], EntitySlime['Slime'/24, l='MpServer', x=1080.78, y=4.00, z=-1113.94], EntitySlime['Slime'/25, l='MpServer', x=1095.16, y=4.00, z=-1096.69], EntitySlime['Slime'/26, l='MpServer', x=1095.19, y=5.22, z=-1090.34], EntitySlime['Slime'/27, l='MpServer', x=1094.50, y=4.00, z=-1088.19], EntitySlime['Slime'/28, l='MpServer', x=1091.03, y=4.00, z=-1070.34], EntitySlime['Slime'/29, l='MpServer', x=1107.97, y=4.75, z=-1087.19], EntitySlime['Slime'/30, l='MpServer', x=1095.53, y=4.00, z=-1076.91], EntitySlime['Slime'/31, l='MpServer', x=1093.38, y=4.00, z=-1003.66], EntitySlime['Slime'/32, l='MpServer', x=1092.91, y=4.47, z=-972.91], EntityCow['Cow'/38, l='MpServer', x=1108.31, y=4.00, z=-1114.25], EntityCow['Cow'/41, l='MpServer', x=1106.53, y=4.00, z=-1089.38], EntityCow['Cow'/42, l='MpServer', x=1110.22, y=4.00, z=-1089.50], EntityCow['Cow'/43, l='MpServer', x=1111.47, y=4.00, z=-1088.41], EntityCow['Cow'/44, l='MpServer', x=1106.09, y=4.00, z=-1092.00], EntitySlime['Slime'/45, l='MpServer', x=1112.41, y=4.00, z=-1094.97], EntityCow['Cow'/46, l='MpServer', x=1111.75, y=4.00, z=-1087.28], EntityCow['Cow'/47, l='MpServer', x=1108.00, y=4.00, z=-1094.97], EntityCow['Cow'/48, l='MpServer', x=1115.81, y=4.00, z=-1082.22], EntityCow['Cow'/49, l='MpServer', x=1108.50, y=4.00, z=-1085.50], EntityCow['Cow'/50, l='MpServer', x=1109.03, y=4.00, z=-1080.16], EntityCow['Cow'/51, l='MpServer', x=1097.53, y=4.00, z=-1073.78], EntitySlime['Slime'/52, l='MpServer', x=1114.81, y=4.00, z=-1071.63], EntitySlime['Slime'/53, l='MpServer', x=1116.09, y=4.00, z=-1035.59], EntitySlime['Slime'/54, l='MpServer', x=1115.13, y=5.22, z=-1020.88], EntitySlime['Slime'/55, l='MpServer', x=1105.94, y=4.00, z=-997.44], EntitySlime['Slime'/56, l='MpServer', x=1121.28, y=4.00, z=-989.94], EntitySlime['Slime'/57, l='MpServer', x=1118.75, y=4.00, z=-961.69], EntitySlime['Slime'/58, l='MpServer', x=1114.50, y=4.00, z=-962.03], EntitySlime['Slime'/59, l='MpServer', x=1126.63, y=5.22, z=-955.28], EntityRabbit['Rabbit'/60, l='MpServer', x=1130.53, y=4.00, z=-1073.94], EntityPig['Pig'/61, l='MpServer', x=1126.78, y=4.00, z=-1074.91], EntityCow['Cow'/62, l='MpServer', x=1126.72, y=4.00, z=-1080.38], EntityPig['Pig'/63, l='MpServer', x=1135.72, y=4.00, z=-1072.22], EntitySheep['Sheep'/64, l='MpServer', x=1126.81, y=4.00, z=-1078.81], EntityPig['Pig'/65, l='MpServer', x=1133.41, y=4.00, z=-1070.00], EntityPig['Pig'/66, l='MpServer', x=1115.03, y=4.00, z=-1067.03], EntityRabbit['Rabbit'/67, l='MpServer', x=1127.31, y=4.00, z=-1067.34], EntityRabbit['Rabbit'/68, l='MpServer', x=1132.47, y=4.00, z=-1070.84], EntityRabbit['Rabbit'/69, l='MpServer', x=1134.56, y=4.00, z=-1070.41], EntitySheep['Sheep'/70, l='MpServer', x=1133.00, y=4.00, z=-1062.06], EntitySlime['Slime'/71, l='MpServer', x=1124.94, y=4.00, z=-1017.03], EntitySlime['Slime'/72, l='MpServer', x=1132.34, y=4.00, z=-1012.81], EntitySlime['Slime'/73, l='MpServer', x=1116.72, y=4.00, z=-1011.13], EntitySlime['Slime'/74, l='MpServer', x=1129.44, y=4.00, z=-998.31], EntitySlime['Slime'/75, l='MpServer', x=1124.84, y=4.00, z=-993.94], EntitySlime['Slime'/76, l='MpServer', x=1140.81, y=4.78, z=-989.09], EntitySlime['Slime'/77, l='MpServer', x=1131.84, y=4.00, z=-987.25], EntitySlime['Slime'/78, l='MpServer', x=1130.19, y=5.00, z=-975.09], EntitySheep['Sheep'/83, l='MpServer', x=1141.16, y=4.00, z=-1062.19], EntitySlime['Slime'/84, l='MpServer', x=1129.81, y=4.00, z=-1011.41], EntitySlime['Slime'/85, l='MpServer', x=1145.81, y=4.41, z=-975.41], EntitySlime['Slime'/86, l='MpServer', x=1152.13, y=4.00, z=-1082.16], EntitySlime['Slime'/87, l='MpServer', x=1171.44, y=4.00, z=-995.72], EntitySlime['Slime'/89, l='MpServer', x=1170.53, y=4.00, z=-1109.47], EntitySlime['Slime'/90, l='MpServer', x=1177.06, y=5.22, z=-1100.44], EntitySlime['Slime'/91, l='MpServer', x=1180.66, y=4.78, z=-1005.25], EntitySlime['Slime'/92, l='MpServer', x=1170.53, y=5.16, z=-997.63], EntitySlime['Slime'/94, l='MpServer', x=1189.16, y=5.22, z=-1112.53], EntityPlayerSP['Player915'/126, l='MpServer', x=1158.25, y=4.00, z=-1034.20], EntitySlime['Slime'/95, l='MpServer', x=1182.97, y=4.00, z=-1100.25], EntitySlime['Slime'/107, l='MpServer', x=1187.75, y=4.75, z=-1099.25], EntitySlime['Slime'/108, l='MpServer', x=1230.88, y=5.00, z=-1047.03]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:383)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2645)
at net.minecraft.client.Minecraft.run(Minecraft.java:401)
at net.minecraft.client.main.Main.main(Main.java:116)
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)

When they say your code doesn't follow convention but ur edgy so u dont care

d-d-d-dab on them haterz

 

Item#onCreated() is only called when the item is crafted or smelted, so the stackTagCompund is be null if you obtain the item any other way.

@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
{
	NBTTagCompound nbt = stack.getTagCompound();
	if (nbt == null)
	{
		nbt = new NBTTagCompound();
		stack.setTagCompound(nbt);
	}

	int knowledge = nbt.getInteger("KL");
	int knowP = nbt.getInteger("KLP"); // This is percent, use byte, unless you need to surpass 100.
	boolean isLearning = worldIn.rand.nextInt(51) + knowP >= 100;

	if (isLearning)
	{
		if (isSelected)
		{
			worldIn.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, entityIn.posX, entityIn.posY + 1, entityIn.posZ, 0.0, 0.0, 0.0, 1);
			nbt.setBoolean("S", false);
		}
		else
		{
			nbt.setBoolean("S", true);
		}
		nbt.setInteger("KL", knowledge + 1);
	}
	else
	{
		nbt.setInteger("KLP", knowP + worldIn.rand.nextInt(11)); // This will reach 100 very fast.
	}
}

 

Remove #onCreated. It's useless.

1.7.10 is no longer supported by forge, you are on your own.

If you did had psychic I would of probably asked how I can get some XDDDDDDDD. completely forgot

 

You left out the actual exception. Next time post the whole crash report.

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.

  • Author

If you did had psychic I would of probably asked how I can get some XDDDDDDDD. completely forgot

 

You left out the actual exception. Next time post the whole crash report.

 

edited, sowy.

When they say your code doesn't follow convention but ur edgy so u dont care

d-d-d-dab on them haterz

 

Note that

1. There is ItemStack#hasTagCompound() to check if the itemstack has data.

2. It seems that Capability system for Item will fit in this case greatly. Have a look at it.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

 
this.setCreativeTab(new CreativeTabs("Soul Craft"){
        @SideOnly(Side.CLIENT)
        public Item getTabIconItem()
        {
            return ModItems.NoteBook;
        }
    });

 

Don't do that. Make the creative tab somewhere else like a ModTabs class and then reference it. The same way you reference ModItems.NoteBook

  • Author

 
this.setCreativeTab(new CreativeTabs("Soul Craft"){
        @SideOnly(Side.CLIENT)
        public Item getTabIconItem()
        {
            return ModItems.NoteBook;
        }
    });

 

Don't do that. Make the creative tab somewhere else like a ModTabs class and then reference it. The same way you reference ModItems.NoteBook

 

It was temporary until I make it work. Since it was my only item and block in the mod

 

Regardless, This doesn't help the actual issue boo boo. Thanks anyway  ;D

When they say your code doesn't follow convention but ur edgy so u dont care

d-d-d-dab on them haterz

 

  • Author

Remove #onCreated. It's useless.

 

It will be used in the future because there will be other properties that will require #onCreated specifically.

 

This, too, doesn't help the crash. Thanks anyway :)

When they say your code doesn't follow convention but ur edgy so u dont care

d-d-d-dab on them haterz

 

  • Author

Item#onCreated() is only called when the item is crafted or smelted, so the stackTagCompund is be null if you obtain the item any other way.

 

This woudn't prevent crashing (since it would just not go in the if statement, thus keeping both values to 0), but it did escaped my mind.

 

Thanks.

 

 

When they say your code doesn't follow convention but ur edgy so u dont care

d-d-d-dab on them haterz

 

Remove #onCreated. It's useless.

 

It will be used in the future because there will be other properties that will require #onCreated specifically.

 

This, too, doesn't help the crash. Thanks anyway :)

 

Then you have done something horribly wrong. The provided code should work.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.