mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Begin parsing block mappings (still much to do!)
This commit is contained in:
parent
8f7d67bde0
commit
2029ba800d
2 changed files with 111 additions and 19 deletions
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue