3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 15:50:14 +01:00

Ok now they work at least

Dieser Commit ist enthalten in:
Joshua Castle 2023-01-01 00:08:01 -08:00
Ursprung c71f2c5597
Commit 461bff61f1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: F674F38216C35D5D
4 geänderte Dateien mit 69 neuen und 69 gelöschten Zeilen

Datei anzeigen

@ -141,8 +141,6 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
protected RotationComponent rotation; protected RotationComponent rotation;
protected boolean placeAir = false; protected boolean placeAir = false;
private static final Set<String> VALID_MATERIAL_INSTANCE_NAMES = ImmutableSet.of("*", "up", "down", "north", "south", "west", "east");
private void validateBox(BoxComponent box) { private void validateBox(BoxComponent box) {
if (box == null) { if (box == null) {
return; return;
@ -189,9 +187,6 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
@Override @Override
public Builder materialInstance(@NotNull String name, @NotNull MaterialInstance materialInstance) { public Builder materialInstance(@NotNull String name, @NotNull MaterialInstance materialInstance) {
if (!VALID_MATERIAL_INSTANCE_NAMES.contains(name)) {
throw new IllegalArgumentException("Material instance name must be one of " + VALID_MATERIAL_INSTANCE_NAMES);
}
this.materialInstances.put(name, materialInstance); this.materialInstances.put(name, materialInstance);
return this; return this;
} }

Datei anzeigen

@ -139,7 +139,7 @@ public class GeyserCustomBlockData implements CustomBlockData {
@Override @Override
public Builder booleanProperty(@NonNull String propertyName) { public Builder booleanProperty(@NonNull String propertyName) {
this.properties.put(propertyName, new GeyserCustomBlockProperty<>(propertyName, List.of(false, true), PropertyType.BOOLEAN)); this.properties.put(propertyName, new GeyserCustomBlockProperty<>(propertyName, List.of((byte) 0, (byte) 1), PropertyType.BOOLEAN));
return this; return this;
} }

Datei anzeigen

@ -70,7 +70,7 @@ public class GeyserCustomBlockState implements CustomBlockState {
@Override @Override
public Builder booleanProperty(@NonNull String propertyName, boolean value) { public Builder booleanProperty(@NonNull String propertyName, boolean value) {
properties.put(propertyName, value); properties.put(propertyName, value ? (byte) 1 : (byte) 0);
return this; return this;
} }

Datei anzeigen

@ -42,6 +42,7 @@ import org.geysermc.geyser.level.block.GeyserCustomBlockComponents.CustomBlockCo
import org.geysermc.geyser.level.block.GeyserCustomBlockData.CustomBlockDataBuilder; import org.geysermc.geyser.level.block.GeyserCustomBlockData.CustomBlockDataBuilder;
import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.registry.mappings.util.BlockPropertyTypeMaps; import org.geysermc.geyser.registry.mappings.util.BlockPropertyTypeMaps;
import org.geysermc.geyser.util.BlockUtils;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
@ -169,7 +170,7 @@ public class MappingsReader_v1 extends MappingsReader {
@Override @Override
public CustomBlockMapping readBlockMappingEntry(String identifier, JsonNode node) throws InvalidCustomMappingsFileException { public CustomBlockMapping readBlockMappingEntry(String identifier, JsonNode node) throws InvalidCustomMappingsFileException {
if (node == null || !node.isObject()) { if (node == null || !node.isObject()) {
throw new InvalidCustomMappingsFileException("Invalid block mappings entry:" + node.toString()); throw new InvalidCustomMappingsFileException("Invalid block mappings entry:" + node);
} }
String name = node.get("name").asText(); String name = node.get("name").asText();
@ -177,41 +178,49 @@ public class MappingsReader_v1 extends MappingsReader {
throw new InvalidCustomMappingsFileException("A block entry has no name"); throw new InvalidCustomMappingsFileException("A block entry has no name");
} }
boolean onlyOverrideStates = node.has("only_override_states") && node.get("only_override_states").asBoolean();
JsonNode stateOverrides = node.get("state_overrides"); JsonNode stateOverrides = node.get("state_overrides");
if (onlyOverrideStates && (stateOverrides == null || !stateOverrides.isObject())) {
throw new InvalidCustomMappingsFileException("A block entry has only_override_states set to true but no state_overrides");
}
List<String> stateKeys = new ArrayList<>(); List<String> stateKeys = new ArrayList<>();
Iterator<Map.Entry<String, JsonNode>> fields = stateOverrides.fields();
while (fields.hasNext()) { if (stateOverrides != null && stateOverrides.isObject()) {
stateKeys.add(identifier + fields.next().getKey()); Iterator<Map.Entry<String, JsonNode>> fields = stateOverrides.fields();
while (fields.hasNext()) {
stateKeys.add(identifier + fields.next().getKey());
}
} }
List<String> defaultStates = List.copyOf(BlockRegistries.JAVA_IDENTIFIERS.get().keySet()) List<String> defaultStates = List.copyOf(BlockRegistries.JAVA_IDENTIFIERS.get().keySet())
.stream() .stream()
.filter(s -> s.startsWith(identifier + "[")) .filter(s -> s.startsWith(identifier + "["))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (defaultStates.isEmpty()) defaultStates.add("");
CustomBlockDataBuilder customBlockDataBuilder = new CustomBlockDataBuilder(); CustomBlockDataBuilder customBlockDataBuilder = new CustomBlockDataBuilder();
customBlockDataBuilder.name(name)
customBlockDataBuilder .components(createCustomBlockComponents(node, defaultStates.get(0), identifier))
.name(name) .permutations(createCustomBlockPermutations(stateOverrides, identifier))
.components(createCustomBlockComponents(node))
.permutations(createCustomBlockPermutations(stateOverrides))
.booleanProperty("geyser_custom:default"); .booleanProperty("geyser_custom:default");
BlockPropertyTypeMaps blockPropertyTypeMaps = createBlockPropertyTypeMaps(defaultStates); BlockPropertyTypeMaps blockPropertyTypeMaps = createBlockPropertyTypeMaps(onlyOverrideStates ? stateKeys : defaultStates);
blockPropertyTypeMaps.stringValuesMap().forEach((key, value) -> customBlockDataBuilder.stringProperty(key, new ArrayList<String>(value))); blockPropertyTypeMaps.stringValuesMap().forEach((key, value) -> customBlockDataBuilder.stringProperty(key, new ArrayList<String>(value)));
blockPropertyTypeMaps.intValuesMap().forEach((key, value) -> customBlockDataBuilder.intProperty(key, new ArrayList<Integer>(value))); blockPropertyTypeMaps.intValuesMap().forEach((key, value) -> customBlockDataBuilder.intProperty(key, new ArrayList<Integer>(value)));
blockPropertyTypeMaps.booleanValuesSet().forEach((value) -> customBlockDataBuilder.booleanProperty(value)); blockPropertyTypeMaps.booleanValuesSet().forEach((value) -> customBlockDataBuilder.booleanProperty(value));
CustomBlockData customBlockData = customBlockDataBuilder.build(); CustomBlockData customBlockData = customBlockDataBuilder.build();
Map<String, CustomBlockState> states = createCustomBlockStatesMap(identifier, stateKeys, defaultStates, customBlockData, Map<String, CustomBlockState> states = createCustomBlockStatesMap(identifier, stateKeys, defaultStates, onlyOverrideStates, customBlockData,
blockPropertyTypeMaps.stateKeyStrings(), blockPropertyTypeMaps.stateKeyInts(), blockPropertyTypeMaps.stateKeyBools()); blockPropertyTypeMaps.stateKeyStrings(), blockPropertyTypeMaps.stateKeyInts(), blockPropertyTypeMaps.stateKeyBools());
return new CustomBlockMapping(customBlockData, states); return new CustomBlockMapping(customBlockData, states);
} }
private List<CustomBlockPermutation> createCustomBlockPermutations(JsonNode node) { private List<CustomBlockPermutation> createCustomBlockPermutations(JsonNode node, String identifier) {
List<CustomBlockPermutation> permutations = new ArrayList<>(); List<CustomBlockPermutation> permutations = new ArrayList<>();
if (node != null && node.isObject()) { if (node != null && node.isObject()) {
@ -220,62 +229,49 @@ public class MappingsReader_v1 extends MappingsReader {
JsonNode value = entry.getValue(); JsonNode value = entry.getValue();
if (value.isObject()) { if (value.isObject()) {
value.forEach(data -> { value.forEach(data -> {
permutations.add(new CustomBlockPermutation(createCustomBlockComponents(data), createCustomBlockPropertyQuery(key))); permutations.add(new CustomBlockPermutation(createCustomBlockComponents(data, key, identifier), createCustomBlockPropertyQuery(key)));
}); });
} }
}); });
} }
permutations.add(new CustomBlockPermutation( permutations.add(new CustomBlockPermutation(new GeyserCustomBlockComponents.CustomBlockComponentsBuilder().build(), "q.block_property('geyser_custom:default') == 1"));
new GeyserCustomBlockComponents.CustomBlockComponentsBuilder().build(),
"q.block_property('geyser_custom:default') == 1"));
return permutations; return permutations;
} }
private Map<String, CustomBlockState> createCustomBlockStatesMap( private Map<String, CustomBlockState> createCustomBlockStatesMap(String identifier, List<String> stateKeys,List<String> defaultStates, boolean onlyOverrideStates, CustomBlockData customBlockData,
String identifier, Map<String, Map<String, String>> stateKeyStrings, Map<String, Map<String, Integer>> stateKeyInts, Map<String, Map<String, Boolean>> stateKeyBools) {
List<String> stateKeys,
List<String> defaultStates,
CustomBlockData customBlockData,
Map<String, Map<String, String>> stateKeyStrings,
Map<String, Map<String, Integer>> stateKeyInts,
Map<String, Map<String, Boolean>> stateKeyBools) {
Map<String, CustomBlockState> states = new HashMap<>(); Map<String, CustomBlockState> states = new HashMap<>();
defaultStates.removeAll(stateKeys); if (!onlyOverrideStates) {
defaultStates.removeAll(stateKeys);
defaultStates.forEach(key -> { createCustomBlockStates(defaultStates, true, customBlockData, stateKeyStrings, stateKeyInts, stateKeyBools, states);
CustomBlockState.Builder builder = customBlockData.blockStateBuilder(); }
builder.booleanProperty("geyser_custom:default", true); createCustomBlockStates(stateKeys, false, customBlockData, stateKeyStrings, stateKeyInts, stateKeyBools, states);
stateKeyStrings.getOrDefault(key, Collections.emptyMap()).forEach((property, stringValue) -> builder.stringProperty(property, stringValue));
stateKeyInts.getOrDefault(key, Collections.emptyMap()).forEach((property, intValue) -> builder.intProperty(property, intValue));
stateKeyBools.getOrDefault(key, Collections.emptyMap()).forEach((property, boolValue) -> builder.booleanProperty(property, boolValue));
CustomBlockState blockState = builder.build();
states.put(key, blockState);
});
stateKeys.forEach((key) -> {
CustomBlockState.Builder builder = customBlockData.blockStateBuilder();
builder.booleanProperty("geyser_custom:default", false);
stateKeyStrings.getOrDefault(key, Collections.emptyMap()).forEach((property, stringValue) -> builder.stringProperty(property, stringValue));
stateKeyInts.getOrDefault(key, Collections.emptyMap()).forEach((property, intValue) -> builder.intProperty(property, intValue));
stateKeyBools.getOrDefault(key, Collections.emptyMap()).forEach((property, boolValue) -> builder.booleanProperty(property, boolValue));
CustomBlockState blockState = builder.build();
states.put(key, blockState);
});
return states; return states;
} }
private BlockPropertyTypeMaps createBlockPropertyTypeMaps(List<String> stateKeys) { private void createCustomBlockStates(List<String> stateKeys, boolean defaultState, CustomBlockData customBlockData,
Map<String, Map<String, String>> stateKeyStrings, Map<String, Map<String, Integer>> stateKeyInts,
Map<String, Map<String, Boolean>> stateKeyBools, Map<String, CustomBlockState> states) {
stateKeys.forEach((key) -> {
CustomBlockState.Builder builder = customBlockData.blockStateBuilder();
builder.booleanProperty("geyser_custom:default", defaultState);
stateKeyStrings.getOrDefault(key, Collections.emptyMap()).forEach((property, stringValue) -> builder.stringProperty(property, stringValue));
stateKeyInts.getOrDefault(key, Collections.emptyMap()).forEach((property, intValue) -> builder.intProperty(property, intValue));
stateKeyBools.getOrDefault(key, Collections.emptyMap()).forEach((property, boolValue) -> builder.booleanProperty(property, boolValue));
CustomBlockState blockState = builder.build();
states.put(key, blockState);
});
}
private BlockPropertyTypeMaps createBlockPropertyTypeMaps(List<String> usedStateKeys) {
Map<String, LinkedHashSet<String>> stringValuesMap = new HashMap<>(); Map<String, LinkedHashSet<String>> stringValuesMap = new HashMap<>();
Map<String, Map<String, String>> stateKeyStrings = new HashMap<>(); Map<String, Map<String, String>> stateKeyStrings = new HashMap<>();
@ -285,13 +281,8 @@ public class MappingsReader_v1 extends MappingsReader {
Set<String> booleanValuesSet = new HashSet<>(); Set<String> booleanValuesSet = new HashSet<>();
Map<String, Map<String, Boolean>> stateKeyBools = new HashMap<>(); Map<String, Map<String, Boolean>> stateKeyBools = new HashMap<>();
for (String state : stateKeys) { for (String state : usedStateKeys) {
int openBracketIndex = state.indexOf("["); String[] pairs = splitStateString(state);
int closeBracketIndex = state.indexOf("]");
String cleanStates = state.substring(openBracketIndex + 1, closeBracketIndex);
String[] pairs = cleanStates.split("\\s*,\\s*");
for (String pair : pairs) { for (String pair : pairs) {
String[] parts = pair.split("="); String[] parts = pair.split("=");
@ -329,7 +320,11 @@ public class MappingsReader_v1 extends MappingsReader {
return new BlockPropertyTypeMaps(stringValuesMap, stateKeyStrings, intValuesMap, stateKeyInts, booleanValuesSet, stateKeyBools); return new BlockPropertyTypeMaps(stringValuesMap, stateKeyStrings, intValuesMap, stateKeyInts, booleanValuesSet, stateKeyBools);
} }
private CustomBlockComponents createCustomBlockComponents(JsonNode node) { private CustomBlockComponents createCustomBlockComponents(JsonNode node, String state, String identifier) {
String stateIdentifier = identifier + state;
int test = BlockRegistries.JAVA_IDENTIFIERS.getOrDefault(stateIdentifier, -1);
BlockUtils.getCollision(test);
CustomBlockComponentsBuilder builder = new CustomBlockComponentsBuilder(); CustomBlockComponentsBuilder builder = new CustomBlockComponentsBuilder();
builder builder
.geometry("geometry.some.geometry"); .geometry("geometry.some.geometry");
@ -354,8 +349,7 @@ public class MappingsReader_v1 extends MappingsReader {
} }
private String createCustomBlockPropertyQuery(String state) { private String createCustomBlockPropertyQuery(String state) {
String list = state.substring(1, state.length() - 1); String[] conditions = splitStateString(state);
String[] conditions = list.split(",");
String[] queries = new String[conditions.length]; String[] queries = new String[conditions.length];
for (int i = 0; i < conditions.length; i++) { for (int i = 0; i < conditions.length; i++) {
@ -376,4 +370,15 @@ public class MappingsReader_v1 extends MappingsReader {
return String.format("q.block_property('geyser_custom:default') == 0 && %s", query); return String.format("q.block_property('geyser_custom:default') == 0 && %s", query);
} }
private String[] splitStateString(String state) {
int openBracketIndex = state.indexOf("[");
int closeBracketIndex = state.indexOf("]");
String cleanStates = state.substring(openBracketIndex + 1, closeBracketIndex);
String[] pairs = cleanStates.split("\\s*,\\s*");
return pairs;
}
} }