mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Add codecs for GeyserRangeDispatchPredicate
This commit is contained in:
@@ -117,6 +117,7 @@ public class BedrockItemMapper {
|
|||||||
switch (model) {
|
switch (model) {
|
||||||
case BlockModelWrapper.Unbaked modelWrapper -> mapBlockModelWrapper(modelWrapper, context.child("plain model " + modelWrapper.model()));
|
case BlockModelWrapper.Unbaked modelWrapper -> mapBlockModelWrapper(modelWrapper, context.child("plain model " + modelWrapper.model()));
|
||||||
case ConditionalItemModel.Unbaked conditional -> mapConditionalModel(conditional, context.child("condition model "));
|
case ConditionalItemModel.Unbaked conditional -> mapConditionalModel(conditional, context.child("condition model "));
|
||||||
|
case RangeSelectItemModel.Unbaked rangeSelect -> mapRangeSelectModel(rangeSelect, context.child("range select model "));
|
||||||
case SelectItemModel.Unbaked select -> mapSelectModel(select, context.child("select model "));
|
case SelectItemModel.Unbaked select -> mapSelectModel(select, context.child("select model "));
|
||||||
default -> context.reporter.report(() -> "unsupported item model " + getModelId(model));
|
default -> context.reporter.report(() -> "unsupported item model " + getModelId(model));
|
||||||
}
|
}
|
||||||
@@ -186,6 +187,10 @@ public class BedrockItemMapper {
|
|||||||
mapItem(onFalse, context.with(new GeyserConditionPredicate(predicateProperty, false), "condition on false "));
|
mapItem(onFalse, context.with(new GeyserConditionPredicate(predicateProperty, false), "condition on false "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void mapRangeSelectModel(RangeSelectItemModel.Unbaked model, MappingContext context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void mapSelectModel(SelectItemModel.Unbaked model, MappingContext context) {
|
private static void mapSelectModel(SelectItemModel.Unbaked model, MappingContext context) {
|
||||||
SelectItemModel.UnbakedSwitch<?, ?> unbakedSwitch = model.unbakedSwitch();
|
SelectItemModel.UnbakedSwitch<?, ?> unbakedSwitch = model.unbakedSwitch();
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ public interface GeyserPredicate {
|
|||||||
|
|
||||||
enum Type implements StringRepresentable {
|
enum Type implements StringRepresentable {
|
||||||
CONDITION("condition", GeyserConditionPredicate.CODEC),
|
CONDITION("condition", GeyserConditionPredicate.CODEC),
|
||||||
MATCH("match", GeyserMatchPredicate.CODEC);
|
MATCH("match", GeyserMatchPredicate.CODEC),
|
||||||
|
RANGE_DISPATCH("range_dispatch", GeyserRangeDispatchPredicate.CODEC);
|
||||||
|
|
||||||
public static final Codec<Type> CODEC = StringRepresentable.fromEnum(Type::values);
|
public static final Codec<Type> CODEC = StringRepresentable.fromEnum(Type::values);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package org.geysermc.rainbow.mapping.geyser.predicate;
|
||||||
|
|
||||||
|
import com.google.common.base.Suppliers;
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.MapCodec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
|
import net.minecraft.util.ExtraCodecs;
|
||||||
|
import net.minecraft.util.StringRepresentable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public record GeyserRangeDispatchPredicate(Property property, float threshold, float scale, boolean normalise) implements GeyserPredicate {
|
||||||
|
|
||||||
|
public static final MapCodec<GeyserRangeDispatchPredicate> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||||
|
instance.group(
|
||||||
|
Property.CODEC.forGetter(GeyserRangeDispatchPredicate::property),
|
||||||
|
Codec.FLOAT.fieldOf("threshold").forGetter(GeyserRangeDispatchPredicate::threshold),
|
||||||
|
Codec.FLOAT.fieldOf("scale").forGetter(GeyserRangeDispatchPredicate::scale),
|
||||||
|
Codec.BOOL.fieldOf("normalize").forGetter(GeyserRangeDispatchPredicate::normalise)
|
||||||
|
).apply(instance, GeyserRangeDispatchPredicate::new)
|
||||||
|
);
|
||||||
|
|
||||||
|
public static final Property BUNDLE_FULLNESS = unit(Property.Type.BUNDLE_FULLNESS);
|
||||||
|
public static final Property DAMAGE = unit(Property.Type.DAMAGE);
|
||||||
|
public static final Property COUNT = unit(Property.Type.COUNT);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type type() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Property {
|
||||||
|
|
||||||
|
MapCodec<Property> CODEC = Type.CODEC.dispatchMap("property", Property::type, Type::codec);
|
||||||
|
|
||||||
|
Type type();
|
||||||
|
|
||||||
|
enum Type implements StringRepresentable {
|
||||||
|
BUNDLE_FULLNESS("bundle_fullness", () -> MapCodec.unit(GeyserRangeDispatchPredicate.BUNDLE_FULLNESS)),
|
||||||
|
DAMAGE("damage", () -> MapCodec.unit(GeyserRangeDispatchPredicate.DAMAGE)),
|
||||||
|
COUNT("count", () -> MapCodec.unit(GeyserRangeDispatchPredicate.COUNT)),
|
||||||
|
CUSTOM_MODEL_DATA("custom_model_data", () -> CustomModelData.CODEC);
|
||||||
|
|
||||||
|
public static final Codec<Type> CODEC = StringRepresentable.fromEnum(Type::values);
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final Supplier<MapCodec<? extends Property>> codec;
|
||||||
|
|
||||||
|
Type(String name, Supplier<MapCodec<? extends Property>> codec) {
|
||||||
|
this.name = name;
|
||||||
|
this.codec = Suppliers.memoize(codec::get);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapCodec<? extends Property> codec() {
|
||||||
|
return codec.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getSerializedName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record CustomModelData(int index) implements Property {
|
||||||
|
public static final MapCodec<CustomModelData> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||||
|
instance.group(
|
||||||
|
ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("index", 0).forGetter(CustomModelData::index)
|
||||||
|
).apply(instance, CustomModelData::new)
|
||||||
|
);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type type() {
|
||||||
|
return Type.CUSTOM_MODEL_DATA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Property unit(Property.Type type) {
|
||||||
|
return () -> type;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,12 +3,11 @@
|
|||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "org.geysermc.rainbow.mixin",
|
"package": "org.geysermc.rainbow.mixin",
|
||||||
"compatibilityLevel": "JAVA_21",
|
"compatibilityLevel": "JAVA_21",
|
||||||
"mixins": [
|
"mixins": [],
|
||||||
"LateBoundIdMapperAccessor"
|
|
||||||
],
|
|
||||||
"client": [
|
"client": [
|
||||||
"EntityRenderDispatcherAccessor",
|
"EntityRenderDispatcherAccessor",
|
||||||
"GuiItemRenderStateMixin",
|
"GuiItemRenderStateMixin",
|
||||||
|
"LateBoundIdMapperAccessor",
|
||||||
"ModelManagerMixin",
|
"ModelManagerMixin",
|
||||||
"PictureInPictureRendererAccessor",
|
"PictureInPictureRendererAccessor",
|
||||||
"PictureInPictureRendererMixin",
|
"PictureInPictureRendererMixin",
|
||||||
|
|||||||
Reference in New Issue
Block a user