Jump to content

[1.12.2] Data syncing practices for NBT and blocks


SatyPardus

Recommended Posts

I hope I can post this in this Forum, as this is not completely asking for help, but more so giving ideas how to approach things.

 

I am currently working on a hologram for my mod, that should, in the finished mod, maybe be able to live update blockchanges.

It is mostly used for static rendering of a specific structure, but live rendering is possible.

 

Now to my question: How would you approach something like this? What would be the "best" practice to sync data without lagspikes or huge traffic.

The static rendering is already pretty traffic heavy, with updating it's NBT with each renderd blocks data - I probably should change that.

 

I was thinking about custom packets, sending only the required fields that are important for rendering, but I don't seem to understand the "new" BlockState system and it's block properties yet. It was so easy years ago with block IDs and metadata lol.

For the live rendering, I am curently calculating each height layer once in a TileEntity update. So each update it increases by 1, rendering the next layer in the next update. I still have to implement custom packages to only send what REALLY changed (As it currently sends the whole NBT data each update... a bit to much)

 

Does anybody have resources or maybe even experience with large data sync? That would be great.

 

A work in progress of the live update hologram. The unknown model is water, need to fix that too.

Link to comment
Share on other sites

Blockstates are just a more developer friendly way of expressing metadata and other types of information (such as a fence's connectedness)

 

The underlying data structure is still Block + Metadata, but you as a developer will only ever interact with it in order to translate between blockstate and metadata (and back) for your own blocks.

 

The result is you can have LADDER:FACING=NORTH instead of LADDER:0 or REPEATER:FACING=WEST,DELAY=2 instead of REPEATER:11 (11? 11!? What is this magic number?)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I mean, that is nice and all and maybe easier to read, but it would be great if there was still some way to just get numbers out of it.

I don't find any good resource on how to read out these attributes. Or maybe I just overlook something. But what I would like to do, is compressing the data myself as much as possible, storing it as int, short or maybe even byte to take down traffic.

 

It is just to much when there is a hologram with a huge house (like 1000 blocks) and it sends all this data via NBT. And it's even more when I plan to update it live.

I tested it on a small server and it's just horrible. May friend even lost connection completely.

 

I try to read through tutorials, the forge wiki but I don't seem to figure it out.

 

private NBTTagCompound writeBlockState(int index, NBTTagCompound tag, IBlockState state)
    {
        tag.setString("Name"+index, ((ResourceLocation)Block.REGISTRY.getNameForObject(state.getBlock())).toString());

        if (!state.getProperties().isEmpty())
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            UnmodifiableIterator unmodifiableiterator = state.getProperties().entrySet().iterator();

            while (unmodifiableiterator.hasNext())
            {
                @SuppressWarnings("unchecked")
				Entry < IProperty<?>, Comparable<? >> entry = (Entry)unmodifiableiterator.next();
                IProperty<?> iproperty = (IProperty)entry.getKey();
                nbttagcompound.setString(iproperty.getName(), getName(iproperty, entry.getValue()));
            }

            tag.setTag("Properties"+index, nbttagcompound);
        }

        return tag;
    }

 

This is the only thing I could find in NBTUtil what writes these properties... but honestly, I don't understand it.

A more performant way like blockids and int metadata would be much nicer in my case to work with, even when a metadata of 11 looks confusing, but wikis and documentation and own comments help there.

Link to comment
Share on other sites

if(ladderState.GetValue(FACING) == EnumFacing.NORTH) { // do stuff }

if(cropState.GetValue(AGE) > 5) { // do stuff }

repeaterState = repeaterState.WithProperty(DELAY, 2);

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.



×
×
  • Create New...

Important Information

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