Skip to content

Commit

Permalink
this works!
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Mar 17, 2024
1 parent 1003782 commit f864325
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ public class LegacyAnimationsSettings {

@SerialEntry public boolean punchDuringUsage = true;
@SerialEntry public boolean oldSwordBlock = true; // TODO: this prevents an item in offhand (e.g., bow) from being used. Also causes to walk slow despite not actually blocking, may trigger ACs
@SerialEntry public boolean blockWithShieldOnly = true; // this fixes the aforementioned issue by requiring a shield in offhand
// @SerialEntry public boolean blockWithShieldOnly = true; // this fixes the aforementioned issue by requiring a shield in offhand
@SerialEntry public boolean hideShields = true;
@SerialEntry public boolean hideShieldHotbar = true;
@SerialEntry public boolean noCooldown = true;
@SerialEntry public boolean noShieldCooldown = true;
@SerialEntry public boolean oldSneaking = true;
@SerialEntry public boolean oldWalking = true;
@SerialEntry public boolean oldDeath = true;
Expand All @@ -36,7 +35,6 @@ public class LegacyAnimationsSettings {
@SerialEntry public boolean perspectiveCrosshair = true;
@SerialEntry public boolean oldProjectiles = true;
@SerialEntry public boolean oldViewBob = true;
@SerialEntry public boolean noDropSwing = true;
@SerialEntry public boolean fastItems = true;
@SerialEntry public boolean armorTint = true;

Expand All @@ -61,12 +59,12 @@ public static Screen configScreen(Screen parent) {
.binding(defaults.oldSwordBlock, () -> config.oldSwordBlock, newVal -> config.oldSwordBlock = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("Block Only when Holding Shield"))
.description(OptionDescription.of(Text.of("Only blocks with your sword when you hold a shield in your offhand.")))
.binding(defaults.blockWithShieldOnly, () -> config.blockWithShieldOnly, newVal -> config.blockWithShieldOnly = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
// .option(Option.createBuilder(boolean.class)
// .name(Text.literal("Block Only when Holding Shield"))
// .description(OptionDescription.of(Text.of("Only blocks with your sword when you hold a shield in your offhand.")))
// .binding(defaults.blockWithShieldOnly, () -> config.blockWithShieldOnly, newVal -> config.blockWithShieldOnly = newVal)
// .controller(TickBoxControllerBuilder::create)
// .build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("Hide Shield Model"))
.description(OptionDescription.of(Text.of("Hides the shield model from rendering.")))
Expand All @@ -79,12 +77,6 @@ public static Screen configScreen(Screen parent) {
.binding(defaults.hideShieldHotbar, () -> config.hideShieldHotbar, newVal -> config.hideShieldHotbar = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("No Shield Cooldown"))
.description(OptionDescription.of(Text.of("Removes the shield activation delay.")))
.binding(defaults.noShieldCooldown, () -> config.noShieldCooldown, newVal -> config.noShieldCooldown = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.build())

.category(ConfigCategory.createBuilder()
Expand Down Expand Up @@ -154,13 +146,7 @@ public static Screen configScreen(Screen parent) {
.name(Text.literal("Miscellaneous"))

.option(Option.createBuilder(boolean.class)
.name(Text.literal("Remove Swing Cooldown Animation"))
.description(OptionDescription.of(Text.of("Removes the swing animation played when dropping/throwing items!")))
.binding(defaults.noDropSwing, () -> config.noDropSwing, newVal -> config.noDropSwing = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("Remove Swing Animation on Throwing Items"))
.name(Text.literal("Remove Swing Animation"))
.description(OptionDescription.of(Text.of("Visually removes the swing cooldown animation!")))
.binding(defaults.noCooldown, () -> config.noCooldown, newVal -> config.noCooldown = newVal)
.controller(TickBoxControllerBuilder::create)
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.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
Expand All @@ -10,8 +11,11 @@
import net.minecraft.client.render.item.HeldItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShieldItem;
import net.minecraft.item.SwordItem;
import net.minecraft.util.Arm;
import net.minecraft.util.Hand;
import net.minecraft.util.math.RotationAxis;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -24,8 +28,10 @@
public abstract class HeldItemRendererMixin {

@Shadow protected abstract void applySwingOffset(MatrixStack matrices, Arm arm, float swingProgress);
@Shadow protected abstract void applyEquipOffset(MatrixStack matrices, Arm arm, float equipProgress);
@Shadow private float equipProgressOffHand;
@Shadow private ItemStack mainHand;
@Shadow private ItemStack offHand;

@Inject(
method = "renderFirstPersonItem",
Expand All @@ -46,15 +52,42 @@ public abstract class HeldItemRendererMixin {
)
)
private void addSwingOffset(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci, @Local Arm arm) {
if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage) {
applySwingOffset(matrices, arm, swingProgress);
}
// if (item.getUseAction() == UseAction.BLOCK) {
// matrices.translate(1 * -0.14142136F, 0.08F, 0.14142136F);
// matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-102.25F));
// matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(1 * 13.365F));
// matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(1 * 78.05F));
// }
if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage) {
applySwingOffset(matrices, arm, swingProgress);
}
}

@Inject(
method = "renderFirstPersonItem",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V",
ordinal = 1
)
)
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) {
if (LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock && item.getItem() instanceof SwordItem && player.getOffHandStack().getItem() instanceof ShieldItem && player.isUsingItem()) {
boolean bl = hand == Hand.MAIN_HAND;
Arm arm = bl ? player.getMainArm() : player.getMainArm().getOpposite();
boolean bl2 = arm == Arm.RIGHT;
int l = bl2 ? 1 : -1;
matrices.translate(l * -0.14142136F, 0.08F, 0.14142136F);
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-102.25F));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(l * 13.365F));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(l * 78.05F));
}
}

@WrapWithCondition(
method = "renderFirstPersonItem",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/util/math/MatrixStack;translate(FFF)V",
ordinal = 12
)
)
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) {
return !LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock || !(item.getItem() instanceof SwordItem) || !(player.getOffHandStack().getItem() instanceof ShieldItem) || !player.isUsingItem();
}

@WrapOperation(
Expand All @@ -70,12 +103,12 @@ public float removeCoolDownSpeed(ClientPlayerEntity instance, float v, Operation
return original.call(instance, v);
}

// @Inject(method = "resetEquipProgress", at = @At("HEAD"), cancellable = true)
// private void removeStartDelay(Hand hand, CallbackInfo ci) {
// if (LegacyAnimationsSettings.CONFIG.instance().noCooldown) {
// ci.cancel();
// }
// }
@Inject(method = "resetEquipProgress", at = @At("HEAD"), cancellable = true)
private void removeStartDelay(Hand hand, CallbackInfo ci) {
if (LegacyAnimationsSettings.CONFIG.instance().noCooldown) {
ci.cancel();
}
}

@ModifyArg(
method = "updateHeldItems",
Expand All @@ -87,7 +120,7 @@ public float removeCoolDownSpeed(ClientPlayerEntity instance, float v, Operation
index = 0
)
private float conditionallyUpdateShield(float value, @Local(ordinal = 0) ItemStack itemStack) {
if (LegacyAnimationsSettings.CONFIG.instance().hideShields) {
if (LegacyAnimationsSettings.CONFIG.instance().hideShields && offHand.getItem() instanceof ShieldItem) {
return (mainHand == itemStack ? 1.0F : 0.0F) - equipProgressOffHand;
}
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@

import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import com.mixces.legacyanimations.duck.PlayerPitchInterface;
import com.mixces.legacyanimations.util.ServerUtils;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@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;

@ModifyConstant(method = "isBlocking", constant = @Constant(intValue = 5))
private int isBlocking_fixSync(int constant) {
if (LegacyAnimationsSettings.CONFIG.instance().noShieldCooldown) {
if (ServerUtils.INSTANCE.isOnHypixel()) {
return 0;
}
return constant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import com.mixces.legacyanimations.util.ServerUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SwordItem;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {

@Shadow @Nullable public ClientPlayerEntity player;
@Shadow public ClientPlayerEntity player;

@Shadow private static MinecraftClient instance;
@Shadow public int attackCooldown;

@ModifyExpressionValue(
method = "doItemUse",
Expand Down Expand Up @@ -68,25 +62,15 @@ private void swapForFakeSwing(ClientPlayerEntity instance, Hand hand) {
}

@Inject(
method = "tick",
method = "doAttack",
at = @At(
value = "HEAD"
)
)
private void fakeShield(CallbackInfo ci) {
// if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage && instance.isUsingItem()) {
// legacyAnimations$fakeSwingHand(instance, hand);
// } else {
// instance.swingHand(hand);
// }

if (player == null) return;

if (player.getInventory().offHand.isEmpty()) {

player.getInventory().offHand.set(EquipmentSlot.OFFHAND.getEntitySlotId(), new ItemStack(Items.SHIELD));
private void allowWhileUsingItema(CallbackInfoReturnable<Boolean> cir) {
if (ServerUtils.INSTANCE.isOnHypixel()) {
attackCooldown = 0;
}

}

@Unique
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import com.mixces.legacyanimations.util.ItemUtils;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.StairsBlock;
import com.mixces.legacyanimations.util.ServerUtils;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SwordItem;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin extends LivingEntityMixin {

// @Inject(method = "resetLastAttackedTicks", at = @At("HEAD"), cancellable = true)
// private void resetLastAttackedTicks_removeDelay(CallbackInfo ci) {
// ci.cancel();
// }
@Inject(method = "resetLastAttackedTicks", at = @At("HEAD"), cancellable = true)
private void resetLastAttackedTicks_removeDelay(CallbackInfo ci) {
if (ServerUtils.INSTANCE.isOnHypixel()) {
ci.cancel();
}
}

@Shadow protected abstract boolean canChangeIntoPose(EntityPose pose);

@ModifyReturnValue(
method = "getActiveEyeHeight",
Expand All @@ -29,7 +38,7 @@ public abstract class PlayerEntityMixin extends LivingEntityMixin {
)
private float modifyEyeHeight(float constant) {
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking) {
if (ItemUtils.getBlock(0, 1, 0) instanceof SlabBlock || ItemUtils.getBlock(0, 1, 0) instanceof StairsBlock) {
if (!canChangeIntoPose(EntityPose.STANDING)) {
return constant;
} else {
return constant + 0.27F;
Expand Down Expand Up @@ -59,17 +68,17 @@ private void getPitchFromVelocity(CallbackInfo ci) {
}
}

// @Redirect(
// method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;",
// at = @At(
// value = "INVOKE",
// target = "Lnet/minecraft/entity/player/PlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"
// )
// )
// private void removeSwingAnimation2(PlayerEntity instance, Hand hand) {
// if (!LegacyAnimationsSettings.CONFIG.instance().noDropSwing) {
// instance.swingHand(hand);
// }
// }
@Inject(
method = "getEquippedStack",
at = @At(
value = "RETURN",
ordinal = 1
),
cancellable = true)
private void hypixelShieldBug(EquipmentSlot slot, CallbackInfoReturnable<ItemStack> cir) {
if (ServerUtils.INSTANCE.isOnHypixel() && getMainHandStack().getItem() instanceof SwordItem && !isUsingItem()) {
cir.setReturnValue(new ItemStack(Items.SHIELD));
}
}

}
Loading

0 comments on commit f864325

Please sign in to comment.