From fc5d12980f77684a767b8fafe4c95510fa4ae924 Mon Sep 17 00:00:00 2001 From: BitHeaven Date: Tue, 21 Jan 2025 14:45:49 +0500 Subject: [PATCH] Update Mixins from Redirect to Update Statement --- .../mixin/DivingHelmetItemMixin.java | 9 +++----- .../mixin/EntityOxygenSystemMixin.java | 22 +++++++++---------- .../mixin/EntityTemperatureSystemMixin.java | 12 +++++----- .../mixin/RemainingAirOverlayMixin.java | 13 ++++++----- 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/main/java/ru/bitheaven/createairfabric/mixin/DivingHelmetItemMixin.java b/src/main/java/ru/bitheaven/createairfabric/mixin/DivingHelmetItemMixin.java index e199510..d61c0ca 100644 --- a/src/main/java/ru/bitheaven/createairfabric/mixin/DivingHelmetItemMixin.java +++ b/src/main/java/ru/bitheaven/createairfabric/mixin/DivingHelmetItemMixin.java @@ -1,11 +1,8 @@ package ru.bitheaven.createairfabric.mixin; -import net.minecraft.tags.TagKey; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.level.material.Fluid; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.simibubi.create.content.equipment.armor.DivingHelmetItem; import ru.bitheaven.createairfabric.CreateAirFabric; @@ -15,11 +12,11 @@ public abstract class DivingHelmetItemMixin { /** * Activate helmet "if in water or lava" -> "if in water or bad air or lava" */ - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"), + @ModifyExpressionValue(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"), method = "breatheUnderwater(Lnet/minecraft/world/entity/LivingEntity;)V") - private static boolean redirectBreatheUnderwater(LivingEntity entity, TagKey fluidTagKey) { + private static boolean redirectBreatheUnderwater(boolean original, LivingEntity entity) { boolean oxygen = true; - oxygen &= !entity.isEyeInFluid(fluidTagKey); + oxygen &= !original; oxygen &= !entity.isUnderWater(); oxygen &= CreateAirFabric.isOxygen(entity); diff --git a/src/main/java/ru/bitheaven/createairfabric/mixin/EntityOxygenSystemMixin.java b/src/main/java/ru/bitheaven/createairfabric/mixin/EntityOxygenSystemMixin.java index c22883c..f326d2e 100644 --- a/src/main/java/ru/bitheaven/createairfabric/mixin/EntityOxygenSystemMixin.java +++ b/src/main/java/ru/bitheaven/createairfabric/mixin/EntityOxygenSystemMixin.java @@ -1,43 +1,41 @@ package ru.bitheaven.createairfabric.mixin; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.simibubi.create.content.equipment.armor.BacktankItem; import com.simibubi.create.content.equipment.armor.BacktankUtil; import com.simibubi.create.content.equipment.armor.DivingHelmetItem; -import earth.terrarium.adastra.common.items.armor.SpaceSuitItem; import earth.terrarium.adastra.common.systems.OxygenApiImpl; import earth.terrarium.adastra.common.tags.ModItemTags; -import net.minecraft.world.entity.Entity; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(OxygenApiImpl.class) public abstract class EntityOxygenSystemMixin { /** * Make air exists if Create Air */ - @Redirect(at = @At(value = "INVOKE", target = "Learth/terrarium/adastra/common/items/armor/SpaceSuitItem;hasOxygen(Lnet/minecraft/world/entity/Entity;)Z"), + @ModifyExpressionValue(at = @At(value = "INVOKE", target = "Learth/terrarium/adastra/common/items/armor/SpaceSuitItem;hasOxygen(Lnet/minecraft/world/entity/Entity;)Z"), method = "entityTick(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/LivingEntity;)V") - private boolean redirectHasOxygen(Entity entity) { - if (!(entity instanceof LivingEntity livingEntity)) return SpaceSuitItem.hasOxygen(entity); + private boolean redirectHasOxygen(boolean original, ServerLevel level, LivingEntity entity) { boolean createOxygen = true; - createOxygen &= !DivingHelmetItem.getWornItem(livingEntity).isEmpty(); - createOxygen &= !BacktankUtil.getAllWithAir(livingEntity).isEmpty(); - return SpaceSuitItem.hasOxygen(livingEntity) || createOxygen; + createOxygen &= !DivingHelmetItem.getWornItem(entity).isEmpty(); + createOxygen &= !BacktankUtil.getAllWithAir(entity).isEmpty(); + return original || createOxygen; } - @Redirect(at = @At(value = "INVOKE", target = "Learth/terrarium/adastra/common/items/armor/SpaceSuitItem;hasFullSet(Lnet/minecraft/world/entity/LivingEntity;)Z"), + @ModifyExpressionValue(at = @At(value = "INVOKE", target = "Learth/terrarium/adastra/common/items/armor/SpaceSuitItem;hasFullSet(Lnet/minecraft/world/entity/LivingEntity;)Z"), method = "entityTick(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/LivingEntity;)V") - private boolean redirectHasFullSet(LivingEntity entity) { + private boolean redirectHasFullSet(boolean original, ServerLevel level, LivingEntity entity) { boolean createArmor = true; createArmor &= entity.getItemBySlot(EquipmentSlot.HEAD).getItem() instanceof DivingHelmetItem; createArmor &= entity.getItemBySlot(EquipmentSlot.CHEST).getItem() instanceof BacktankItem; createArmor &= entity.getItemBySlot(EquipmentSlot.LEGS).is(ModItemTags.SPACE_SUITS); createArmor &= entity.getItemBySlot(EquipmentSlot.FEET).is(ModItemTags.SPACE_SUITS); - return SpaceSuitItem.hasFullSet(entity) || createArmor; + return original || createArmor; } } diff --git a/src/main/java/ru/bitheaven/createairfabric/mixin/EntityTemperatureSystemMixin.java b/src/main/java/ru/bitheaven/createairfabric/mixin/EntityTemperatureSystemMixin.java index b4172f0..971f6f0 100644 --- a/src/main/java/ru/bitheaven/createairfabric/mixin/EntityTemperatureSystemMixin.java +++ b/src/main/java/ru/bitheaven/createairfabric/mixin/EntityTemperatureSystemMixin.java @@ -1,19 +1,20 @@ package ru.bitheaven.createairfabric.mixin; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import earth.terrarium.adastra.common.items.armor.NetheriteSpaceSuitItem; import earth.terrarium.adastra.common.tags.ModItemTags; import earth.terrarium.adastra.common.systems.TemperatureApiImpl; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(TemperatureApiImpl.class) public abstract class EntityTemperatureSystemMixin { - @Redirect(at = @At(value = "INVOKE", target = "Learth/terrarium/adastra/common/systems/TemperatureApiImpl;burnEntity(Lnet/minecraft/world/entity/LivingEntity;)V"), + @ModifyExpressionValue(at = @At(value = "INVOKE", target = "Learth/terrarium/adastra/api/events/AdAstraEvents$HotTemperatureTickEvent;fire(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/LivingEntity;)Z"), method = "entityTick(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/LivingEntity;)V") - private void redirectTemperatureTick(TemperatureApiImpl instance, LivingEntity entity) { + private boolean redirectTemperatureTick(boolean original, ServerLevel level, LivingEntity entity) { boolean createNetherite = true; createNetherite &= entity.getItemBySlot(EquipmentSlot.HEAD).getItem().isFireResistant(); createNetherite &= entity.getItemBySlot(EquipmentSlot.CHEST).getItem().isFireResistant(); @@ -24,9 +25,6 @@ public abstract class EntityTemperatureSystemMixin { || entity.getItemBySlot(EquipmentSlot.FEET).getItem() instanceof NetheriteSpaceSuitItem || entity.getItemBySlot(EquipmentSlot.FEET).getItem().isFireResistant(); - if(!createNetherite) { - entity.hurt(entity.damageSources().onFire(), 6); - entity.setSecondsOnFire(10); - } + return original && !createNetherite; } } diff --git a/src/main/java/ru/bitheaven/createairfabric/mixin/RemainingAirOverlayMixin.java b/src/main/java/ru/bitheaven/createairfabric/mixin/RemainingAirOverlayMixin.java index 94c2a5e..5de0e3d 100644 --- a/src/main/java/ru/bitheaven/createairfabric/mixin/RemainingAirOverlayMixin.java +++ b/src/main/java/ru/bitheaven/createairfabric/mixin/RemainingAirOverlayMixin.java @@ -1,12 +1,11 @@ package ru.bitheaven.createairfabric.mixin; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.simibubi.create.content.equipment.armor.RemainingAirOverlay; +import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.tags.TagKey; -import net.minecraft.world.level.material.Fluid; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; import ru.bitheaven.createairfabric.CreateAirFabric; @Mixin(RemainingAirOverlay.class) @@ -14,9 +13,11 @@ public class RemainingAirOverlayMixin { /** * Activate UI "if in water or lava" -> "if in water or bad air or lava" */ - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"), + @ModifyExpressionValue(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"), method = "render(Lnet/minecraft/client/gui/GuiGraphics;II)V") - private static boolean redirectRender(LocalPlayer player, TagKey fluidTagKey) { - return player.isEyeInFluid(fluidTagKey) || !CreateAirFabric.isOxygen(player); + private static boolean redirectRender(boolean original) { + Minecraft mc = Minecraft.getInstance(); + LocalPlayer player = mc.player; + return original || !CreateAirFabric.isOxygen(player); } }