From bd777f426ff54e1850ad188fcd27dc04f2185491 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Wed, 17 Jan 2024 16:29:19 -0500 Subject: [PATCH] @ModifyConstant => @ModifyExpressionValue for compat & stackablity. Fixes #4591 and #4588 --- .../tools/module/BeaconRedirectionModule.java | 4 ++-- .../quark/mixin/mixins/ArmorStandMixin.java | 16 +++++++--------- .../mixins/BannerDuplicateRecipeMixin.java | 18 ++++++++---------- .../mixin/mixins/BeaconBlockEntityMixin.java | 12 +++++------- .../quark/mixin/mixins/LoomMenuMixin.java | 12 +++++------- .../mixins/PistonMovingBlockEntityMixin.java | 14 ++++++-------- .../quark/mixin/mixins/SpongeBlockMixin.java | 18 ++++++++---------- .../mixin/mixins/client/BannerItemMixin.java | 12 +++++------- .../mixin/mixins/client/ForgeGuiMixin.java | 12 +++++------- .../mixin/mixins/client/ItemRendererMixin.java | 11 +++-------- .../mixin/mixins/client/LoomScreenMixin.java | 12 +++++------- 11 files changed, 59 insertions(+), 82 deletions(-) diff --git a/src/main/java/org/violetmoon/quark/content/tools/module/BeaconRedirectionModule.java b/src/main/java/org/violetmoon/quark/content/tools/module/BeaconRedirectionModule.java index e56ba7951b..e239788ff6 100644 --- a/src/main/java/org/violetmoon/quark/content/tools/module/BeaconRedirectionModule.java +++ b/src/main/java/org/violetmoon/quark/content/tools/module/BeaconRedirectionModule.java @@ -82,9 +82,9 @@ public void addAdditionalHints(ZGatherHints event) { // The value that comes out of this is fed onto a constant for the FOR loop that // computes the beacon segments, so we return 0 to run that code, or MAX_VALUE to not - public static int tickBeacon(BeaconBlockEntity beacon) { + public static int tickBeacon(BeaconBlockEntity beacon, int original) { if(!staticEnabled) - return 0; + return original; Level world = beacon.getLevel(); BlockPos beaconPos = beacon.getBlockPos(); diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/ArmorStandMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/ArmorStandMixin.java index 9d68b7d6cc..ae62716029 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/ArmorStandMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/ArmorStandMixin.java @@ -1,28 +1,26 @@ package org.violetmoon.quark.mixin.mixins; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.decoration.ArmorStand; - import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - +import org.spongepowered.asm.mixin.injection.At; import org.violetmoon.quark.content.tweaks.module.ArmedArmorStandsModule; @Mixin(ArmorStand.class) public class ArmorStandMixin { - @ModifyConstant(method = "defineSynchedData", constant = @Constant(intValue = 0)) - private int asdasld(int orig) { + @ModifyExpressionValue(method = "defineSynchedData", at = @At(value = "CONSTANT", args = "intValue=0")) + private int quark$armedArmorStands(int original) { if(!ArmedArmorStandsModule.staticEnabled) - return orig; + return original; //try to be careful - this is a kinda scary looking mixin, lol SynchedEntityData data = ((Entity) (Object) this).getEntityData(); if(data.hasItem(ArmorStand.DATA_CLIENT_FLAGS)) - return orig; //it's already been defined + return original; //it's already been defined else - return orig | ArmorStand.CLIENT_FLAG_SHOW_ARMS; // | 4 + return original | ArmorStand.CLIENT_FLAG_SHOW_ARMS; // | 4 } } diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/BannerDuplicateRecipeMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/BannerDuplicateRecipeMixin.java index f46d3687e9..8fd42e1b08 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/BannerDuplicateRecipeMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/BannerDuplicateRecipeMixin.java @@ -1,24 +1,22 @@ package org.violetmoon.quark.mixin.mixins; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.world.item.crafting.BannerDuplicateRecipe; - import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - +import org.spongepowered.asm.mixin.injection.At; import org.violetmoon.quark.content.tweaks.module.MoreBannerLayersModule; @Mixin(BannerDuplicateRecipe.class) public class BannerDuplicateRecipeMixin { - @ModifyConstant(method = "matches(Lnet/minecraft/world/inventory/CraftingContainer;Lnet/minecraft/world/level/Level;)Z", constant = @Constant(intValue = 6)) - public int getLimitMatches(int curr) { - return MoreBannerLayersModule.getLimit(curr); + @ModifyExpressionValue(method = "matches(Lnet/minecraft/world/inventory/CraftingContainer;Lnet/minecraft/world/level/Level;)Z", at = @At(value = "CONSTANT", args = "intValue=6")) + public int getLimitMatches(int original) { + return MoreBannerLayersModule.getLimit(original); } - @ModifyConstant(method = "assemble(Lnet/minecraft/world/inventory/CraftingContainer;Lnet/minecraft/core/RegistryAccess;)Lnet/minecraft/world/item/ItemStack;", constant = @Constant(intValue = 6)) - public int getLimitAssemble(int curr) { - return MoreBannerLayersModule.getLimit(curr); + @ModifyExpressionValue(method = "assemble(Lnet/minecraft/world/inventory/CraftingContainer;Lnet/minecraft/core/RegistryAccess;)Lnet/minecraft/world/item/ItemStack;", at = @At(value = "CONSTANT", args = "intValue=6")) + public int getLimitAssemble(int original) { + return MoreBannerLayersModule.getLimit(original); } } diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/BeaconBlockEntityMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/BeaconBlockEntityMixin.java index d1cccc33e2..507ce47f04 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/BeaconBlockEntityMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/BeaconBlockEntityMixin.java @@ -1,23 +1,21 @@ package org.violetmoon.quark.mixin.mixins; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BeaconBlockEntity; import net.minecraft.world.level.block.state.BlockState; - import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - +import org.spongepowered.asm.mixin.injection.At; import org.violetmoon.quark.content.tools.module.BeaconRedirectionModule; @Mixin(BeaconBlockEntity.class) public class BeaconBlockEntityMixin { // This captures the for loop inside tick that computes the beacon segments - @ModifyConstant(method = "tick", constant = @Constant(intValue = 0, ordinal = 0)) - private static int tick(int val, Level level, BlockPos pos, BlockState state, BeaconBlockEntity beacon) { - return BeaconRedirectionModule.tickBeacon(beacon); + @ModifyExpressionValue(method = "tick", at = @At(value = "CONSTANT", args = "intValue=0", ordinal = 0)) + private static int tick(int original, Level level, BlockPos pos, BlockState state, BeaconBlockEntity beacon) { + return BeaconRedirectionModule.tickBeacon(beacon, original); } } diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/LoomMenuMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/LoomMenuMixin.java index dbe4020a42..79a12ff395 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/LoomMenuMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/LoomMenuMixin.java @@ -1,19 +1,17 @@ package org.violetmoon.quark.mixin.mixins; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.world.inventory.LoomMenu; - import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - +import org.spongepowered.asm.mixin.injection.At; import org.violetmoon.quark.content.tweaks.module.MoreBannerLayersModule; @Mixin(LoomMenu.class) public class LoomMenuMixin { - @ModifyConstant(method = "slotsChanged", constant = @Constant(intValue = 6)) - public int getLimit(int curr) { - return MoreBannerLayersModule.getLimit(curr); + @ModifyExpressionValue(method = "slotsChanged", at = @At(value = "CONSTANT", args = "intValue=6")) + public int getLimit(int original) { + return MoreBannerLayersModule.getLimit(original); } } diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/PistonMovingBlockEntityMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/PistonMovingBlockEntityMixin.java index b9f3117dee..d22bd3d740 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/PistonMovingBlockEntityMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/PistonMovingBlockEntityMixin.java @@ -1,18 +1,14 @@ package org.violetmoon.quark.mixin.mixins; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.piston.PistonMovingBlockEntity; import net.minecraft.world.level.block.state.BlockState; - import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - import org.violetmoon.quark.content.automation.module.PistonsMoveTileEntitiesModule; import org.violetmoon.quark.content.experimental.module.GameNerfsModule; @@ -24,8 +20,10 @@ private static boolean tick(Level instance, BlockPos pos, BlockState newState, i return PistonsMoveTileEntitiesModule.setPistonBlock(instance, pos, newState, flags) || original.call(instance, pos, newState, flags); } - @ModifyConstant(method = "tick", constant = @Constant(intValue = 84)) - private static int forceNotifyBlockUpdate(int flag) { - return GameNerfsModule.stopPistonPhysicsExploits() ? (flag | 2) : flag; // paper impl comment: Paper - force notify (flag 2), it's possible the set type by the piston block (which doesn't notify) set this block to air + @ModifyExpressionValue(method = "tick", at = @At(value = "CONSTANT", args = "intValue=84")) + private static int forceNotifyBlockUpdate(int original) { + // paper impl comment: Paper - force notify (original 2), + // it's possible the set type by the piston block (which doesn't notify) to set this block to air + return GameNerfsModule.stopPistonPhysicsExploits() ? (original | 2) : original; } } diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/SpongeBlockMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/SpongeBlockMixin.java index 0080fa2b90..3be9282130 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/SpongeBlockMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/SpongeBlockMixin.java @@ -1,24 +1,22 @@ package org.violetmoon.quark.mixin.mixins; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.world.level.block.SpongeBlock; - import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - +import org.spongepowered.asm.mixin.injection.At; import org.violetmoon.quark.content.tweaks.module.ImprovedSpongesModule; @Mixin(SpongeBlock.class) public class SpongeBlockMixin { - @ModifyConstant(method = "removeWaterBreadthFirstSearch", constant = @Constant(intValue = 65)) - public int getDrainLimit(int limit) { - return ImprovedSpongesModule.drainLimit(limit); + @ModifyExpressionValue(method = "removeWaterBreadthFirstSearch", at = @At(value = "CONSTANT", args = "intValue=65")) + public int getDrainLimit(int original) { + return ImprovedSpongesModule.drainLimit(original); } - @ModifyConstant(method = "removeWaterBreadthFirstSearch", constant = @Constant(intValue = 6)) - public int getCrawlLimit(int limit) { - return ImprovedSpongesModule.crawlLimit(limit); + @ModifyExpressionValue(method = "removeWaterBreadthFirstSearch", at = @At(value = "CONSTANT", args = "intValue=6")) + public int getCrawlLimit(int original) { + return ImprovedSpongesModule.crawlLimit(original); } } diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/client/BannerItemMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/client/BannerItemMixin.java index f3e5997f8b..f4bfeadbac 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/client/BannerItemMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/client/BannerItemMixin.java @@ -1,19 +1,17 @@ package org.violetmoon.quark.mixin.mixins.client; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.world.item.BannerItem; - import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - +import org.spongepowered.asm.mixin.injection.At; import org.violetmoon.quark.content.tweaks.module.MoreBannerLayersModule; @Mixin(BannerItem.class) public class BannerItemMixin { - @ModifyConstant(method = "appendHoverTextFromBannerBlockEntityTag", constant = @Constant(intValue = 6)) - private static int getLimit(int curr) { - return MoreBannerLayersModule.getLimit(curr); + @ModifyExpressionValue(method = "appendHoverTextFromBannerBlockEntityTag", at = @At(value = "CONSTANT", args = "intValue=6")) + private static int getLimit(int original) { + return MoreBannerLayersModule.getLimit(original); } } diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/client/ForgeGuiMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/client/ForgeGuiMixin.java index 76c2d3784a..3561e97c72 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/client/ForgeGuiMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/client/ForgeGuiMixin.java @@ -1,21 +1,19 @@ package org.violetmoon.quark.mixin.mixins.client; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraftforge.client.gui.overlay.ForgeGui; - import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - +import org.spongepowered.asm.mixin.injection.At; import org.violetmoon.quark.base.Quark; import org.violetmoon.quark.content.client.module.ElytraIndicatorModule; @Mixin(ForgeGui.class) public class ForgeGuiMixin { - @ModifyConstant(method = "renderArmor", constant = @Constant(intValue = 20), remap = false) - private static int renderArmor(int curr) { + @ModifyExpressionValue(method = "renderArmor", at = @At(value = "CONSTANT", args = "intValue=20"), remap = false) + private static int renderArmor(int original) { ElytraIndicatorModule module = Quark.ZETA.modules.get(ElytraIndicatorModule.class); - return module == null ? curr : module.getArmorLimit(curr); + return module == null ? original : module.getArmorLimit(original); } } diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/client/ItemRendererMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/client/ItemRendererMixin.java index c414d9b9ce..56d10ae661 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/client/ItemRendererMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/client/ItemRendererMixin.java @@ -2,21 +2,16 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.mojang.blaze3d.vertex.PoseStack; - import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; - import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Constant; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyConstant; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - import org.violetmoon.quark.content.management.module.ItemSharingModule; import org.violetmoon.quark.content.tools.module.ColorRunesModule; @@ -70,8 +65,8 @@ private static RenderType getEntityGlintDirect(RenderType prev) { return ColorRunesModule.Client.getEntityGlintDirect(); } - @ModifyConstant(method = "renderQuadList", constant = @Constant(floatValue = 1F), require = 0) // Allow failure in case of rubidium - public float renderQuads(float constant) { - return ItemSharingModule.Client.alphaValue * constant; + @ModifyExpressionValue(method = "renderQuadList", at = @At(value = "CONSTANT", args = "floatValue=1F"), require = 0) // Allow failure in case of rubidium/embeddium + public float renderQuads(float original) { + return ItemSharingModule.Client.alphaValue * original; } } diff --git a/src/main/java/org/violetmoon/quark/mixin/mixins/client/LoomScreenMixin.java b/src/main/java/org/violetmoon/quark/mixin/mixins/client/LoomScreenMixin.java index 1af3b2dd36..7c374fa59c 100644 --- a/src/main/java/org/violetmoon/quark/mixin/mixins/client/LoomScreenMixin.java +++ b/src/main/java/org/violetmoon/quark/mixin/mixins/client/LoomScreenMixin.java @@ -1,19 +1,17 @@ package org.violetmoon.quark.mixin.mixins.client; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.client.gui.screens.inventory.LoomScreen; - import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - +import org.spongepowered.asm.mixin.injection.At; import org.violetmoon.quark.content.tweaks.module.MoreBannerLayersModule; @Mixin(LoomScreen.class) public class LoomScreenMixin { - @ModifyConstant(method = "containerChanged", constant = @Constant(intValue = 6)) - private static int getLimit(int curr) { - return MoreBannerLayersModule.getLimit(curr); + @ModifyExpressionValue(method = "containerChanged", at = @At(value = "CONSTANT", args = "intValue=6")) + private static int getLimit(int original) { + return MoreBannerLayersModule.getLimit(original); } }