Skip to content

Commit

Permalink
further encapsulate state
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Apr 23, 2024
1 parent dbc05ee commit 2310d5d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class IcarusClient {
private static final List<Predicate<LivingEntity>> 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();
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ 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;
}

@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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> original) {
return original.call(instance, playerModelPart) && !IcarusHelper.hasWings.test(instance);
return original.call(instance, playerModelPart) && !IcarusHelper.hasWings(instance);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,9 +22,15 @@

public class IcarusHelper {

@ApiStatus.Internal
public static Predicate<LivingEntity> hasWings = entity -> false;

@ApiStatus.Internal
public static Function<LivingEntity, ItemStack> getEquippedWings = entity -> ItemStack.EMPTY;
@ApiStatus.Internal
public static BiPredicate<LivingEntity, ItemStack> equipFunc = (entity, stack) -> false;

@ApiStatus.Internal
public static IcarusPlayerValues fallbackValues = new ServerPlayerFallbackValues();

public static boolean onFallFlyingTick(LivingEntity entity, @Nullable ItemStack wings, boolean tick) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 2310d5d

Please sign in to comment.