From 265298e8ca4ab443ef9ca8cf3acd409638831a7a Mon Sep 17 00:00:00 2001 From: Mixces Date: Tue, 19 Mar 2024 17:31:03 -0500 Subject: [PATCH] some little changes --- .../mixin/BuiltinModelItemRendererMixin.java | 2 +- .../FishingBobberEntityRendererMixin.java | 26 +++++++++---------- .../mixin/FlyingItemEntityRendererMixin.java | 2 +- .../mixin/HeldItemRendererMixin.java | 9 +++---- .../mixin/InGameHudMixin.java | 2 +- .../mixin/ItemEntityRendererMixin.java | 4 +-- .../mixin/ItemRendererMixin.java | 2 +- .../mixin/LivingEntityMixin.java | 4 --- .../legacyanimations/util/HandUtils.java | 8 +++--- .../legacyanimations/util/ItemUtils.java | 14 +++++++--- .../legacyanimations/util/ServerUtils.java | 1 - src/main/resources/fabric.mod.json | 3 ++- 12 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java index f02edd1..ab62e73 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java @@ -29,7 +29,7 @@ private boolean disableShieldRendering(boolean original, ItemStack stack, ModelT if (LegacyAnimationsSettings.CONFIG.instance().hideShields && MinecraftClient.getInstance().player != null && TransformationModeUtils.isValidPerspective(mode)) { ItemStack heldStack = MinecraftClient.getInstance().player.getMainHandStack(); UseAction action = heldStack.getUseAction(); - if (ItemUtils.isValidItem(heldStack, action)) + if (ItemUtils.INSTANCE.isValidItem(heldStack, action)) return false; } return original; diff --git a/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java index a22adb2..ac6db2b 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java @@ -1,5 +1,6 @@ package com.mixces.legacyanimations.mixin; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.sugar.Local; import com.mixces.legacyanimations.config.LegacyAnimationsSettings; import com.mixces.legacyanimations.util.HandUtils; @@ -17,7 +18,6 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -39,7 +39,7 @@ protected FishingBobberEntityRendererMixin(EntityRendererFactory.Context ctx) { public void shiftRodBob(FishingBobberEntity fishingBobberEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) { ClientPlayerEntity player = MinecraftClient.getInstance().player; if (LegacyAnimationsSettings.CONFIG.instance().oldProjectiles && player != null) { - matrixStack.translate(HandUtils.handMultiplier(player, dispatcher) * 0.25F, 0.0F, 0.0F); + matrixStack.translate(HandUtils.INSTANCE.handMultiplier(player, dispatcher) * 0.25F, 0.0F, 0.0F); } } @@ -54,17 +54,15 @@ public float useInterpolatedEyeHeight(PlayerEntity instance) { return MathHelper.lerp(dispatcher.camera.getLastTickDelta(), ((AccessorCamera) dispatcher.camera).getLastCameraY(), ((AccessorCamera) dispatcher.camera).getCameraY()); } - // todo Fix rod line -// @ModifyArg( -// method = "render(Lnet/minecraft/entity/projectile/FishingBobberEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", -// at = @At( -// value = "INVOKE", -// target = "Lnet/minecraft/client/render/Camera$Projection;getPosition(FF)Lnet/minecraft/util/math/Vec3d;" -// ), -// index = 0 -// ) -// public float fixWrongRod(float factorX, @Local(ordinal = 0) PlayerEntity playerEntity) { -// return (playerEntity.getOffHandStack().isOf(Items.FISHING_ROD) ? -1 : 1) * factorX; -// } + @ModifyExpressionValue( + method = "render(Lnet/minecraft/entity/projectile/FishingBobberEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z" + ) + ) + public boolean fixWrongRodLine(boolean original, @Local(ordinal = 0) PlayerEntity playerEntity) { + return original || !playerEntity.getOffHandStack().isOf(Items.FISHING_ROD); + } } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/FlyingItemEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/FlyingItemEntityRendererMixin.java index fca4a3d..e984e72 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/FlyingItemEntityRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/FlyingItemEntityRendererMixin.java @@ -61,7 +61,7 @@ public void shiftProjectile(T entity, float yaw, float tickDelta, MatrixStack ma ) private float rotateProjectileAccordingly(float deg) { if (LegacyAnimationsSettings.CONFIG.instance().oldProjectiles && MinecraftClient.getInstance().player != null) { - boolean isLeftHand = HandUtils.isLeftHand(MinecraftClient.getInstance().player, dispatcher); + boolean isLeftHand = HandUtils.INSTANCE.isLeftHand(MinecraftClient.getInstance().player, dispatcher); if (!dispatcher.gameOptions.getPerspective().isFrontView()) { return isLeftHand ? deg - 180.0F : deg; } else { diff --git a/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java index f3a5e32..8e46cad 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java @@ -5,8 +5,7 @@ import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; import com.mixces.legacyanimations.config.LegacyAnimationsSettings; -import com.mixces.legacyanimations.util.ServerUtils; -import net.minecraft.client.MinecraftClient; +import com.mixces.legacyanimations.util.ItemUtils; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.render.VertexConsumerProvider; @@ -67,8 +66,7 @@ private void addSwingOffset(AbstractClientPlayerEntity player, float tickDelta, ) ) private void addSwordBlock(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { - boolean isUsing = ServerUtils.INSTANCE.isOnHypixel() ? MinecraftClient.getInstance().options.useKey.isPressed() : player.isUsingItem(); - if (LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock && item.getItem() instanceof SwordItem && player.getOffHandStack().getItem() instanceof ShieldItem && isUsing) { + if (LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock && item.getItem() instanceof SwordItem && player.getOffHandStack().getItem() instanceof ShieldItem && ItemUtils.INSTANCE.isUsing((ClientPlayerEntity) player)) { boolean bl = hand == Hand.MAIN_HAND; Arm arm = bl ? player.getMainArm() : player.getMainArm().getOpposite(); boolean bl2 = arm == Arm.RIGHT; @@ -89,8 +87,7 @@ private void addSwordBlock(AbstractClientPlayerEntity player, float tickDelta, f ) ) private boolean disableSwingTranslation(MatrixStack instance, float x, float y, float z, AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) { - boolean isUsing = ServerUtils.INSTANCE.isOnHypixel() ? MinecraftClient.getInstance().options.useKey.isPressed() : player.isUsingItem(); - return !LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock || !(item.getItem() instanceof SwordItem) || !(player.getOffHandStack().getItem() instanceof ShieldItem) || !isUsing; + return !LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock || !(item.getItem() instanceof SwordItem) || !(player.getOffHandStack().getItem() instanceof ShieldItem) || !ItemUtils.INSTANCE.isUsing((ClientPlayerEntity) player); } @WrapOperation( diff --git a/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java index f8affd1..a2b412a 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java @@ -25,7 +25,7 @@ private boolean cancelOffhandHotbar(ItemStack itemStack, Operation orig if (player != null) { ItemStack stack = player.getMainHandStack(); UseAction action = stack.getUseAction(); - if (LegacyAnimationsSettings.CONFIG.instance().hideShieldHotbar && ItemUtils.isValidItem(stack, action)) { + if (LegacyAnimationsSettings.CONFIG.instance().hideShieldHotbar && ItemUtils.INSTANCE.isValidItem(stack, action)) { return original.call(itemStack) || player.getOffHandStack().isOf(Items.SHIELD); } } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java index b4fe4b8..0242ddc 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java @@ -47,11 +47,11 @@ private Quaternionf facePlayer(Quaternionf quaternion, @Local(ordinal = 0) boole private void rotateItemAccordingly(ItemEntity itemEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci, @Local(ordinal = 0) boolean bl) { if (LegacyAnimationsSettings.CONFIG.instance().fastItems && MinecraftClient.getInstance().player != null && !bl) { if (dispatcher.gameOptions.getPerspective().isFrontView()) { - if (HandUtils.isLeftHand(MinecraftClient.getInstance().player, dispatcher)) { + if (HandUtils.INSTANCE.isLeftHand(MinecraftClient.getInstance().player, dispatcher)) { matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180)); } } else { - if (HandUtils.isRightHand(MinecraftClient.getInstance().player, dispatcher)) { + if (HandUtils.INSTANCE.isRightHand(MinecraftClient.getInstance().player, dispatcher)) { matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180)); } } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java index 3f96777..a28a17d 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java @@ -33,7 +33,7 @@ public class ItemRendererMixin { @ModifyArg(method = "renderBakedItemModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;renderBakedItemQuads(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;Ljava/util/List;Lnet/minecraft/item/ItemStack;II)V", ordinal = 1), index = 2) private List changeToSprite(List quads, @Local(ordinal = 0) BakedModel model) { if (LegacyAnimationsSettings.CONFIG.instance().fastItems && client.player != null && TransformationModeUtils.shouldBeSprite() && !model.hasDepth()) { - boolean isLeftHand = HandUtils.isLeftHand(client.player, client.getEntityRenderDispatcher()); + boolean isLeftHand = HandUtils.INSTANCE.isLeftHand(client.player, client.getEntityRenderDispatcher()); boolean isFrontView = client.getEntityRenderDispatcher().gameOptions.getPerspective().isFrontView(); Direction perspectiveFace = legacyAnimations$determineDirection(isFrontView, isLeftHand); if (TransformationModeUtils.getTransformationMode() == ModelTransformationMode.GROUND) { diff --git a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java index 544ff12..94f743a 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java @@ -15,12 +15,8 @@ @Mixin(LivingEntity.class) public abstract class LivingEntityMixin implements PlayerPitchInterface { - @Shadow public abstract boolean isBlocking(); - @Shadow public abstract ItemStack getMainHandStack(); - @Shadow public abstract boolean isUsingItem(); - @Unique public float legacyAnimations$prevCameraPitch; @Unique public float legacyAnimations$cameraPitch; diff --git a/src/main/java/com/mixces/legacyanimations/util/HandUtils.java b/src/main/java/com/mixces/legacyanimations/util/HandUtils.java index 22d51d1..43f0c3e 100644 --- a/src/main/java/com/mixces/legacyanimations/util/HandUtils.java +++ b/src/main/java/com/mixces/legacyanimations/util/HandUtils.java @@ -8,7 +8,9 @@ public class HandUtils { - public static int handMultiplier(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) { + public static HandUtils INSTANCE = new HandUtils(); + + public int handMultiplier(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) { Hand hand = MoreObjects.firstNonNull(player.preferredHand, Hand.MAIN_HAND); boolean bl = hand == Hand.MAIN_HAND; Arm arm = bl ? player.getMainArm() : player.getMainArm().getOpposite(); @@ -18,11 +20,11 @@ public static int handMultiplier(ClientPlayerEntity player, EntityRenderDispatch return bl2 ? perspectiveMultiplier : -perspectiveMultiplier; } - public static boolean isLeftHand(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) { + public boolean isLeftHand(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) { return handMultiplier(player, dispatcher) == -1; } - public static boolean isRightHand(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) { + public boolean isRightHand(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) { return handMultiplier(player, dispatcher) == 1; } diff --git a/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java b/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java index afb6f90..6edd0e2 100644 --- a/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java +++ b/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java @@ -1,6 +1,8 @@ package com.mixces.legacyanimations.util; import com.mixces.legacyanimations.mixin.FoodComponentAccessor; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.item.FishingRodItem; import net.minecraft.item.ItemStack; import net.minecraft.item.SwordItem; @@ -8,8 +10,10 @@ public class ItemUtils { - public static boolean isValidItem(ItemStack heldStack, UseAction action) { - if (isValidHeldItem(heldStack) || + public static ItemUtils INSTANCE = new ItemUtils(); + + public boolean isValidItem(ItemStack heldStack, UseAction action) { + if (ItemUtils.INSTANCE.isValidHeldItem(heldStack) || (action == UseAction.EAT && heldStack.getItem().getFoodComponent() != null && ((FoodComponentAccessor) heldStack.getItem().getFoodComponent()).getAlwaysEdible())) { return true; @@ -19,8 +23,12 @@ public static boolean isValidItem(ItemStack heldStack, UseAction action) { return false; } - public static boolean isValidHeldItem(ItemStack heldStack) { + public boolean isValidHeldItem(ItemStack heldStack) { return heldStack.getItem() instanceof SwordItem || heldStack.getItem() instanceof FishingRodItem; } + public boolean isUsing(ClientPlayerEntity player) { + return ServerUtils.INSTANCE.isOnHypixel() ? MinecraftClient.getInstance().options.useKey.isPressed() : player.isUsingItem(); + } + } diff --git a/src/main/java/com/mixces/legacyanimations/util/ServerUtils.java b/src/main/java/com/mixces/legacyanimations/util/ServerUtils.java index 79cce5d..ac8392d 100644 --- a/src/main/java/com/mixces/legacyanimations/util/ServerUtils.java +++ b/src/main/java/com/mixces/legacyanimations/util/ServerUtils.java @@ -2,7 +2,6 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ServerInfo; -import net.minecraft.world.World; public class ServerUtils { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 258d59e..99b1296 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -8,7 +8,8 @@ "Mixces", "Wyvest", "Microcontrollers", - "ImToggle" + "ImToggle", + "Cecer (CecerMCProjects)" ], "contact": { "homepage": "https://github.com/Mixces",