Skip to content

Commit 2a34282

Browse files
Implement mapping of range dispatch models (#7)
2 parents 0cecce8 + c8caa26 commit 2a34282

15 files changed

+260
-261
lines changed

src/main/java/org/geysermc/rainbow/accessor/BlockModelWrapperLocationAccessor.java

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package org.geysermc.rainbow.accessor;
22

3+
import net.minecraft.client.renderer.item.ClientItem;
34
import net.minecraft.client.resources.model.ResolvedModel;
45
import net.minecraft.resources.ResourceLocation;
56

67
import java.util.Optional;
78

8-
// Implemented on ModelManager, since this class doesn't keep the resolved models after baking, we have to store it manually
9+
// Implemented on ModelManager, since this class doesn't keep the resolved models or unbaked client items after baking, we have to store them manually.
10+
// This comes with some extra memory usage, but Rainbow should only be used to convert packs, so it should be fine
911
public interface ResolvedModelAccessor {
1012

1113
Optional<ResolvedModel> rainbow$getResolvedModel(ResourceLocation location);
14+
15+
Optional<ClientItem> rainbow$getClientItem(ResourceLocation location);
1216
}

src/main/java/org/geysermc/rainbow/accessor/SelectItemModelCasesAccessor.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/java/org/geysermc/rainbow/mapping/BedrockItemMapper.java

Lines changed: 127 additions & 85 deletions
Large diffs are not rendered by default.

src/main/java/org/geysermc/rainbow/mapping/geyser/predicate/GeyserConditionPredicate.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ public MapCodec<? extends Property> codec() {
6464
}
6565

6666
public record CustomModelData(int index) implements Property {
67-
public static final MapCodec<CustomModelData> CODEC = RecordCodecBuilder.mapCodec(instance ->
68-
instance.group(
69-
ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("index", 0).forGetter(CustomModelData::index)
70-
).apply(instance, CustomModelData::new)
71-
);
67+
public static final MapCodec<CustomModelData> CODEC = ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("index", 0).xmap(CustomModelData::new, CustomModelData::index);
7268

7369
@Override
7470
public Type type() {
@@ -77,11 +73,7 @@ public Type type() {
7773
}
7874

7975
public record HasComponent(DataComponentType<?> component) implements Property {
80-
public static final MapCodec<HasComponent> CODEC = RecordCodecBuilder.mapCodec(instance ->
81-
instance.group(
82-
DataComponentType.CODEC.fieldOf("component").forGetter(HasComponent::component)
83-
).apply(instance, HasComponent::new)
84-
);
76+
public static final MapCodec<HasComponent> CODEC = DataComponentType.CODEC.fieldOf("component").xmap(HasComponent::new, HasComponent::component);
8577

8678
@Override
8779
public Type type() {

src/main/java/org/geysermc/rainbow/mapping/geyser/predicate/GeyserPredicate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public interface GeyserPredicate {
1717

1818
enum Type implements StringRepresentable {
1919
CONDITION("condition", GeyserConditionPredicate.CODEC),
20-
MATCH("match", GeyserMatchPredicate.CODEC);
20+
MATCH("match", GeyserMatchPredicate.CODEC),
21+
RANGE_DISPATCH("range_dispatch", GeyserRangeDispatchPredicate.CODEC);
2122

2223
public static final Codec<Type> CODEC = StringRepresentable.fromEnum(Type::values);
2324

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.geysermc.rainbow.mapping.geyser.predicate;
2+
3+
import com.google.common.base.Suppliers;
4+
import com.mojang.serialization.Codec;
5+
import com.mojang.serialization.MapCodec;
6+
import com.mojang.serialization.codecs.RecordCodecBuilder;
7+
import net.minecraft.util.ExtraCodecs;
8+
import net.minecraft.util.StringRepresentable;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
import java.util.function.Supplier;
12+
13+
public record GeyserRangeDispatchPredicate(Property property, float threshold, float scale) implements GeyserPredicate {
14+
15+
public static final MapCodec<GeyserRangeDispatchPredicate> CODEC = RecordCodecBuilder.mapCodec(instance ->
16+
instance.group(
17+
Property.CODEC.forGetter(GeyserRangeDispatchPredicate::property),
18+
Codec.FLOAT.fieldOf("threshold").forGetter(GeyserRangeDispatchPredicate::threshold),
19+
Codec.FLOAT.fieldOf("scale").forGetter(GeyserRangeDispatchPredicate::scale)
20+
).apply(instance, GeyserRangeDispatchPredicate::new)
21+
);
22+
23+
public static final Property BUNDLE_FULLNESS = unit(Property.Type.BUNDLE_FULLNESS);
24+
25+
@Override
26+
public Type type() {
27+
return null;
28+
}
29+
30+
public interface Property {
31+
32+
MapCodec<Property> CODEC = Type.CODEC.dispatchMap("property", Property::type, Type::codec);
33+
34+
Type type();
35+
36+
enum Type implements StringRepresentable {
37+
BUNDLE_FULLNESS("bundle_fullness", () -> MapCodec.unit(GeyserRangeDispatchPredicate.BUNDLE_FULLNESS)),
38+
DAMAGE("damage", () -> Damage.CODEC),
39+
COUNT("count", () -> Count.CODEC),
40+
CUSTOM_MODEL_DATA("custom_model_data", () -> CustomModelData.CODEC);
41+
42+
public static final Codec<Type> CODEC = StringRepresentable.fromEnum(Type::values);
43+
44+
private final String name;
45+
private final Supplier<MapCodec<? extends Property>> codec;
46+
47+
Type(String name, Supplier<MapCodec<? extends Property>> codec) {
48+
this.name = name;
49+
this.codec = Suppliers.memoize(codec::get);
50+
}
51+
52+
public MapCodec<? extends Property> codec() {
53+
return codec.get();
54+
}
55+
56+
@Override
57+
public @NotNull String getSerializedName() {
58+
return name;
59+
}
60+
}
61+
}
62+
63+
public record Damage(boolean normalize) implements Property {
64+
public static final MapCodec<Damage> CODEC = Codec.BOOL.fieldOf("normalize").xmap(Damage::new, Damage::normalize);
65+
66+
@Override
67+
public Type type() {
68+
return Type.DAMAGE;
69+
}
70+
}
71+
72+
public record Count(boolean normalize) implements Property {
73+
public static final MapCodec<Count> CODEC = Codec.BOOL.fieldOf("normalize").xmap(Count::new, Count::normalize);
74+
75+
@Override
76+
public Type type() {
77+
return Type.COUNT;
78+
}
79+
}
80+
81+
public record CustomModelData(int index) implements Property {
82+
public static final MapCodec<CustomModelData> CODEC = ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("index", 0).xmap(CustomModelData::new, CustomModelData::index);
83+
84+
@Override
85+
public Type type() {
86+
return Type.CUSTOM_MODEL_DATA;
87+
}
88+
}
89+
90+
private static Property unit(Property.Type type) {
91+
return () -> type;
92+
}
93+
}

src/main/java/org/geysermc/rainbow/mixin/BlockModelWrapperMixin.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/main/java/org/geysermc/rainbow/mixin/ConditionalItemModelAccessor.java

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.geysermc.rainbow.mixin;
2+
3+
import com.google.common.collect.BiMap;
4+
import net.minecraft.util.ExtraCodecs;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.gen.Accessor;
7+
8+
@Mixin(ExtraCodecs.LateBoundIdMapper.class)
9+
public interface LateBoundIdMapperAccessor<I, V> {
10+
11+
@Accessor
12+
BiMap<I, V> getIdToValue();
13+
}

0 commit comments

Comments
 (0)