1
0
mirror of https://github.com/GeyserMC/Rainbow.git synced 2026-01-04 15:31:39 +00:00

Implement range dispatch predicate mapping

This commit is contained in:
Eclipse
2025-10-13 15:37:33 +00:00
parent 7059cdfc24
commit c8caa26ed0
3 changed files with 47 additions and 22 deletions

View File

@@ -14,6 +14,9 @@ import net.minecraft.client.renderer.item.properties.conditional.Damaged;
import net.minecraft.client.renderer.item.properties.conditional.FishingRodCast;
import net.minecraft.client.renderer.item.properties.conditional.HasComponent;
import net.minecraft.client.renderer.item.properties.conditional.ItemModelPropertyTest;
import net.minecraft.client.renderer.item.properties.numeric.BundleFullness;
import net.minecraft.client.renderer.item.properties.numeric.Count;
import net.minecraft.client.renderer.item.properties.numeric.Damage;
import net.minecraft.client.renderer.item.properties.numeric.RangeSelectItemModelProperty;
import net.minecraft.client.renderer.item.properties.select.Charge;
import net.minecraft.client.renderer.item.properties.select.ContextDimension;
@@ -49,6 +52,7 @@ import org.geysermc.rainbow.mapping.geyser.GeyserSingleDefinition;
import org.geysermc.rainbow.mapping.geyser.predicate.GeyserConditionPredicate;
import org.geysermc.rainbow.mapping.geyser.predicate.GeyserMatchPredicate;
import org.geysermc.rainbow.mapping.geyser.predicate.GeyserPredicate;
import org.geysermc.rainbow.mapping.geyser.predicate.GeyserRangeDispatchPredicate;
import org.geysermc.rainbow.mixin.LateBoundIdMapperAccessor;
import org.geysermc.rainbow.mixin.RangeSelectItemModelAccessor;
import org.geysermc.rainbow.mixin.TextureSlotsAccessor;
@@ -188,7 +192,25 @@ public class BedrockItemMapper {
}
private static void mapRangeSelectModel(RangeSelectItemModel.Unbaked model, MappingContext context) {
RangeSelectItemModelProperty property = model.property();
GeyserRangeDispatchPredicate.Property predicateProperty = switch (property) {
case BundleFullness ignored -> GeyserRangeDispatchPredicate.BUNDLE_FULLNESS;
case Count count -> new GeyserRangeDispatchPredicate.Count(count.normalize());
// Mojang, why? :(
case net.minecraft.client.renderer.item.properties.numeric.CustomModelDataProperty customModelData -> new GeyserRangeDispatchPredicate.CustomModelData(customModelData.index());
case Damage damage -> new GeyserRangeDispatchPredicate.Damage(damage.normalize());
default -> null;
};
if (predicateProperty == null) {
context.reporter.report(() -> "unsupported range dispatch model property " + property + ", only mapping fallback, if it is present");
} else {
for (RangeSelectItemModel.Entry entry : model.entries()) {
mapItem(entry.model(), context.with(new GeyserRangeDispatchPredicate(predicateProperty, entry.threshold(), model.scale()), "threshold " + entry.threshold()));
}
}
model.fallback().ifPresent(fallback -> mapItem(fallback, context.child("range dispatch fallback")));
}
@SuppressWarnings("unchecked")

View File

@@ -64,11 +64,7 @@ public record GeyserConditionPredicate(Property property, boolean expected) impl
}
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)
);
public static final MapCodec<CustomModelData> CODEC = ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("index", 0).xmap(CustomModelData::new, CustomModelData::index);
@Override
public Type type() {
@@ -77,11 +73,7 @@ public record GeyserConditionPredicate(Property property, boolean expected) impl
}
public record HasComponent(DataComponentType<?> component) implements Property {
public static final MapCodec<HasComponent> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
DataComponentType.CODEC.fieldOf("component").forGetter(HasComponent::component)
).apply(instance, HasComponent::new)
);
public static final MapCodec<HasComponent> CODEC = DataComponentType.CODEC.fieldOf("component").xmap(HasComponent::new, HasComponent::component);
@Override
public Type type() {

View File

@@ -10,20 +10,17 @@ import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
public record GeyserRangeDispatchPredicate(Property property, float threshold, float scale, boolean normalise) implements GeyserPredicate {
public record GeyserRangeDispatchPredicate(Property property, float threshold, float scale) 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)
Codec.FLOAT.fieldOf("scale").forGetter(GeyserRangeDispatchPredicate::scale)
).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() {
@@ -38,8 +35,8 @@ public record GeyserRangeDispatchPredicate(Property property, float threshold, f
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)),
DAMAGE("damage", () -> Damage.CODEC),
COUNT("count", () -> Count.CODEC),
CUSTOM_MODEL_DATA("custom_model_data", () -> CustomModelData.CODEC);
public static final Codec<Type> CODEC = StringRepresentable.fromEnum(Type::values);
@@ -63,12 +60,26 @@ public record GeyserRangeDispatchPredicate(Property property, float threshold, f
}
}
public record Damage(boolean normalize) implements Property {
public static final MapCodec<Damage> CODEC = Codec.BOOL.fieldOf("normalize").xmap(Damage::new, Damage::normalize);
@Override
public Type type() {
return Type.DAMAGE;
}
}
public record Count(boolean normalize) implements Property {
public static final MapCodec<Count> CODEC = Codec.BOOL.fieldOf("normalize").xmap(Count::new, Count::normalize);
@Override
public Type type() {
return Type.COUNT;
}
}
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)
);
public static final MapCodec<CustomModelData> CODEC = ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("index", 0).xmap(CustomModelData::new, CustomModelData::index);
@Override
public Type type() {