From 2310d5d2b18ba7d8e1a7c0d31fb1ffdad333a804 Mon Sep 17 00:00:00 2001 From: Up Date: Tue, 23 Apr 2024 13:50:57 +0200 Subject: [PATCH] further encapsulate state --- .../cammiescorner/icarus/client/IcarusClient.java | 4 ++-- .../cammiescorner/icarus/mixin/EntityMixin.java | 4 ++-- .../icarus/mixin/client/CapeLayerMixin.java | 2 +- .../icarus/mixin/client/MouseHandlerMixin.java | 2 +- .../cammiescorner/icarus/util/IcarusHelper.java | 15 +++++++++++++++ .../icarus/neoforge/EventHandler.java | 6 +++--- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Common/src/main/java/dev/cammiescorner/icarus/client/IcarusClient.java b/Common/src/main/java/dev/cammiescorner/icarus/client/IcarusClient.java index 15fe4b0..d1d3dc2 100644 --- a/Common/src/main/java/dev/cammiescorner/icarus/client/IcarusClient.java +++ b/Common/src/main/java/dev/cammiescorner/icarus/client/IcarusClient.java @@ -15,7 +15,7 @@ public class IcarusClient { private static final List> renderPredicates = new ArrayList<>(); public static void onPlayerTick(Player player) { - if (player.isFallFlying() && IcarusHelper.hasWings.test(player) && player.zza > 0) { + if (player.isFallFlying() && IcarusHelper.hasWings(player) && player.zza > 0) { var cfg = IcarusHelper.getConfigValues(player); var rotation = player.getLookAngle(); var velocity = player.getDeltaMovement(); @@ -30,7 +30,7 @@ public static void onPlayerTick(Player player) { @ApiStatus.Internal public static ItemStack getWingsForRendering(LivingEntity entity) { - return IcarusHelper.getEquippedWings.apply(entity); + return IcarusHelper.getEquippedWings(entity); } @ApiStatus.Internal diff --git a/Common/src/main/java/dev/cammiescorner/icarus/mixin/EntityMixin.java b/Common/src/main/java/dev/cammiescorner/icarus/mixin/EntityMixin.java index 5348489..9addbc6 100644 --- a/Common/src/main/java/dev/cammiescorner/icarus/mixin/EntityMixin.java +++ b/Common/src/main/java/dev/cammiescorner/icarus/mixin/EntityMixin.java @@ -31,7 +31,7 @@ public abstract class EntityMixin { @ModifyExpressionValue(method = "turn", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;clamp(FFF)F", ordinal = 0)) private float icarus$updateLookDirection(float original) { if(((Object) this) instanceof LivingEntity living) { - return living.isFallFlying() && IcarusHelper.hasWings.test(living) ? Mth.wrapDegrees(this.getXRot()) : original; + return living.isFallFlying() && IcarusHelper.hasWings(living) ? Mth.wrapDegrees(this.getXRot()) : original; } return original; } @@ -39,7 +39,7 @@ public abstract class EntityMixin { @ModifyExpressionValue(method = "turn", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;clamp(FFF)F", ordinal = 1)) private float icarus$updateLookDirection0(float original) { if (((Object) this) instanceof LivingEntity living) { - return living.isFallFlying() && IcarusHelper.hasWings.test(living) ? Mth.wrapDegrees(this.xRotO) : original; + return living.isFallFlying() && IcarusHelper.hasWings(living) ? Mth.wrapDegrees(this.xRotO) : original; } return original; } diff --git a/Common/src/main/java/dev/cammiescorner/icarus/mixin/client/CapeLayerMixin.java b/Common/src/main/java/dev/cammiescorner/icarus/mixin/client/CapeLayerMixin.java index ad308cb..ce9ef62 100644 --- a/Common/src/main/java/dev/cammiescorner/icarus/mixin/client/CapeLayerMixin.java +++ b/Common/src/main/java/dev/cammiescorner/icarus/mixin/client/CapeLayerMixin.java @@ -14,7 +14,7 @@ public abstract class CapeLayerMixin { @WrapOperation(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/player/AbstractClientPlayer;FFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/AbstractClientPlayer;isModelPartShown(Lnet/minecraft/world/entity/player/PlayerModelPart;)Z")) private boolean icarus$hideCape(AbstractClientPlayer instance, PlayerModelPart playerModelPart, Operation original) { - return original.call(instance, playerModelPart) && !IcarusHelper.hasWings.test(instance); + return original.call(instance, playerModelPart) && !IcarusHelper.hasWings(instance); } } diff --git a/Common/src/main/java/dev/cammiescorner/icarus/mixin/client/MouseHandlerMixin.java b/Common/src/main/java/dev/cammiescorner/icarus/mixin/client/MouseHandlerMixin.java index 2269129..da477f7 100644 --- a/Common/src/main/java/dev/cammiescorner/icarus/mixin/client/MouseHandlerMixin.java +++ b/Common/src/main/java/dev/cammiescorner/icarus/mixin/client/MouseHandlerMixin.java @@ -18,7 +18,7 @@ public class MouseHandlerMixin { @ModifyArg(method = "turnPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;turn(DD)V"), index = 0) public double changeLookDirectionX(double x) { - if (minecraft.player != null && minecraft.player.isFallFlying() && IcarusHelper.hasWings.test(minecraft.player) && IcarusHelper.getConfigValues(minecraft.player).canLoopDeLoop() && (minecraft.player.getXRot() > 90 || minecraft.player.getXRot() < -90)) + if (minecraft.player != null && minecraft.player.isFallFlying() && IcarusHelper.hasWings(minecraft.player) && IcarusHelper.getConfigValues(minecraft.player).canLoopDeLoop() && (minecraft.player.getXRot() > 90 || minecraft.player.getXRot() < -90)) return -x; return x; diff --git a/Common/src/main/java/dev/cammiescorner/icarus/util/IcarusHelper.java b/Common/src/main/java/dev/cammiescorner/icarus/util/IcarusHelper.java index a1183bd..91ec2cc 100644 --- a/Common/src/main/java/dev/cammiescorner/icarus/util/IcarusHelper.java +++ b/Common/src/main/java/dev/cammiescorner/icarus/util/IcarusHelper.java @@ -13,6 +13,7 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.function.BiPredicate; @@ -21,9 +22,15 @@ public class IcarusHelper { + @ApiStatus.Internal public static Predicate hasWings = entity -> false; + + @ApiStatus.Internal public static Function getEquippedWings = entity -> ItemStack.EMPTY; + @ApiStatus.Internal public static BiPredicate equipFunc = (entity, stack) -> false; + + @ApiStatus.Internal public static IcarusPlayerValues fallbackValues = new ServerPlayerFallbackValues(); public static boolean onFallFlyingTick(LivingEntity entity, @Nullable ItemStack wings, boolean tick) { @@ -73,6 +80,14 @@ public static boolean onFallFlyingTick(LivingEntity entity, @Nullable ItemStack return true; } + public static boolean hasWings(LivingEntity entity) { + return hasWings.test(entity); + } + + public static ItemStack getEquippedWings(LivingEntity entity) { + return getEquippedWings.apply(entity); + } + public static IcarusPlayerValues getConfigValues(LivingEntity entity) { return fallbackValues; } diff --git a/NeoForge/src/main/java/dev/cammiescorner/icarus/neoforge/EventHandler.java b/NeoForge/src/main/java/dev/cammiescorner/icarus/neoforge/EventHandler.java index 96bab90..c301f5a 100644 --- a/NeoForge/src/main/java/dev/cammiescorner/icarus/neoforge/EventHandler.java +++ b/NeoForge/src/main/java/dev/cammiescorner/icarus/neoforge/EventHandler.java @@ -29,18 +29,18 @@ public static void onPlayerTick(TickEvent.PlayerTickEvent event) { if(attributeInstance != null) { if (attributeInstance.hasModifier(WINGS_FLIGHT)) { if(event.player.isFallFlying()) { - if (!IcarusHelper.onFallFlyingTick(event.player, IcarusHelper.getEquippedWings.apply(event.player), true)) { + if (!IcarusHelper.onFallFlyingTick(event.player, IcarusHelper.getEquippedWings(event.player), true)) { attributeInstance.removeModifier(WINGS_FLIGHT); } } else { - if(!IcarusHelper.hasWings.test(event.player)) { + if(!IcarusHelper.hasWings(event.player)) { attributeInstance.removeModifier(WINGS_FLIGHT); } } } else { - if (IcarusHelper.hasWings.test(event.player)) { + if (IcarusHelper.hasWings(event.player)) { attributeInstance.addTransientModifier(WINGS_FLIGHT); } }