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

Clean up custom block api a bit

Dieser Commit ist enthalten in:
davchoo 2022-07-10 12:26:52 -04:00
Ursprung 08c24cb462
Commit 86c822631c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: A0168C8E45799B7D
8 geänderte Dateien mit 35 neuen und 45 gelöschten Zeilen

Datei anzeigen

@ -53,13 +53,12 @@ public interface CustomBlockData {
Builder components(@NonNull CustomBlockComponents components);
Builder booleanProperty(@NonNull String propertyName, List<Boolean> values);
Builder booleanProperty(@NonNull String propertyName);
Builder intProperty(@NonNull String propertyName, List<Integer> values);
Builder stringProperty(@NonNull String propertyName, List<String> values);
Builder permutations(@NonNull List<CustomBlockPermutation> permutations);
CustomBlockData build();

Datei anzeigen

@ -30,6 +30,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Map;
public interface CustomBlockState {
@NonNull CustomBlockData block();
@NonNull String name();
@NonNull <T> T property(String propertyName);

Datei anzeigen

@ -34,5 +34,5 @@ public interface CustomBlockProperty<T> {
@NonNull List<T> values();
@NonNull PropertyType<T> type();
@NonNull PropertyType type();
}

Datei anzeigen

@ -25,18 +25,17 @@
package org.geysermc.geyser.api.block.custom.property;
public class PropertyType<T> {
public static final PropertyType<Boolean> BOOLEAN = new PropertyType<>(Boolean.class);
public static final PropertyType<Integer> INTEGER = new PropertyType<>(Integer.class);
public static final PropertyType<String> STRING = new PropertyType<>(String.class);
import lombok.Getter;
public class PropertyType {
public static final PropertyType BOOLEAN = new PropertyType(Boolean.class);
public static final PropertyType INTEGER = new PropertyType(Integer.class);
public static final PropertyType STRING = new PropertyType(String.class);
@Getter
private final Class<?> typeClass;
private PropertyType(Class<?> typeClass) {
this.typeClass = typeClass;
}
public Class<?> getTypeClass() {
return typeClass;
}
}

Datei anzeigen

@ -28,6 +28,8 @@ package org.geysermc.geyser.level.block;
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectLists;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Value;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.block.custom.CustomBlockData;
@ -41,7 +43,11 @@ import java.util.List;
import java.util.Map;
@Value
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class GeyserCustomBlockData implements CustomBlockData {
public static final String GEYSER_NAMESPACE = "geyser:";
String name;
CustomBlockComponents components;
Map<String, CustomBlockProperty<?>> properties;
@ -54,7 +60,7 @@ public class GeyserCustomBlockData implements CustomBlockData {
@Override
public @NonNull String identifier() {
return "geyser:" + name;
return GEYSER_NAMESPACE + name;
}
@Override
@ -96,8 +102,8 @@ public class GeyserCustomBlockData implements CustomBlockData {
}
@Override
public Builder booleanProperty(@NonNull String propertyName, List<Boolean> values) {
this.properties.put(propertyName, new GeyserCustomBlockProperty<>(propertyName, values, PropertyType.BOOLEAN));
public Builder booleanProperty(@NonNull String propertyName) {
this.properties.put(propertyName, new GeyserCustomBlockProperty<>(propertyName, List.of(false, true), PropertyType.BOOLEAN));
return this;
}
@ -131,6 +137,9 @@ public class GeyserCustomBlockData implements CustomBlockData {
if (property.values().isEmpty() || property.values().size() > 16) {
throw new IllegalArgumentException(property.name() + " must contain 1 to 16 values.");
}
if (property.values().stream().distinct().count() != property.values().size()) {
throw new IllegalArgumentException(property.name() + " has duplicate values.");
}
}
}
if (permutations == null) {

Datei anzeigen

@ -31,30 +31,6 @@ import org.geysermc.geyser.api.block.custom.property.PropertyType;
import java.util.List;
public class GeyserCustomBlockProperty<T> implements CustomBlockProperty<T> {
private final String name;
private final List<T> values;
private final PropertyType<T> type;
public GeyserCustomBlockProperty(String name, List<T> values, PropertyType<T> type) {
this.name = name;
this.values = values;
this.type = type;
}
@Override
public @NonNull String name() {
return name;
}
@Override
public @NonNull List<T> values(){
return values;
}
@Override
public @NonNull PropertyType<T> type() {
return type;
}
public record GeyserCustomBlockProperty<T>(@NonNull String name, @NonNull List<T> values,
@NonNull PropertyType type) implements CustomBlockProperty<T> {
}

Datei anzeigen

@ -39,12 +39,17 @@ import java.util.Map;
@Value
public class GeyserCustomBlockState implements CustomBlockState {
String name;
CustomBlockData block;
Map<String, Object> properties;
@Override
public @NonNull CustomBlockData block() {
return block;
}
@Override
public @NonNull String name() {
return name;
return block.name();
}
@SuppressWarnings("unchecked")
@ -97,11 +102,11 @@ public class GeyserCustomBlockState implements CustomBlockState {
if (property == null) {
throw new IllegalArgumentException("Unknown property: " + propertyName);
} else if (!property.values().contains(propertyValue)) {
throw new IllegalArgumentException("Invalid value for property: " + propertyName + " Value: " + propertyValue);
throw new IllegalArgumentException("Invalid value: " + propertyValue + " for property: " + propertyName);
}
}
return new GeyserCustomBlockState(blockData.name(), Object2ObjectMaps.unmodifiable(properties));
return new GeyserCustomBlockState(blockData, Object2ObjectMaps.unmodifiable(properties));
}
}
}

Datei anzeigen

@ -135,7 +135,7 @@ public class BlockRegistryPopulator {
.putInt("version", stateVersion)
.putCompound("states", states)
.build());
customExtBlockStates.add(new GeyserCustomBlockState(customBlock.name(), states));
customExtBlockStates.add(new GeyserCustomBlockState(customBlock, states));
}
}