diff options
author | Linnea Gräf <nea@nea.moe> | 2024-09-08 21:08:22 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-09-08 21:08:22 +0200 |
commit | ab809e197f3e8c9a51745ee9510bc65c952c0cc8 (patch) | |
tree | e5e5784ba03641bc4d1669fd470942fde1c1a262 /src/main | |
parent | c9aaaeed770efcc53992038c08ac188ee27d1671 (diff) | |
download | Firmament-ab809e197f3e8c9a51745ee9510bc65c952c0cc8.tar.gz Firmament-ab809e197f3e8c9a51745ee9510bc65c952c0cc8.tar.bz2 Firmament-ab809e197f3e8c9a51745ee9510bc65c952c0cc8.zip |
Add legacy cit resewn compat
Diffstat (limited to 'src/main')
3 files changed, 44 insertions, 2 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/MixinConditionComponents.java b/src/main/java/moe/nea/firmament/mixins/MixinConditionComponents.java index 8c33a6c..602c13d 100644 --- a/src/main/java/moe/nea/firmament/mixins/MixinConditionComponents.java +++ b/src/main/java/moe/nea/firmament/mixins/MixinConditionComponents.java @@ -2,12 +2,18 @@ package moe.nea.firmament.mixins; // People are complaining but this really is not my place to fix things +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.DynamicOps; +import moe.nea.firmament.features.texturepack.CustomSkyBlockTextures; import moe.nea.firmament.util.ConditionNBTMixin; import net.minecraft.component.ComponentType; import net.minecraft.component.DataComponentTypes; -import net.minecraft.nbt.NbtString; -import net.minecraft.text.Text; +import net.minecraft.component.type.NbtComponent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.Shadow; @@ -16,6 +22,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import shcm.shsupercm.fabric.citresewn.CITResewn; import shcm.shsupercm.fabric.citresewn.cit.CITContext; import shcm.shsupercm.fabric.citresewn.defaults.cit.conditions.ConditionComponents; import shcm.shsupercm.fabric.citresewn.defaults.cit.conditions.ConditionNBT; @@ -36,6 +43,26 @@ public class MixinConditionComponents { @Unique private int loreInt = -1; + @Inject(method = "load", at = @At("HEAD"), remap = false) + public void addExtraAttributeSupport(PropertyKey key, PropertyValue value, PropertyGroup properties, CallbackInfo ci, + @Local(argsOnly = true) LocalRef<PropertyKey> keyRef, + @Local(argsOnly = true) LocalRef<PropertyValue> valueRef) { + if (!CustomSkyBlockTextures.TConfig.INSTANCE.getEnableLegacyCIT()) return; + if (!"nbt".equals(key.path())) return; + if (!value.keyMetadata().startsWith("ExtraAttributes.")) return; + keyRef.set(new PropertyKey(key.namespace(), "component")); + valueRef.set(new PropertyValue( + "minecraft:custom_data" + value.keyMetadata().substring("ExtraAttributes".length()), + value.value(), + value.separator(), + value.position(), + value.propertiesIdentifier(), + value.packName() + )); + CITResewn.logWarnLoading(properties.messageWithDescriptorOf("NBT condition is not supported since 1.21. THIS IS A FIRMAMENT SPECIAL FEATURE ALLOWING YOU TO CONTINUE TO USE nbt.ExtraAttributes.* PROPERTIES FOR A LIMITED TIME! UPDATE YOUR .PROPERTIES FILES OR SWITCH TO FIRMAMENT CIT (https://github.com/FirmamentMC/CitToFirm)", + value.position())); + } + @Inject(method = "load", at = @At(value = "INVOKE", remap = false, target = "Lshcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionNBT;loadNbtCondition(Lshcm/shsupercm/fabric/citresewn/pack/format/PropertyValue;Lshcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup;[Ljava/lang/String;Ljava/lang/String;)V"), remap = false) @@ -45,10 +72,23 @@ public class MixinConditionComponents { this.loreInt = -1; } + @Unique private boolean matchStringDirect(String directString, CITContext context) { return ConditionNBTMixin.invokeDirectConditionNBTStringMatch(fallbackNBTCheck, directString); } + @WrapOperation(method = "test", at = @At(value = "INVOKE", target = "Lcom/mojang/serialization/Codec;encodeStart(Lcom/mojang/serialization/DynamicOps;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;"), remap = false) + DataResult fastPathUnsafeNbtComponent( + Codec instance, + DynamicOps dynamicOps, + Object o, + Operation<DataResult> original) { + if (o instanceof NbtComponent nbtComponent) { + return DataResult.success(nbtComponent.getNbt()); + } + return original.call(instance, dynamicOps, o); + } + @Inject(method = "test", at = @At("HEAD"), cancellable = true, remap = false) void fastPathDisplayName(CITContext context, CallbackInfoReturnable<Boolean> cir) { if (this.componentType == DataComponentTypes.CUSTOM_NAME && pathCheck.length == 0) { diff --git a/src/main/kotlin/features/texturepack/CustomSkyBlockTextures.kt b/src/main/kotlin/features/texturepack/CustomSkyBlockTextures.kt index dec6046..692f73b 100644 --- a/src/main/kotlin/features/texturepack/CustomSkyBlockTextures.kt +++ b/src/main/kotlin/features/texturepack/CustomSkyBlockTextures.kt @@ -30,6 +30,7 @@ object CustomSkyBlockTextures : FirmamentFeature { val enableModelOverrides by toggle("model-overrides") { true } val enableArmorOverrides by toggle("armor-overrides") { true } val enableBlockOverrides by toggle("block-overrides") { true } + val enableLegacyCIT by toggle("legacy-cit") { true } } override val config: ManagedConfig diff --git a/src/main/resources/assets/firmament/lang/en_us.json b/src/main/resources/assets/firmament/lang/en_us.json index 912c6e0..934aeb3 100644 --- a/src/main/resources/assets/firmament/lang/en_us.json +++ b/src/main/resources/assets/firmament/lang/en_us.json @@ -168,6 +168,7 @@ "firmament.config.custom-skyblock-textures": "Custom SkyBlock Item Textures", "firmament.config.custom-skyblock-textures.cache-duration": "Model Cache Duration", "firmament.config.custom-skyblock-textures.model-overrides": "Enable model overrides/predicates", + "firmament.config.custom-skyblock-textures.legacy-cit": "Enable legacy CIT Resewn compat", "firmament.config.custom-skyblock-textures.armor-overrides": "Enable Armor re-texturing", "firmament.config.custom-skyblock-textures.block-overrides": "Enable Block re-modelling", "firmament.config.custom-skyblock-textures.enabled": "Enable Custom Item Textures", |