Bonjour,
Je veux stocker des bloc de cette façon:
conf {
blocs=[
[
"minecraft:air",
"minecraft:air",
"minecraft:air",
"minecraft:air",
"minecraft:air",
"minecraft:air",
"minecraft:air",
"minecraft:air"
],
[
"minecraft:air",
"minecraft:stone[variant=stone]",
"minecraft:torch[facing=west]",
"minecraft:stone[variant=stone]",
"minecraft:stone[variant=stone]",
"minecraft:stone[variant=stone]",
"minecraft:stone[variant=andesite]",
"minecraft:stone[variant=stone]"
]
]
}
Pour tester je fais:
List<BlockState> bloc1 = new ArrayList<>();
List<BlockState> bloc2 = new ArrayList<>();
List<List<BlockState>> liste = new ArrayList<>();
// Code
liste.add(bloc1);
liste.add(bloc2);
et je sauvegarde:
try {
conf.getConfig().getNode("conf", "blocs").setValue(new TypeToken<List<List<BlockState>>>() {}, liste);
} catch (ObjectMappingException e) {
e.printStackTrace();
}
conf.save();
J’arrive a récupérer ma liste de bloc de cette façon:
List<? extends List<? extends ConfigurationNode>> test = conf.getConfig().getNode("conf", "blocs").getChildrenList().stream().map(ConfigurationNode::getChildrenList).collect(Collectors.toList());
// Test:
Tool.getLogger().debug("test.get(0): " + test.get(0).toString());
Tool.getLogger().debug("test.get(0).get(1): " + test.get(0).get(0).getString());
Tool.getLogger().debug(" test.get(0).get(1): " + test.get(0).get(1).getString());
Donc jusqu’ici aucun problème.
Par contre je ne sais pas comment faire pour rajouter un élément a cette liste, comment je dois faire ?
List<BlockState> bloc2 = new ArrayList<>();
// Code
test.add(bloc3);
PS: je parle pas anglais, j’espère que les exemples seront clair, car je suis pas sur que google trad traduise bien
{Google TRAD}
Hello,
I want to store block this way:
conf {
blocs=[
[
"minecraft:air",
"minecraft:air",
"minecraft:air",
"minecraft:air",
"minecraft:air",
"minecraft:air",
"minecraft:air",
"minecraft:air"
],
[
"minecraft:air",
"minecraft:stone[variant=stone]",
"minecraft:torch[facing=west]",
"minecraft:stone[variant=stone]",
"minecraft:stone[variant=stone]",
"minecraft:stone[variant=stone]",
"minecraft:stone[variant=andesite]",
"minecraft:stone[variant=stone]"
]
]
}
To test I do:
List<BlockState> bloc1 = new ArrayList<>();
List<BlockState> bloc2 = new ArrayList<>();
List<List<BlockState>> liste = new ArrayList<>();
// Code
liste.add(bloc1);
liste.add(bloc2);
and I backup:
try {
conf.getConfig().getNode("conf", "blocs").setValue(new TypeToken<List<List<BlockState>>>() {}, liste);
} catch (ObjectMappingException e) {
e.printStackTrace();
}
conf.save();
I can recover my block list this way:
List<? extends List<? extends ConfigurationNode>> test = conf.getConfig().getNode("conf", "blocs").getChildrenList().stream().map(ConfigurationNode::getChildrenList).collect(Collectors.toList());
// Test:
Tool.getLogger().debug("test.get(0): " + test.get(0).toString());
Tool.getLogger().debug("test.get(0).get(1): " + test.get(0).get(0).getString());
Tool.getLogger().debug(" test.get(0).get(1): " + test.get(0).get(1).getString());
So far no problem.
By cons I do not know how to add an item to this list, how should I do?
List<BlockState> bloc2 = new ArrayList<>();
// Code
test.add(bloc3);