Posted August 24, 20196 yr Hello, so I am trying to make an item lock that prevents you from dropping items so you don't accidentally lose them. I save NBT data to it, but I have a problem. If I try to save data to a block I've already made, which saves the NBT when you break it and shows it in the tooltip, it gives a null pointer exception. Add information and getItemCount methods in my block class: @Override public void addInformation(ItemStack itemstack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { tooltip.add("Makes cobblestone and compressed cobblestone with upgrades at a stack per tick. Uses LOADS of power when upgraded."); tooltip.add("Will auto-eject items."); NBTTagCompound tagCompound = itemstack.getTagCompound(); if (tagCompound != null) { int energy = tagCompound.getInteger("energy"); //Crashing Line int sizeIn = getItemCount(tagCompound, "itemsIn"); int sizeOut = getItemCount(tagCompound, "itemsOut"); String translated = I18n.format("message.tm.cobble_generator", energy, sizeIn, sizeOut); translated = COMPILE.matcher(translated).replaceAll("\u00a7"); Collections.addAll(tooltip, StringUtils.split(translated, "\n")); } } private int getItemCount(NBTTagCompound tagCompound, String itemsIn2) { int sizeIn = 0; NBTTagCompound compoundIn = (NBTTagCompound) tagCompound.getTag(itemsIn2); //Crashing line NBTTagList itemsIn = compoundIn.getTagList("Items", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < itemsIn.tagCount(); i++) { NBTTagCompound itemTags = itemsIn.getCompoundTagAt(i); if (!new ItemStack(itemTags).isEmpty()) { sizeIn++; } } return sizeIn; } I think this is because of the "NBTTagCompound tagCompound = itemstack.getTagCompound();" line which gets all the NBT data, including the locking NBT boolean. Is there anything I can do to fix this? Note: This is a duplicate because I posted this in the wrong place. Sorry. Edited August 24, 20196 yr by TesterTesting135 Solved
August 24, 20196 yr tagCompound.getTag(itemsIn2); This is returning null. So your sub compound does not exist. Make sure you got all the keys right https://github.com/CAS-ual-TY/Visibilis [1.14] How to Villagers, Trades, Professions, Fix Trades https://minecraft.curseforge.com/projects/gun-customization-infinity / https://github.com/CAS-ual-TY/GunCus https://minecraft.curseforge.com/projects/ygo-dueling-mod https://minecraft.curseforge.com/projects/mundus-magicus https://minecraft.curseforge.com/projects/deuf-duplicate-entity-uuid-fix
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.