Skip to content

Commit

Permalink
re-write part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Aug 22, 2024
1 parent b064615 commit 64fc89f
Show file tree
Hide file tree
Showing 15 changed files with 443 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.List;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.GlStateManager;
import io.github.axolotlclient.AxolotlClient;
import io.github.axolotlclient.AxolotlClientConfig.AxolotlClientConfigManager;
import io.github.axolotlclient.AxolotlClientConfig.common.ConfigHolder;
Expand All @@ -32,13 +31,7 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.item.BowItem;
import net.minecraft.item.FishingRodItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.MathHelper;

public class OldAnimations implements ClientModInitializer {

Expand All @@ -52,9 +45,10 @@ public class OldAnimations implements ClientModInitializer {

public final BooleanOption enabled = new BooleanOption("enabled", true);
public final BooleanOption useAndMine = new BooleanOption("useAndMine", true);
public final BooleanOption particles = new BooleanOption("particles", true);
public final BooleanOption particles = new BooleanOption("particles", true); /* use and mine particles */
public final BooleanOption blocking = new BooleanOption("blocking", true);
public final BooleanOption eatingAndDrinking = new BooleanOption("eatingAndDrinking", true);
public final BooleanOption itemPositions = new BooleanOption("itemPositions", true);
public final BooleanOption bow = new BooleanOption("bow", true);
public final BooleanOption rod = new BooleanOption("rod", true);
public final BooleanOption armourDamage = new BooleanOption("armorDamage", true);
Expand All @@ -66,7 +60,19 @@ public class OldAnimations implements ClientModInitializer {
private MinecraftClient mc;

public OldAnimations() {
category.add(enabled, useAndMine, particles, blocking, eatingAndDrinking, bow, rod, armourDamage, sneaking, debugOverlay);
category.add(
enabled,
useAndMine,
particles,
blocking,
eatingAndDrinking,
itemPositions,
bow,
rod,
armourDamage,
sneaking,
debugOverlay
);
AXOLOTLCLIENT = FabricLoader.getInstance().isModLoaded("axolotlclient");

if (!AXOLOTLCLIENT) {
Expand Down Expand Up @@ -107,44 +113,4 @@ public void tick() {
}
}
}

public static void oldDrinking(ItemStack itemToRender, AbstractClientPlayerEntity clientPlayer,
float partialTicks) {
float var14 = clientPlayer.getItemUseTicks() - partialTicks + 1.0F;
float var15 = 1.0F - var14 / itemToRender.getMaxUseTime();
float var16 = 1.0F - var15;
var16 = var16 * var16 * var16;
var16 = var16 * var16 * var16;
var16 = var16 * var16 * var16;
var16 -= 0.05F;
float var17 = 1.0F - var16;
GlStateManager.translate(0.0F, MathHelper.abs(MathHelper.cos(var14 / 4F * (float) Math.PI) * 0.11F)
* (var15 > 0.2D ? 1 : 0), 0.0F);
GlStateManager.translate(var17 * 0.6F, -var17 * 0.5F, 0.0F);
GlStateManager.rotate(var17 * 90.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(var17 * 10.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(var17 * 30.0F, 0.0F, 0.0F, 1.0F);
GlStateManager.translate(0, -0.0F, 0.06F);
GlStateManager.rotate(-4F, 1, 0, 0);
}

public static void oldBlocking() {
GlStateManager.scale(0.83F, 0.88F, 0.85F);
GlStateManager.translate(-0.3F, 0.1F, 0.0F);
}

public void transformItem(Item item) {
if (!(bow.get() || rod.get())) {
return;
}

// https://github.com/sp614x/optifine/issues/2098
if (mc.player.isUsingItem() && item instanceof BowItem) {
if (bow.get())
GlStateManager.translate(-0.01f, 0.05f, -0.06f);
} else if ((item instanceof FishingRodItem) && rod.get()) {
GlStateManager.translate(0.08f, -0.027f, -0.33f);
GlStateManager.scale(0.93f, 1.0f, 1.0f);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.github.axolotlclient.oldanimations.ducks;

/* welcome back! */
public interface Sneaky {

/* we need to easily share the interpolated eye height with some other classes */
float axolotlclient$getEyeHeight();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class ArmorFeatureRendererMixin {

@Inject(method = "combineTextures", at = @At("HEAD"), cancellable = true)
public void oldArmour(CallbackInfoReturnable<Boolean> callback) {
public void axolotlclient$oldArmour(CallbackInfoReturnable<Boolean> callback) {
if (OldAnimations.getInstance().enabled.get() && OldAnimations.getInstance().armourDamage.get())
callback.setReturnValue(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.github.axolotlclient.oldanimations.mixin;

import net.minecraft.client.render.entity.model.BiPedModel;
import net.minecraft.client.render.model.ModelPart;
import net.minecraft.entity.Entity;
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.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(BiPedModel.class)
public abstract class BiPedModelMixin {

@Shadow
public ModelPart rightArm;

@Inject(
method = "setAngles",
at = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/render/model/ModelPart;posY:F",
shift = At.Shift.AFTER
),
slice = @Slice(
from = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BiPedModel;rightArmPose:I",
ordinal = 0
),
to = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BiPedModel;rightArmPose:I",
ordinal = 2
)
)
)
private void axolotlclient$oldArmPosition(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn, CallbackInfo ci) {
rightArm.posY = 0.0f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
public class DebugHudMixin {

@Inject(method = "renderLeftText", at = @At("HEAD"), cancellable = true)
public void render(CallbackInfo callback) {
if (!active())
public void axolotlclient$renderLeftDebugText(CallbackInfo callback) {
if (!isDebugOverlayEnabled())
return;

callback.cancel();
Expand Down Expand Up @@ -111,8 +111,8 @@ public void render(CallbackInfo callback) {
}

@Inject(method = "renderRightText", at = @At("HEAD"), cancellable = true)
public void render(Window window, CallbackInfo callback) {
if (!active())
public void axolotlclient$renderRightDebugText(Window window, CallbackInfo callback) {
if (!isDebugOverlayEnabled())
return;

callback.cancel();
Expand Down Expand Up @@ -147,13 +147,14 @@ private static int getHeightValue(World world, int x, int y) {
}

@Shadow
private @Final MinecraftClient client;
@Final
private MinecraftClient client;

@Unique
private static final String[] DIRECTIONS = {"SOUTH", "WEST", "NORTH", "EAST"};

@Unique
private static boolean active() {
private static boolean isDebugOverlayEnabled() {
return OldAnimations.getInstance().enabled.get() && OldAnimations.getInstance().debugOverlay.get();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.github.axolotlclient.oldanimations.mixin;

import io.github.axolotlclient.oldanimations.OldAnimations;
import io.github.axolotlclient.oldanimations.ducks.Sneaky;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.entity.FishingBobberEntityRenderer;
import net.minecraft.entity.player.PlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(FishingBobberEntityRenderer.class)
public class FishingBobberEntityRendererMixin {

@ModifyArgs(method = "render(Lnet/minecraft/entity/projectile/FishingBobberEntity;DDDFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;<init>(DDD)V"))
private void axolotlclient$modifyLinePosition(Args args) {
if (isRodEnabled()) {
/* original values from 1.7 */
args.set(0, (double) args.get(0) - 0.24D);
args.set(2, (double) args.get(2) + 0.45D);
}
}

@ModifyConstant(method = "render(Lnet/minecraft/entity/projectile/FishingBobberEntity;DDDFF)V", constant = @Constant(doubleValue = 0.8D))
public double axolotlclient$moveLinePosition(double constant) {
/* original value from 1.7 */
if (isRodEnabled()) constant += 0.05D;
return constant;
}

@Redirect(method = "render(Lnet/minecraft/entity/projectile/FishingBobberEntity;DDDFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isSneaking()Z"))
public boolean axolotlclient$removeSneakTranslation(PlayerEntity instance) {
return !isRodEnabled() && instance.isSneaking();
}

@Redirect(method = "render(Lnet/minecraft/entity/projectile/FishingBobberEntity;DDDFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getEyeHeight()F"))
public float axolotlclient$useLerpEyeHeight_Fish(PlayerEntity instance) {
if (OldAnimations.getInstance().enabled.get() && OldAnimations.getInstance().rod.get()) {
return ((Sneaky) MinecraftClient.getInstance().gameRenderer).axolotlclient$getEyeHeight();
}
return instance.getEyeHeight();
}

@Unique
private static boolean isRodEnabled() {
return OldAnimations.getInstance().enabled.get() && OldAnimations.getInstance().rod.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,76 @@
package io.github.axolotlclient.oldanimations.mixin;

import io.github.axolotlclient.oldanimations.OldAnimations;
import io.github.axolotlclient.oldanimations.ducks.Sneaky;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.entity.Entity;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(GameRenderer.class)
public abstract class GameRendererMixin {
public abstract class GameRendererMixin implements Sneaky {

@Shadow
/* why you not final :( */
private MinecraftClient client;

@Unique
private float eyeHeightSubtractor;
private float lastCameraY;

@Unique
private float cameraY;

@Unique
private long lastEyeHeightUpdate;
private float eyeHeight;

@Inject(method = "setupCamera", at = @At("HEAD"))
protected void axolotlclient$lerpCamera(float partialTicks, int pass, CallbackInfo ci) {
/* eye height is interpolated between the last and current camera Y positions */
if (isSneakingEnabled()) eyeHeight = lerp(partialTicks, lastCameraY, cameraY);
}

@ModifyVariable(method = "transformCamera", at = @At(value = "STORE"), ordinal = 1)
private float oldanimations$modifyEyeHeight(float eyeHeight) {
private float axolotlclient$useLerpEyeHeight(float eyeHeight) {
return isSneakingEnabled() ? axolotlclient$getEyeHeight() : eyeHeight; /* player eye height */
}

@ModifyArg(method = "renderDebugCrosshair", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;translate(FFF)V"), index = 1)
public float axolotlclient$useLerpEyeHeight_Debug(float x) {
return isSneakingEnabled() ? axolotlclient$getEyeHeight() : x; /* debug crosshair parity */
}

Entity entity = this.client.getCameraEntity();
@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;updateHeldItems()V")) /* placed below null check */
private void axolotlclient$updateCameraY(CallbackInfo ci) {
/* updates the current eye height */
if (!isSneakingEnabled()) { return; }
Entity entity = client.getCameraEntity();
float eyeHeight = entity.getEyeHeight();
lastCameraY = cameraY;
if (eyeHeight < cameraY)
cameraY = eyeHeight;
else
cameraY += (eyeHeight - cameraY) * 0.5f;
}

@Unique
private static float lerp(float delta, float start, float end) { /* taken straight from modern minecraft */
return start + delta * (end - start);
}

@Unique
private static boolean isSneakingEnabled() {
return OldAnimations.getInstance().enabled.get() && OldAnimations.getInstance().sneaking.get();
}

if (OldAnimations.getInstance().enabled.get() && OldAnimations.getInstance().sneaking.get()) {
float height = eyeHeight;
if (entity.isSneaking()) {
height += 0.08F;
}
float actualEyeHeightSubtractor = entity.isSneaking() ? 0.08F : 0;
long sinceLastUpdate = System.currentTimeMillis() - lastEyeHeightUpdate;
lastEyeHeightUpdate = System.currentTimeMillis();
if (actualEyeHeightSubtractor > eyeHeightSubtractor) {
eyeHeightSubtractor += sinceLastUpdate / 500f;
if (actualEyeHeightSubtractor < eyeHeightSubtractor) {
eyeHeightSubtractor = actualEyeHeightSubtractor;
}
} else if (actualEyeHeightSubtractor < eyeHeightSubtractor) {
eyeHeightSubtractor -= sinceLastUpdate / 500f;
if (actualEyeHeightSubtractor > eyeHeightSubtractor) {
eyeHeightSubtractor = actualEyeHeightSubtractor;
}
}
return height - eyeHeightSubtractor;
}
return entity.getEyeHeight();
@Override
public float axolotlclient$getEyeHeight() {
return eyeHeight;
}
}
Loading

0 comments on commit 64fc89f

Please sign in to comment.