Jump to content

[1.9.2] custom Extructure i need to save the blocks and the states as plain text or json


perromercenary00

Recommended Posts


Good days 

im currently trying to add some custome extructures to mi mod using a mix of mi custome blocks plus the vainilla ones 

in the old times a minecraft block could have up to 16 variants no more 

and there was methods to get the block metadata as an int value 

and also was method to set back the block metadata using that same  int metadata value 


but now we have properties whit object names and values 
The first i try was to save the block properties as a json file ,  but i couldn find no way to recreate back the blockstate from the json 

	    // ########## ########## ########## ##########
    public String print() {
        BlockState blkstate = this.getBlockState();
        
        String json = "";
        
	        System.out.println("blkfullname   = " + this.get_blkfullname());
	        int id = Block.getId(blkstate);
        System.out.println("id    = " + id);
	        System.out.println("world = " + this.warudo.isClientSide);
        System.out.println("pos = " + this.pos);
	        String propiedades = "";
        for (Property<?> porp : blkstate.getProperties()) {
            
            System.out.println(porp.getName() + " -> " + blkstate.getValue(porp));
            propiedades += String.format( ",\"%1$s\":\"%2$s\"", porp.getName(), blkstate.getValue(porp) );  
        }
        
        json = String.format("{\"blockname\":\"%1$s\",\"x\":\"%2$s\",\"y\":\"%3$s\",\"z\":\"%4$s\"%5$s}",
                this.get_blkfullname(), this.pos.getX(), this.pos.getY(), this.pos.getZ(), propiedades 
                );
        
        System.out.println("\n" + json + "\n" );
        return json;
    }
	{"blockname":"ender chest","x":"-29","y":"67","z":"53","facing":"north","waterlogged":"false"}
	{"blockname":"iron trapdoor","x":"-33","y":"67","z":"62","facing":"north","half":"bottom","open":"false","powered":"false","waterlogged":"false"}
	{"blockname":"stone brick wall","x":"-33","y":"67","z":"60","east":"none","north":"low","south":"none","up":"true","waterlogged":"false","west":"none"}
	{"blockname":"grass block","x":"-33","y":"66","z":"76","snowy":"false"}
	{"blockname":"scaffolding","x":"-33","y":"67","z":"76","bottom":"false","distance":"0","waterlogged":"false"}
	

######################################################################################

The second thing i try  was to use the minecraft tools
i set some blocks on the ground and save it as a nbt file using a  minecraft:structure_block

workspace/mod-1.19.2-43.1.3/run/saves/New%20World%20(1)/generated/minecraft/structures/dx.nbt

well the guide explains how to spawns the extructure minecraft:dx in to the world using chat commands 
but there's no mention on how to spawn it from the java code 
or i overlookit  anyway im not native speaker 

 

######################################################################################
i would prefer to make work the first method, briging back the Blockstates from json files 
looks like i have more control that way 

but if the second works then works 

 

 

thanks for your time 

 

 

 

 

 

 

 

 

 


 

 

 

 

Edited by perromercenary00
Link to comment
Share on other sites

NbtUtils.read/writeBlockState()

BlockEntity.loadStatic/saveWithFullMeta()

 

The modern way to handle the BlockState is really to use the BlockState.CODEC

 

The game uses a Pallete (to save space) when saving chunk sections, see ChunkSerializer.

Or an example using NbtUtils is StructureTemplate

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

i wass looking at the thing 

NbtUtils.read/writeBlockState()

BlockEntity.loadStatic/saveWithFullMeta()

reallly really dont get how to use that to save and s pawns extructures then 

hyperfocus thingly thing jumping on, end hardcoding the full thing

 

and end adding it to mi block finder class 
theres a shitty thing whit enums not acepting string values in exchange for the equivalent objects 

WallSide.valueOf(value.toUpperCase())  //dont works

WallSide.valueOf(value.toLowerCase()) //also dont works 
 

####

i would prefer a method to just take the blockstate metada as a int  and set it back as an int

after all it must be no more than a six figures binary number 

 

 

##################################################################################

do you have a link to more detailed tutrail on how to use the nbt thing to use extructures as nbts ?

 

 

 


 

 

 

 

Link to comment
Share on other sites

Quote

i would prefer a method to just take the blockstate metada as a int  and set it back as an int

That is not how this works.

The ints used to identify blocks/blockstates are not necessarily the same when you restart minecraft.

The int -> blockstate is dependent upon which mods are loaded and in what order they register blocks.

You can't just save int ids in a file and expect them to be the same or even valid when you reload them in the future.

 

What minecraft does is use a palette (as I said above). This is to save space and redundant processing.

e.g. in simple terms you might have a save file of 3x3 blocks that is

1, 1, 2

1, 0, 0

2, 3, 1

The palette could then look something like this

0=minecraft:air

1=minecraft:stone

2=minecraft:snow{layers=4}

3=minecraft:oak_log{axis=x)

 

At reload you then deserialize minecraft:stone to find the BlockState and use that where you have stored 1 in your save.

 

What minecraft actually does with its palettes in its code is slightly more complicated than my simple explanation because it can do further optimisations.

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.