Posted November 6, 20195 yr I have an block that stores its content when broken via the loot table functions, like this: Spoiler { "type": "minecraft:block", "pools": [ { "name":"pool1", "rolls": 1, "entries": [ { "type": "minecraft:item", "functions": [ { "function": "minecraft:copy_name", "source": "block_entity" }, { "function": "minecraft:copy_nbt", "source": "block_entity", "ops": [ { "source": "inv", "target": "BlockEntityTag.inv", "op": "replace" } ] }, { "function": "minecraft:set_contents", "entries": [ { "type": "minecraft:dynamic", "name": "minecraft:contents" } ] } ], "name": "bedres:ritual_pedestal" } ], "conditions": [ { "condition": "minecraft:survives_explosion" } ] } ] } im not sure how to acces that information from the ItemStack#addInformation method, at the moment i have this in my tile, which all works, breaking and placing stays with the same item and variable values: Spoiler @Override public void read(CompoundNBT tag) { CompoundNBT compound = tag.getCompound("inv"); handler.ifPresent(h -> { ((INBTSerializable<CompoundNBT>) h).deserializeNBT(compound); }); item = compound.getString("name"); super.read(tag); } @Override public CompoundNBT write(CompoundNBT tag) { handler.ifPresent(h ->{ CompoundNBT compound = ((INBTSerializable<CompoundNBT>)h).serializeNBT(); tag.put("inv",compound); compound.put("items", ((INBTSerializable<CompoundNBT>) h).serializeNBT()); compound.putString("name",item); }); return super.write(tag); } and on the add info i have this, which i knew it wouldn't work, but im not sure how to approach it: Spoiler @Override public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { CompoundNBT compoundNBT = stack.getTag(); if(compoundNBT != null) { String s = compoundNBT.getString("name"); tooltip.add(new StringTextComponent(TextFormatting.DARK_GRAY + ("Item: " +s))); } super.addInformation(stack, worldIn, tooltip, flagIn); } Edited November 6, 20195 yr by AlexVR
November 7, 20195 yr Author 1 hour ago, [NoOneButNo] said: Take a look at the shulker box code. I believe it might help you. But the shulker box doesn't tell you it's content on the tool tip, does it?
November 7, 20195 yr 2 minutes ago, AlexVR said: But the shulker box doesn't tell you it's content on the tool tip, does it? It does, look at ShulkerBoxBlock#addInformation, which itself gets called inside of BlockItem to add the block's tooltips to its item. I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.
November 7, 20195 yr Author 12 minutes ago, imacatlolol said: It does, look at ShulkerBoxBlock#addInformation, which itself gets called inside of BlockItem to add the block's tooltips to its item. Just checked, it does, thanks so much! Will post code for future searchers: Spoiler @OnlyIn(Dist.CLIENT) public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { super.addInformation(stack, worldIn, tooltip, flagIn); CompoundNBT compoundnbt = stack.getChildTag("BlockEntityTag"); if (compoundnbt != null) { if (compoundnbt.contains("LootTable", 8)) { tooltip.add(new StringTextComponent("???????")); } if (compoundnbt.contains("Items", 9)) { NonNullList<ItemStack> nonnulllist = NonNullList.withSize(1, ItemStack.EMPTY); ItemStackHelper.loadAllItems(compoundnbt, nonnulllist); if (!nonnulllist.get(0).isEmpty()) { ITextComponent itextcomponent = nonnulllist.get(0).getDisplayName().deepCopy(); itextcomponent.appendText(" x").appendText(String.valueOf(nonnulllist.get(0).getCount())); tooltip.add(itextcomponent); } } } }
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.