Deserialize block


#1

[Google TRAD]
Hello
How do we deserialize a block?

minecraft:chest[facing=west]

MemoryDataContainer{safety=ALL_DATA_CLONED, map={ContentVersion=1, WorldName=monde, WorldUuid=22ad369d-9260-4130-b684-96af7b9540ee, BlockType=minecraft:chest, X=-37.0, Y=64.0, Z=283.0}}

I do not speak French, sorry.
thank you

.
.
[Français]
Bonjour
Comment on deserialize un bloc ?

minecraft:chest[facing=west]

MemoryDataContainer{safety=ALL_DATA_CLONED, map={ContentVersion=1, WorldName=monde, WorldUuid=22ad369d-9260-4130-b684-96af7b9540ee, BlockType=minecraft:chest, X=-37.0, Y=64.0, Z=283.0}}

merci


#2

[EN]
To help you we need more details. What do you want to serialize/deserialize, a BlockState or a BlockSnapshot? And in what form? A String, a ConfigurationNode or a DataContainer?

[FR]
Pour t’aider on a besoin de plus de détails. Que veux tu sérialiser/déserialiser, un BlockState ou un BlockSnapshot ? Et sous quel forme ? Un String, un ConfigurationNode ou un DataContainer ?


#3

A shit ^^, I did not think it was so complex, I want to deserialize something that I recover from my config for example: “minecraft: wool [color = red]”

World code:

FileConfig.getConfig().getNode(“Block”).setValue(location.getBlock().toString());
FileConfig.getConfig().getNode(“Block”).getString();

[FR]
A merde^^, je pensais pas que c’était si complexe, je veux désérializer quelque chose que je récupère de ma config par exemple: “minecraft:wool[color=red]”

Monde code:

FileConfig.getConfig().getNode(“Block”).setValue(location.getBlock().toString());
FileConfig.getConfig().getNode(“Block”).getString();


#4

[EN]
It looks like you want to serialize and deserialize a BlockState to and from a ConfigurationNode. This example should do the trick:

[FR]
Il semblerait que tu souhaites sérialiser et désérialiser un BlockState vers et depuis un ConfigurationNode. Cet exemple devrait faire l’affaire:

FileConfig.getConfig().getNode(“Block”).setValue(TypeTokens.BLOCK_TOKEN, location.getBlock());
FileConfig.getConfig().getNode(“Block”).getValue(TypeTokens.BLOCK_TOKEN);

#5

[Google TRAD]
A big thank you, I had not found in the doc https://docs.spongepowered.org/stable/fr/
I’m looking for yesterday ^^

Why do not we just use ? location.getBlock().toString()

[FR]
merci, j’avais pas trouvé dans la doc https://docs.spongepowered.org/stable/fr/
Je cherche depuis hier^^

Pourquoi on utilise pas juste ? location.getBlock().toString()


#6

[Google trad]
When I copy

minecraft:quartz_block[variant=lines]

it does not save the orientation

[FR]
Quand je copy

minecraft:quartz_block[variant=lines]

ça ne sauvegarde pas l’orientation


#7

[EN]
The purpose of BlockState#toString is not to serialize the object. There is no guarantee that this method will always return the same thing in future updates.
For your problem with the orientation it’s strange. Which version of spongevanilla or spongeforge do you use?

[FR]
Le but de BlockState#toString n’est pas de sérialiser l’objet. Rien ne garanti que cette méthode renverra toujours la même chose dans de futures mise à jours.
Pour ton problème avec l’orientation c’est étrange. Quelle version de spongevanilla ou spongeforge utilises tu ?


#8

[Google trad]
Question how do I know the version I’m using? I dare do more update, I had a lot of installation problems for it to work.

[FR]
Question bête comment je sais la version que j’utilise ? J’ose plus faire de mise à jour, j’ai eu énormément de problèmes d’installation pour que ça fonctionne.


#9

[EN]
Execute sponge version in game.
If you never update it can explain some bugs ^^.

[FR]
Execute sponge version en jeu.
Si tu ne fais jamais de mise à jour ca peut expliquer quelques bugs ^^.


#10

Voila:


#11

[Google trad]
Orientation is not saved:

minecraft:quartz_block[variant=lines]

Left before right when it is pasted:

[FR]
L’orientation n’est pas enregistée:

minecraft:quartz_block[variant=lines]

A gauche avant a droite quand c’est collé:


#12

[EN Translated]
I checked it out. The problem manifests itself at the stage of converting BlockState into DataContainer (BlockState#toContainer()). Please write issue about it at GitHub.
[FR Translated]
Je l’ai vérifié. Le problème se manifeste au stade de la conversion de BlockState en DataContainer (BlockState#toContainer()). Veuillez écrire le problème à ce sujet sur GitHub.


#13

[Google trad]
I have to say what?

[FR]
Je dois dire quoi ?


#14

[EN]
Just explain your problem with as much detail as possible and possibly quote Lignium’s message. Sponge developers will do the rest.

[FR]
Explique juste ton problème avec le plus de détails possible et éventuellement cite le message de Lignum. Les développeurs de Sponge se chargeront du reste.


#15

#16

[Google trad]
thank you

[FR]
merci


#18

[Google trad]
Hello. with this code I get the orientation of the blocks. I save like this:

  final List<BlockState> Blocksmeta = new ArrayList<>();
  int i = 1;
  for (int x = x1; x <= x2; x++) {
  	for (int y =  y1; y <= y2; y++) {
  		for (int z =  z1; z <= z2; z++) {
  			Location<World> location = new Location<World>(player.getWorld(), x, y, z);
  			Blocksmeta.add(location.getBlock());
  	    	i++;
  		}
  	}
  }

  FileConfig.getConfig().getNode("conf", "Blocs", nom_zone, "blocs").setValue(Blocksmeta.toString());
  FileConfig.save();
  FileConfig.load();

Résultat:

conf {
    Blocs {
        Test {
            blocs="[minecraft:quartz_block[variant=lines_x], minecraft:lit_pumpkin[facing=west], minecraft:sandstone_stairs[facing=south,half=top,shape=straight], minecraft:lit_pumpkin[facing=south], minecraft:quartz_block[variant=lines_y], minecraft:wool[color=blue], minecraft:chest[facing=north], minecraft:air, minecraft:quartz_block[variant=lines_x], minecraft:wool[color=red], minecraft:air, minecraft:air]"
            zone {
                "coin_1" {
                    x1=65
                    y1=4
                    z1=30
                }
                "coin_2" {
                    x2=67
                    y2=5
                    z2=31
                }
            }
        }
    }
}

Doing:

CommentedConfigurationNode t = FileConfigAnimatedMagic.getConfig().getNode("conf", "Blocs", nom_zone);
Sponge.getLogger().debug("" + t.getNode("blocs").getValue());

Give me:

[minecraft:quartz_block[variant=lines_x], minecraft:lit_pumpkin[facing=west], minecraft:sandstone_stairs[facing=south,half=top,shape=straight], minecraft:lit_pumpkin[facing=south], minecraft:quartz_block[variant=lines_y], minecraft:wool[color=blue], minecraft:chest[facing=north], minecraft:air, minecraft:quartz_block[variant=lines_x], minecraft:wool[color=red], minecraft:air, minecraft:air]

But how to buckle on? I can not do it

This code gives nothing:

Sponge.getLogger().debug("" + t.getNode(“blocs”).getChildrenList().stream().map(ConfigurationNode::getString).collect(Collectors.toList()).size());

[FR]
Bonjour. avec ce code je récupère l’orientation des blocs. Je sauvegarde comme ceci:

  final List<BlockState> Blocksmeta = new ArrayList<>();
  int i = 1;
  for (int x = x1; x <= x2; x++) {
  	for (int y =  y1; y <= y2; y++) {
  		for (int z =  z1; z <= z2; z++) {
  			Location<World> location = new Location<World>(player.getWorld(), x, y, z);
  			Blocksmeta.add(location.getBlock());
  	    	i++;
  		}
  	}
  }

  FileConfig.getConfig().getNode("conf", "Blocs", nom_zone, "blocs").setValue(Blocksmeta.toString());
  FileConfig.save();
  FileConfig.load();

Résultat:

conf {
    Blocs {
        Test {
            blocs="[minecraft:quartz_block[variant=lines_x], minecraft:lit_pumpkin[facing=west], minecraft:sandstone_stairs[facing=south,half=top,shape=straight], minecraft:lit_pumpkin[facing=south], minecraft:quartz_block[variant=lines_y], minecraft:wool[color=blue], minecraft:chest[facing=north], minecraft:air, minecraft:quartz_block[variant=lines_x], minecraft:wool[color=red], minecraft:air, minecraft:air]"
            zone {
                "coin_1" {
                    x1=65
                    y1=4
                    z1=30
                }
                "coin_2" {
                    x2=67
                    y2=5
                    z2=31
                }
            }
        }
    }
}

En faisant:

CommentedConfigurationNode t = FileConfigAnimatedMagic.getConfig().getNode("conf", "Blocs", nom_zone);
Sponge.getLogger().debug("" + t.getNode("blocs").getValue());

Me donne:

[minecraft:quartz_block[variant=lines_x], minecraft:lit_pumpkin[facing=west], minecraft:sandstone_stairs[facing=south,half=top,shape=straight], minecraft:lit_pumpkin[facing=south], minecraft:quartz_block[variant=lines_y], minecraft:wool[color=blue], minecraft:chest[facing=north], minecraft:air, minecraft:quartz_block[variant=lines_x], minecraft:wool[color=red], minecraft:air, minecraft:air]

Mais comment boucler dessus ? Je n’y arrive pas

Ce code donne rien:

Sponge.getLogger().debug("" + t.getNode(“blocs”).getChildrenList().stream().map(ConfigurationNode::getString).collect(Collectors.toList()).size());


#19

You should replace: setValue(Blocksmeta.toString()) with setValue(new TypeToken<List<BlockState>>() {}, Blocksmeta) and getValue with getList(TypeToken.of(BlockState.class)).


#20

[Google trad]
It’s a shame, because with your method it says:
“minecraft:quartz_block[variant=lines]”,

and before:
“minecraft:quartz_block[variant=lines_x]”,

merci

[FR]
C’est dommage, car avec ta méthode ça écrit:
“minecraft:quartz_block[variant=lines]”,

et avant:
“minecraft:quartz_block[variant=lines_x]”,


EDIT:
Enregistrer:

“minecraft:quartz_block[variant=lines]”,

et quand je le récup:

minecraft:quartz_block[variant=lines_y]