mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Finish implementing select/match predicates
This commit is contained in:
@@ -4,7 +4,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
|||||||
import net.minecraft.client.renderer.item.ItemModel;
|
import net.minecraft.client.renderer.item.ItemModel;
|
||||||
|
|
||||||
// Implemented on BlockModelWrapper, since this class doesn't store the cases it has in a nice format, we have to store it manually
|
// Implemented on BlockModelWrapper, since this class doesn't store the cases it has in a nice format, we have to store it manually
|
||||||
public interface SelectItemModelCaseAccessor<T> {
|
public interface SelectItemModelCasesAccessor<T> {
|
||||||
|
|
||||||
Object2ObjectMap<T, ItemModel> geyser_mappings_generator$getCases();
|
Object2ObjectMap<T, ItemModel> geyser_mappings_generator$getCases();
|
||||||
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.geysermc.packgenerator.mappings;
|
package org.geysermc.packgenerator.mappings;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.item.BlockModelWrapper;
|
import net.minecraft.client.renderer.item.BlockModelWrapper;
|
||||||
import net.minecraft.client.renderer.item.ConditionalItemModel;
|
import net.minecraft.client.renderer.item.ConditionalItemModel;
|
||||||
@@ -16,8 +17,13 @@ import net.minecraft.client.renderer.item.properties.select.ContextDimension;
|
|||||||
import net.minecraft.client.renderer.item.properties.select.SelectItemModelProperty;
|
import net.minecraft.client.renderer.item.properties.select.SelectItemModelProperty;
|
||||||
import net.minecraft.client.renderer.item.properties.select.TrimMaterialProperty;
|
import net.minecraft.client.renderer.item.properties.select.TrimMaterialProperty;
|
||||||
import net.minecraft.core.component.DataComponentPatch;
|
import net.minecraft.core.component.DataComponentPatch;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.item.CrossbowItem;
|
||||||
|
import net.minecraft.world.item.equipment.trim.TrimMaterial;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
import org.geysermc.packgenerator.accessor.BlockModelWrapperLocationAccessor;
|
import org.geysermc.packgenerator.accessor.BlockModelWrapperLocationAccessor;
|
||||||
|
import org.geysermc.packgenerator.accessor.SelectItemModelCasesAccessor;
|
||||||
import org.geysermc.packgenerator.mappings.predicate.GeyserConditionPredicate;
|
import org.geysermc.packgenerator.mappings.predicate.GeyserConditionPredicate;
|
||||||
import org.geysermc.packgenerator.mappings.predicate.GeyserMatchPredicate;
|
import org.geysermc.packgenerator.mappings.predicate.GeyserMatchPredicate;
|
||||||
import org.geysermc.packgenerator.mappings.predicate.GeyserPredicate;
|
import org.geysermc.packgenerator.mappings.predicate.GeyserPredicate;
|
||||||
@@ -47,7 +53,7 @@ public class GeyserItemMapper {
|
|||||||
return mapConditionalModel(conditional, context);
|
return mapConditionalModel(conditional, context);
|
||||||
}
|
}
|
||||||
case SelectItemModel<?> select -> {
|
case SelectItemModel<?> select -> {
|
||||||
return Stream.of();
|
return mapSelectModel(select, context);
|
||||||
}
|
}
|
||||||
default -> {}
|
default -> {}
|
||||||
}
|
}
|
||||||
@@ -78,11 +84,21 @@ public class GeyserItemMapper {
|
|||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
SelectItemModelProperty<T> property = ((SelectItemModelAccessor<T>) model).getProperty();
|
SelectItemModelProperty<T> property = ((SelectItemModelAccessor<T>) model).getProperty();
|
||||||
Function<T, GeyserMatchPredicate.MatchPredicateData> dataConstructor = switch (property) {
|
Function<T, GeyserMatchPredicate.MatchPredicateData> dataConstructor = switch (property) {
|
||||||
case Charge ignored -> t -> new GeyserMatchPredicate.ChargeType(t);
|
case Charge ignored -> chargeType -> new GeyserMatchPredicate.ChargeType((CrossbowItem.ChargeType) chargeType);
|
||||||
case TrimMaterialProperty trimMaterial -> ;
|
case TrimMaterialProperty ignored -> material -> new GeyserMatchPredicate.TrimMaterialData((ResourceKey<TrimMaterial>) material);
|
||||||
case ContextDimension contextDimension -> ;
|
case ContextDimension ignored -> dimension -> new GeyserMatchPredicate.ContextDimension((ResourceKey<Level>) dimension);
|
||||||
case net.minecraft.client.renderer.item.properties.select.CustomModelDataProperty customModelData -> ; // Why, Mojang?
|
// Why, Mojang?
|
||||||
}
|
case net.minecraft.client.renderer.item.properties.select.CustomModelDataProperty customModelData -> string -> new GeyserMatchPredicate.CustomModelData((String) string, customModelData.index());
|
||||||
|
default -> throw new UnsupportedOperationException("Unsupported select model property " + property.getClass());
|
||||||
|
};
|
||||||
|
|
||||||
|
//noinspection unchecked
|
||||||
|
Object2ObjectMap<T, ItemModel> cases = ((SelectItemModelCasesAccessor<T>) model).geyser_mappings_generator$getCases();
|
||||||
|
return Stream.concat(
|
||||||
|
cases.entrySet().stream()
|
||||||
|
.flatMap(caze -> mapItem(caze.getValue(), context.with(new GeyserMatchPredicate(dataConstructor.apply(caze.getKey()))))),
|
||||||
|
mapItem(cases.defaultReturnValue(), context)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private record MappingContext(List<GeyserPredicate> predicateStack, ResourceLocation model, String displayName, int protectionValue, DataComponentPatch componentPatch) {
|
private record MappingContext(List<GeyserPredicate> predicateStack, ResourceLocation model, String displayName, int protectionValue, DataComponentPatch componentPatch) {
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ package org.geysermc.packgenerator.mappings.predicate;
|
|||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.MapCodec;
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.util.ExtraCodecs;
|
import net.minecraft.util.ExtraCodecs;
|
||||||
import net.minecraft.util.StringRepresentable;
|
import net.minecraft.util.StringRepresentable;
|
||||||
import net.minecraft.world.item.CrossbowItem;
|
import net.minecraft.world.item.CrossbowItem;
|
||||||
|
import net.minecraft.world.item.equipment.trim.TrimMaterial;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -28,7 +31,7 @@ public record GeyserMatchPredicate(MatchPredicateData data) implements GeyserPre
|
|||||||
|
|
||||||
enum Type implements StringRepresentable {
|
enum Type implements StringRepresentable {
|
||||||
CHARGE_TYPE("charge_type", ChargeType.CODEC),
|
CHARGE_TYPE("charge_type", ChargeType.CODEC),
|
||||||
TRIM_MATERIAL("trim_material", TrimMaterial.CODEC),
|
TRIM_MATERIAL("trim_material", TrimMaterialData.CODEC),
|
||||||
CONTEXT_DIMENSION("context_dimension", ContextDimension.CODEC),
|
CONTEXT_DIMENSION("context_dimension", ContextDimension.CODEC),
|
||||||
CUSTOM_MODEL_DATA("custom_model_data", CustomModelData.CODEC);
|
CUSTOM_MODEL_DATA("custom_model_data", CustomModelData.CODEC);
|
||||||
|
|
||||||
@@ -62,9 +65,8 @@ public record GeyserMatchPredicate(MatchPredicateData data) implements GeyserPre
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO might change into ResourceKey?
|
public record TrimMaterialData(ResourceKey<TrimMaterial> material) implements MatchPredicateData {
|
||||||
public record TrimMaterial(ResourceLocation material) implements MatchPredicateData {
|
public static final MapCodec<TrimMaterialData> CODEC = simpleCodec(ResourceKey.codec(Registries.TRIM_MATERIAL), TrimMaterialData::material, TrimMaterialData::new);
|
||||||
public static final MapCodec<TrimMaterial> CODEC = simpleCodec(ResourceLocation.CODEC, TrimMaterial::material, TrimMaterial::new);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type type() {
|
public Type type() {
|
||||||
@@ -72,9 +74,8 @@ public record GeyserMatchPredicate(MatchPredicateData data) implements GeyserPre
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO might change into ResourceKey?
|
public record ContextDimension(ResourceKey<Level> level) implements MatchPredicateData {
|
||||||
public record ContextDimension(ResourceLocation dimension) implements MatchPredicateData {
|
public static final MapCodec<ContextDimension> CODEC = simpleCodec(ResourceKey.codec(Registries.DIMENSION), ContextDimension::level, ContextDimension::new);
|
||||||
public static final MapCodec<ContextDimension> CODEC = simpleCodec(ResourceLocation.CODEC, ContextDimension::dimension, ContextDimension::new);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type type() {
|
public Type type() {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
|||||||
import net.minecraft.client.renderer.item.ItemModel;
|
import net.minecraft.client.renderer.item.ItemModel;
|
||||||
import net.minecraft.client.renderer.item.SelectItemModel;
|
import net.minecraft.client.renderer.item.SelectItemModel;
|
||||||
import net.minecraft.client.renderer.item.properties.select.SelectItemModelProperty;
|
import net.minecraft.client.renderer.item.properties.select.SelectItemModelProperty;
|
||||||
import org.geysermc.packgenerator.accessor.SelectItemModelCaseAccessor;
|
import org.geysermc.packgenerator.accessor.SelectItemModelCasesAccessor;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
@Mixin(SelectItemModel.class)
|
@Mixin(SelectItemModel.class)
|
||||||
public abstract class SelectItemModelMixin<T> implements ItemModel, SelectItemModelCaseAccessor<T> {
|
public abstract class SelectItemModelMixin<T> implements ItemModel, SelectItemModelCasesAccessor<T> {
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private Object2ObjectMap<T, ItemModel> cases;
|
private Object2ObjectMap<T, ItemModel> cases;
|
||||||
@@ -35,7 +35,7 @@ public abstract class SelectItemModelMixin<T> implements ItemModel, SelectItemMo
|
|||||||
public void setCases(BakingContext bakingContext, ItemModel model, CallbackInfoReturnable<ItemModel> callbackInfoReturnable,
|
public void setCases(BakingContext bakingContext, ItemModel model, CallbackInfoReturnable<ItemModel> callbackInfoReturnable,
|
||||||
@Local Object2ObjectMap<T, ItemModel> cases) {
|
@Local Object2ObjectMap<T, ItemModel> cases) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
((SelectItemModelCaseAccessor<T>) callbackInfoReturnable.getReturnValue()).geyser_mappings_generator$setCases(cases);
|
((SelectItemModelCasesAccessor<T>) callbackInfoReturnable.getReturnValue()).geyser_mappings_generator$setCases(cases);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user