From 498577294e3494d979782db6da04b96a4d9abb6a Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 24 Apr 2024 19:33:22 +0100 Subject: [PATCH 1/3] Redo ad_astra compat --- .../unicopia/compat/ad_astra/OxygenApi.java | 11 +++++++ .../unicopia/compat/ad_astra/OxygenUtils.java | 11 ------- .../unicopia/entity/player/PlayerPhysics.java | 4 +-- .../mixin/ad_astra/MixinOxygenUtils.java | 33 ++++++++++--------- src/main/resources/unicopia.mixin.json | 3 +- 5 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenApi.java delete mode 100644 src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenUtils.java diff --git a/src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenApi.java b/src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenApi.java new file mode 100644 index 00000000..7a216d4c --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenApi.java @@ -0,0 +1,11 @@ +package com.minelittlepony.unicopia.compat.ad_astra; + +import java.util.concurrent.atomic.AtomicReference; + +import net.minecraft.entity.Entity; + +public interface OxygenApi { + AtomicReference API = new AtomicReference<>(entity -> false); + + boolean hasOxygen(Entity entity); +} diff --git a/src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenUtils.java b/src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenUtils.java deleted file mode 100644 index d1497215..00000000 --- a/src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenUtils.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.minelittlepony.unicopia.compat.ad_astra; - -import net.minecraft.entity.Entity; - -public final class OxygenUtils { - public static OxygenApi API = entity -> false; - - public interface OxygenApi { - boolean hasOxygen(Entity entity); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index de13f11d..e6898304 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -12,7 +12,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.advancement.UCriteria; import com.minelittlepony.unicopia.client.minelittlepony.MineLPDelegate; import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation; -import com.minelittlepony.unicopia.compat.ad_astra.OxygenUtils; +import com.minelittlepony.unicopia.compat.ad_astra.OxygenApi; import com.minelittlepony.unicopia.entity.*; import com.minelittlepony.unicopia.entity.damage.UDamageTypes; import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck; @@ -200,7 +200,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab if ((RegistryUtils.isIn(entity.getWorld(), dimension, RegistryKeys.DIMENSION_TYPE, UTags.DimensionTypes.HAS_NO_ATMOSPHERE) || Unicopia.getConfig().dimensionsWithoutAtmosphere.get().contains(RegistryUtils.getId(entity.getWorld(), dimension, RegistryKeys.DIMENSION_TYPE).toString())) - && !OxygenUtils.API.hasOxygen(entity)) { + && !OxygenApi.API.get().hasOxygen(entity)) { return FlightType.NONE; } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/ad_astra/MixinOxygenUtils.java b/src/main/java/com/minelittlepony/unicopia/mixin/ad_astra/MixinOxygenUtils.java index c71bf32c..f195f81a 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/ad_astra/MixinOxygenUtils.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/ad_astra/MixinOxygenUtils.java @@ -1,30 +1,31 @@ package com.minelittlepony.unicopia.mixin.ad_astra; -import org.spongepowered.asm.mixin.Dynamic; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Coerce; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.minelittlepony.unicopia.compat.ad_astra.OxygenUtils; +import com.minelittlepony.unicopia.compat.ad_astra.OxygenApi; @Pseudo @Mixin( targets = { "earth.terrarium.adastra.api.systems.OxygenApi" }, remap = false ) -public interface MixinOxygenUtils extends OxygenUtils.OxygenApi { - @Accessor("API") - @Coerce - static Object getAPI() { - throw new AbstractMethodError("stub"); - } - - @Dynamic("Compiler-generated class-init() method") - @Inject(method = "()V", at = @At("RETURN"), remap = false) - private static void classInit() { - OxygenUtils.API = (OxygenUtils.OxygenApi)getAPI(); - } +interface MixinOxygenApi extends OxygenApi { } + +@Pseudo +@Mixin( + targets = { "earth.terrarium.adastra.api.ApiHelper" }, + remap = false +) +abstract class MixinApiHelper { + @Inject(method = "load", at = @At("RETURN"), require = 0) + private static void onLoad(Class clazz, CallbackInfoReturnable info) { + if (info.getReturnValue() instanceof OxygenApi api) { + OxygenApi.API.set(api); + } + } +} \ No newline at end of file diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index 46be0255..ba92c81c 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -71,7 +71,8 @@ "trinkets.MixinTrinketInventory", "trinkets.MixinScreenHandler", "seasons.MixinFertilizableUtil", - "ad_astra.MixinOxygenUtils", + "ad_astra.MixinApiHelper", + "ad_astra.MixinOxygenApi", "forgified.MixinIForgeBoat" ], "client": [ From f84ef8654692fb5161fc7ab81e226247227ca7f6 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 24 Apr 2024 19:41:14 +0100 Subject: [PATCH 2/3] Fix null camera crash --- .../java/com/minelittlepony/unicopia/client/UnicopiaClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java b/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java index 663d349e..1ad3f0a1 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java +++ b/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java @@ -65,7 +65,7 @@ public class UnicopiaClient implements ClientModInitializer { private ZapAppleStageStore.Stage zapAppleStage = ZapAppleStageStore.Stage.HIBERNATING; public static Optional getCamera() { - return Optional.of(getNullableCamera()); + return Optional.ofNullable(getNullableCamera()); } @Nullable From cda4e5b0b614fdeba90c6ea156a79fc74cb8e7be Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 24 Apr 2024 20:00:44 +0100 Subject: [PATCH 3/3] Change ad-astra oxygen check to use the current location instead of the entity --- .../minelittlepony/unicopia/compat/ad_astra/OxygenApi.java | 7 ++++--- .../unicopia/entity/player/PlayerPhysics.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenApi.java b/src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenApi.java index 7a216d4c..abc635e2 100644 --- a/src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenApi.java +++ b/src/main/java/com/minelittlepony/unicopia/compat/ad_astra/OxygenApi.java @@ -2,10 +2,11 @@ package com.minelittlepony.unicopia.compat.ad_astra; import java.util.concurrent.atomic.AtomicReference; -import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; public interface OxygenApi { - AtomicReference API = new AtomicReference<>(entity -> false); + AtomicReference API = new AtomicReference<>((world, pos) -> false); - boolean hasOxygen(Entity entity); + boolean hasOxygen(World world, BlockPos pos); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index e6898304..699a2e95 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -200,7 +200,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab if ((RegistryUtils.isIn(entity.getWorld(), dimension, RegistryKeys.DIMENSION_TYPE, UTags.DimensionTypes.HAS_NO_ATMOSPHERE) || Unicopia.getConfig().dimensionsWithoutAtmosphere.get().contains(RegistryUtils.getId(entity.getWorld(), dimension, RegistryKeys.DIMENSION_TYPE).toString())) - && !OxygenApi.API.get().hasOxygen(entity)) { + && !OxygenApi.API.get().hasOxygen(entity.getWorld(), entity.getBlockPos())) { return FlightType.NONE; }