Skip to content

Commit

Permalink
some little changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Mar 19, 2024
1 parent ff206f7 commit 265298e
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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);
}
}

Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private boolean cancelOffhandHotbar(ItemStack itemStack, Operation<Boolean> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BakedQuad> changeToSprite(List<BakedQuad> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/mixces/legacyanimations/util/HandUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}

Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/mixces/legacyanimations/util/ItemUtils.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
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;
import net.minecraft.util.UseAction;

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;
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.world.World;

public class ServerUtils {

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"Mixces",
"Wyvest",
"Microcontrollers",
"ImToggle"
"ImToggle",
"Cecer (CecerMCProjects)"
],
"contact": {
"homepage": "https://github.com/Mixces",
Expand Down

0 comments on commit 265298e

Please sign in to comment.