Jump to content

[1.15.2] ItemStack NBT not transferred to Block's TileEntity


Spyeedy

Recommended Posts

As the title says, my ItemStack's NBT tags aren't getting transferred to my Block's TileEntity NBT. This worked back on 1.12.2, so I'm not sure why it isn't working now.


In the gist linked below are the ItemBlock and TileEntity classes.

https://gist.github.com/Spyeedy/104a892bd3970d189aaf42a10f8645d7

 

Thanks for responding :)

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

10 hours ago, sciwhiz12 said:

stack.getTag().getList("lightsPosLight", Constants.NBT.TAG_LIST).forEach(inbt -> te.addLightPos(((LongNBT)inbt).getLong()));

private static final String NBT_LIGHTS_KEY = "lightsPosList";

It seems you mistyped your list tag's key.

Well, that first line is part of a commented out block, but hmm, I ain't putting the list tag into the BlockEntityTag since I commented out the code inside Block#onBlockPlacedBy, I'll try uncommenting inside onBlockPlacedBy and fixing that typo

Edited by Spyeedy

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

I've fixed that typo, and I've added a print statement in my Block's onBlockPlacedBy to look at the nbt list's size, weirdly enough, it prints out 0, even though in the item's nbt list, it has contents. As well as set the tag compound back into the ItemStack's NBT, just to be extremely sure the Item has the new NBT

 

Updated the gist:

https://gist.github.com/Spyeedy/104a892bd3970d189aaf42a10f8645d7

Edited by Spyeedy

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

I wonder if write() is getting called? because you've override

	@Override
	public CompoundNBT serializeNBT() {
		CompoundNBT nbt = new CompoundNBT();
		System.out.println("serialize");
		return nbt;
	}

	@Override
	public void deserializeNBT(CompoundNBT nbt) {
		System.out.println("deserialize");
	}

and before that serializeNBT calles write(), and desrializeNBT calls read(). Not sure if it's related tho

Link to comment
Share on other sites

Possibly, but the thing is, in the onBlockPlacedBy method, I printed the stack's NBT list count, it returns 0, despite that the item does have content inside the list, hmm

https://gist.github.com/Spyeedy/104a892bd3970d189aaf42a10f8645d7#file-lightswitchblock-java-L33

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

Possibly, but the thing is, in the onBlockPlacedBy method, I printed the stack's NBT list count, it returns 0, despite that the item does have content inside the list, hmm

https://gist.github.com/Spyeedy/104a892bd3970d189aaf42a10f8645d7#file-lightswitchblock-java-L33

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

Okaaaaay, this is weird, the console prints for Render thread, so that's client, it doesn't print for server? Idk if the NBT really gets saved, because the output always come out as:

Before:0
After:1

image.png.e05d673543bfdc996286322e1b14dda1.png

at these lines
https://gist.github.com/Spyeedy/104a892bd3970d189aaf42a10f8645d7#file-lightswitchblockitem-java-L30-L33

Edited by Spyeedy

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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