Jump to content

[1.16] Change blockstate of a specific block in world


FluffyDiscord

Recommended Posts

Hello,

I want to have a block, which will take on a texture of a block which player holds in hand if he right clicks on the block placed in the world. So far I got it to change as I like, but it changes all blocks instead of just the single one I clicked on. I suspect, it's because the blocks in game are all just a single object instance and world just has bunch on references to it.

 

How can I then change the single blockstate (or rather, it's texture, if it helps) ? Do I need to create some kind of registry, which will remember block positions and their blockstates and load the blockstate based on the block position ? Is there something more optimal, because if I have a arraylist of, let's say, 2k block positions and their block states which I need update every so often, I think it's gonna get slow real quick. Or if this IS the best way, then how can I save the registry, so after server restarts, it's gonna remember them?

Link to comment
Share on other sites

58 minutes ago, diesieben07 said:

You need to add a TileEntity to your block to store arbitrary data.

Is this the optimal way? The blocks should be used as a normal/basic building block, so there may be hundreds or maybe even a thousands of them in a single chunk.

Edited by FluffyDiscord
Link to comment
Share on other sites

That is the only way. All blockstates are calculated on registration, so there is no way to save that to a single blockstate.

If there are that many, you may need to rethink your approach.

You could maybe store a chunk capability with a map of blockpos -> blockstate, but I'm not sure that would save you much (after all, that is what the world saves). And you'd have a much harder time sorting out the rendering.

Link to comment
Share on other sites

I tried to add a tile entity to the block, but I don't think it works properly. The tile entity I have seem to be missing read() function to overwrite for NBT tag data, so I tried deserializeNBT() and serializeNBT(), but I don't think that's the correct way. Also with that, my model class doesn't seems to be working - the block is not changing texture as it should. Do I need to register my IBakedModel somewhere ?

 

SC is here: https://github.com/FluffyDiscord/blocks-mod

The code is somewhat taken from some 1.15 example mod.

 

Anyone who can take a bit of their time and help me out with explaining a bit (via PM here or Discord) ?

Link to comment
Share on other sites

2 minutes ago, Alpvax said:

Check out TheGreyGhost's MBE04: Dynamic_block_models. It does almost exactly what you want (make sure you understand, not just copy-paste).

That's the one I have been following, but if I do follow it, I run into issue, where the IBakedModel's getQuads() is being called, instead of IForgeBakedModel's one. Which is a problem, right ?

Link to comment
Share on other sites

7 minutes ago, Alpvax said:

You've commented out the event listener (ModelBakeEvent) which actually instantiates your custom model (in BlocksMod.java).

When I register it and try to load world, I get the error with the wrong getQuads() is being called

Quote

I run into issue, where the IBakedModel's getQuads() is being called, instead of IForgeBakedModel's one

 

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.