3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 22:40:18 +01:00

Begin parsing block mappings (still much to do!)

Dieser Commit ist enthalten in:
Joshua Castle 2022-12-30 04:00:06 -08:00
Ursprung 8f7d67bde0
Commit 2029ba800d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: F674F38216C35D5D
2 geänderte Dateien mit 111 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -28,11 +28,17 @@ package org.geysermc.geyser.registry.mappings.versions;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.block.custom.CustomBlockData; import org.geysermc.geyser.api.block.custom.CustomBlockData;
import org.geysermc.geyser.api.block.custom.CustomBlockPermutation;
import org.geysermc.geyser.api.block.custom.component.CustomBlockComponents;
import org.geysermc.geyser.api.item.custom.CustomItemData; import org.geysermc.geyser.api.item.custom.CustomItemData;
import org.geysermc.geyser.api.item.custom.CustomItemOptions; import org.geysermc.geyser.api.item.custom.CustomItemOptions;
import org.geysermc.geyser.item.exception.InvalidCustomMappingsFileException; import org.geysermc.geyser.item.exception.InvalidCustomMappingsFileException;
import org.geysermc.geyser.level.block.GeyserCustomBlockComponents;
import org.geysermc.geyser.level.block.GeyserCustomBlockData;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
public class MappingsReader_v1 extends MappingsReader { public class MappingsReader_v1 extends MappingsReader {
@ -157,6 +163,80 @@ public class MappingsReader_v1 extends MappingsReader {
throw new InvalidCustomMappingsFileException("A block entry has no name"); throw new InvalidCustomMappingsFileException("A block entry has no name");
} }
return null; JsonNode stateOverrides = node.get("state_overrides");
CustomBlockData customBlockData = new GeyserCustomBlockData.CustomBlockDataBuilder()
.name(name)
.components(createCustomBlockComponents(node))
// TODO: need to parse state data to find these, e.g. [east=none,north=none,power=1,south=none,west=none]
// TODO: add possible values for all blockstates to mappings generator
// .booleanProperty()
// .intProperty()
// .stringProperty()
.permutations(createCustomBlockPermutations(stateOverrides))
.build();
return customBlockData;
}
private List<CustomBlockPermutation> createCustomBlockPermutations(JsonNode node) {
List<CustomBlockPermutation> permutations = new ArrayList<>();
if (node != null && node.isObject()) {
node.fields().forEachRemaining(entry -> {
String key = entry.getKey();
JsonNode value = entry.getValue();
if (value.isObject()) {
value.forEach(data -> {
permutations.add(new CustomBlockPermutation(createCustomBlockComponents(data), createCustomBlockPropertyQuery(key)));
});
}
});
}
return permutations;
}
private CustomBlockComponents createCustomBlockComponents(JsonNode node) {
CustomBlockComponents components = new GeyserCustomBlockComponents.CustomBlockComponentsBuilder()
// .selectionBox()
// .collisionBox()
// .displayName()
// .geometry()
// .materialInstance()
// .destroyTime()
// .friction()
// .lightEmission()
// .lightDampening()
// .rotation()
// .placeAir()
.build();
JsonNode materialInstances = node.get("material_instances");
// TODO: loop through material instances and add component for each to components
return components;
}
private String createCustomBlockPropertyQuery(String state) {
String list = state.substring(1, state.length() - 1);
String[] conditions = list.split(",");
String[] queries = new String[conditions.length];
for (int i = 0; i < conditions.length; i++) {
String[] keyval = conditions[i].split("=", 2);
if (keyval[1].equals("true")) {
queries[i] = String.format("query.block_property('%s') == %b", keyval[0], 1);
} else if (keyval[1].equals("false")) {
queries[i] = String.format("query.block_property('%s') == %b", keyval[0], 0);
} else if (keyval[1].matches("-?\\d+")) {
queries[i] = String.format("query.block_property('%s') == %b", keyval[0], Integer.parseInt(keyval[1]));
} else {
queries[i] = String.format("query.block_property('%s') == '%b'", keyval[0], keyval[1]);
} }
} }
return String.join(" && ", queries);
}
}

Datei anzeigen

@ -25,22 +25,21 @@
package org.geysermc.geyser.registry.populator; package org.geysermc.geyser.registry.populator;
import com.fasterxml.jackson.databind.JsonNode; import java.io.DataInputStream;
import com.fasterxml.jackson.databind.node.ArrayNode; import java.io.InputStream;
import com.google.common.collect.ImmutableMap; import java.nio.charset.StandardCharsets;
import com.nukkitx.nbt.*; import java.util.ArrayDeque;
import com.nukkitx.protocol.bedrock.data.BlockPropertyData; import java.util.ArrayList;
import com.nukkitx.protocol.bedrock.v544.Bedrock_v544; import java.util.Deque;
import com.nukkitx.protocol.bedrock.v560.Bedrock_v560; import java.util.Iterator;
import java.util.List;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import java.util.Map;
import it.unimi.dsi.fastutil.ints.IntSet; import java.util.function.BiFunction;
import it.unimi.dsi.fastutil.objects.*; import java.util.zip.GZIPInputStream;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.block.custom.CustomBlockData; import org.geysermc.geyser.api.block.custom.CustomBlockData;
import org.geysermc.geyser.api.block.custom.CustomBlockState; import org.geysermc.geyser.api.block.custom.CustomBlockState;
import org.geysermc.geyser.api.block.custom.component.BoxComponent;
import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.level.block.BlockStateValues;
import org.geysermc.geyser.level.physics.PistonBehavior; import org.geysermc.geyser.level.physics.PistonBehavior;
import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.registry.BlockRegistries;
@ -48,12 +47,25 @@ import org.geysermc.geyser.registry.type.BlockMapping;
import org.geysermc.geyser.registry.type.BlockMappings; import org.geysermc.geyser.registry.type.BlockMappings;
import org.geysermc.geyser.util.BlockUtils; import org.geysermc.geyser.util.BlockUtils;
import java.io.DataInputStream; import com.fasterxml.jackson.databind.JsonNode;
import java.io.InputStream; import com.fasterxml.jackson.databind.node.ArrayNode;
import java.nio.charset.StandardCharsets; import com.google.common.collect.ImmutableMap;
import java.util.*; import com.nukkitx.nbt.NBTInputStream;
import java.util.function.BiFunction; import com.nukkitx.nbt.NbtList;
import java.util.zip.GZIPInputStream; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.protocol.bedrock.data.BlockPropertyData;
import com.nukkitx.protocol.bedrock.v544.Bedrock_v544;
import com.nukkitx.protocol.bedrock.v560.Bedrock_v560;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectIntPair;
/** /**
* Populates the block registries. * Populates the block registries.