Posted September 28, 201411 yr Hello everyone: I am having problems with adding and getting NBT tags off of a custom item. When a BlockOre drops this item, a HarvestDropsEvent is fired: @SubscribeEvent public void GetCorrectOreDrops(HarvestDropsEvent event) { if (event.block instanceof BlockOre) { //STOP NOW if Block is being silk touched if (event.isSilkTouching) { event.drops.clear(); event.drops.add(Stack.S(event.block)); } int nuggets = (event.world.rand.nextInt(16) + event.fortuneLevel * event.world.rand.nextInt(5) + 1); ItemStack stack = event.drops.get(0); stack = ORef.lumpOre.addOre((BlockOre) event.block, nuggets, stack); event.drops.set(0, stack); event.dropChance = 1.0F; } } This refers to a NBT adding script in the item (addOre): public ItemStack addOre(BlockOre ore, int nuggets, ItemStack stack) { NBTTagList taglist = (stack.stackTagCompound != null && stack.stackTagCompound.hasKey("Ores")) ? (NBTTagList) stack.stackTagCompound.getTag("BiggerDim") : new NBTTagList(); NBTTagCompound tag = new NBTTagCompound(); tag.setInteger("nuggets", nuggets); tag.setInteger("ore", ore.getIdFromBlock(ore)); taglist.appendTag(tag); System.out.println(tag.getInteger("ore")); stack.stackTagCompound.setTag("Ores", taglist); return stack; } Whenever I harvest the block, the game crashes. What am I missing?
September 28, 201411 yr This helped me understand NBT greatly " But the issue is you are forgetting to check to see if the itemstack has a NBTTagCompound if (itemStack.stackTagCompound == null) { itemStack.setTagCompound(new NBTTagCompound()); } you are probably getting a crash of something being null right? Watch the video and all will be revealed to you. (also the posted code snippet is how you make sure not to get a crash trying to add to a null object) Currently updating my Mod to 1.10.2 https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master
October 2, 201411 yr Author The actual crash comes from a ticking memory connection with a whole bunch of forge/minecraft code, but it is caused by a null pointer in stack.stackTagCompound.setTag("Ores", taglist); in the second code bit.
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.