diff options
author | Linnea Gräf <nea@nea.moe> | 2024-09-08 20:51:26 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-09-08 20:51:57 +0200 |
commit | c9aaaeed770efcc53992038c08ac188ee27d1671 (patch) | |
tree | 22c5ed2bb7c1f3666d0cc9ce590873c3b957a10d /src/main/java/moe/nea/firmament/mixins | |
parent | 26461deda4dc8695dacedefe50d976eb5e3d7714 (diff) | |
download | Firmament-c9aaaeed770efcc53992038c08ac188ee27d1671.tar.gz Firmament-c9aaaeed770efcc53992038c08ac188ee27d1671.tar.bz2 Firmament-c9aaaeed770efcc53992038c08ac188ee27d1671.zip |
Fix cit resewn
Diffstat (limited to 'src/main/java/moe/nea/firmament/mixins')
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/MixinConditionComponents.java | 83 | ||||
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java | 4 |
2 files changed, 85 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 new file mode 100644 index 0000000..8c33a6c --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/MixinConditionComponents.java @@ -0,0 +1,83 @@ +package moe.nea.firmament.mixins; + +// People are complaining but this really is not my place to fix things + +import com.llamalad7.mixinextras.sugar.Local; +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 org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +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.cit.CITContext; +import shcm.shsupercm.fabric.citresewn.defaults.cit.conditions.ConditionComponents; +import shcm.shsupercm.fabric.citresewn.defaults.cit.conditions.ConditionNBT; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyKey; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; + +@Mixin(ConditionComponents.class) +@Pseudo +public class MixinConditionComponents { + @Shadow + private ComponentType<?> componentType; + + @Shadow(remap = false) + private ConditionNBT fallbackNBTCheck; + @Unique + private String[] pathCheck; + @Unique + private int loreInt = -1; + + @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) + private void onLoadSavePath(PropertyKey key, PropertyValue value, PropertyGroup properties, CallbackInfo ci, + @Local String[] path) { + this.pathCheck = path; + this.loreInt = -1; + } + + private boolean matchStringDirect(String directString, CITContext context) { + return ConditionNBTMixin.invokeDirectConditionNBTStringMatch(fallbackNBTCheck, directString); + } + + @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) { + var displayName = context.stack.getComponents().get(DataComponentTypes.CUSTOM_NAME); + if (displayName != null) { + cir.setReturnValue(matchStringDirect((displayName.getString()), context)); + } + } + if (this.componentType == DataComponentTypes.LORE && pathCheck.length == 1) { + var lore = context.stack.getComponents().get(DataComponentTypes.LORE); + if (lore != null) { + var loreLines = lore.lines(); + if (pathCheck[0].equals("*")) { + for (var loreLine : loreLines) { + if (matchStringDirect((loreLine.getString()), context)) { + cir.setReturnValue(true); + return; + } + } + cir.setReturnValue(false); + } else { + if (loreInt < 0) + loreInt = Integer.parseInt(pathCheck[0]); + cir.setReturnValue(0 <= loreInt && loreInt < loreLines.size() && + matchStringDirect((loreLines.get(loreInt).getString()), context)); + } + } + } + } + + +} diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java index f791b13..610a106 100644 --- a/src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java @@ -28,11 +28,11 @@ public class PatchHeadFeatureRenderer<T extends LivingEntity, M extends EntityMo @WrapOperation(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BlockItem;getBlock()Lnet/minecraft/block/Block;")) - private Block replaceSkull(BlockItem instance, Operation<Block> original, @Local ItemStack itemStack) { + private Block replaceSkull(BlockItem instance, Operation<Block> original, @Local ItemStack itemStack, @Local(argsOnly = true) T entity) { var oldBlock = original.call(instance); if (oldBlock instanceof AbstractSkullBlock) { var bakedModel = this.heldItemRenderer.itemRenderer - .getModel(itemStack, null, null, 0); + .getModel(itemStack, entity.getWorld(), entity, 0); if (bakedModel instanceof BakedModelExtra extra && extra.getHeadModel_firmament() != null) return Blocks.ENCHANTING_TABLE; // Any non skull block. Let's choose the enchanting table because it is very distinct. } |