Skip to content

Commit

Permalink
Added various features surrounding the fishing rod
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Dec 14, 2024
1 parent 2799d3c commit f9c9c54
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 4 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ Currently, there are no releases. If you want to use a development build, you ca
- [X] oldChatPosition
- Description: TODO
- Type: BOOLEAN
- [X] disableProjectileAgeCheck
- Description: TODO
- Type: BOOLEAN
- [X] oldFishingBobberPosition
- Description: TODO
- Type: BOOLEAN
- [X] fishingRodLineInterpolation
- Description: TODO
- Type: BOOLEAN
- [X] noMoveFishingRodLine
- Description: TODO
- Type: BOOLEAN
- [X] oldFishingRodLinePositionThirdPerson
- Description: TODO
- Type: BOOLEAN
- [X] fixCastLineCheck
- Description: TODO
- Type: BOOLEAN
- [X] fixCastLineSwing
- Description: TODO
- Type: BOOLEAN
- [X] cameraVersion
- Description: TODO
- Type: ENUM
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/me/mixces/animatium/config/AnimatiumConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ public class AnimatiumConfig extends MidnightConfig {
@Entry
public static boolean oldChatPosition = true; // Moves chat down 12 pixels like in <=1.8

@Entry
public static boolean disableProjectileAgeCheck = true; // Render projectile at all ages <=1.15?

@Entry
public static boolean oldFishingBobberPosition = true; // Brings back old fishing bobber position <=1.8?

@Entry
public static boolean fishingRodLineInterpolation = true; // Correctly interpolates the fishing rod cast line with the eye height <1.14?

@Entry
public static boolean noMoveFishingRodLine = true; // Does not move the fishing rod cast line while sneaking when viewed in the third person mode <=1.7

@Entry
public static boolean oldFishingRodLinePositionThirdPerson = true; // Adjusts the position of the fishing rod cast line horizontally like in <=1.7

@Entry
public static boolean fixCastLineCheck = true; // Fixes the arm logic for casting the fishing rod

@Entry
public static boolean fixCastLineSwing = true; // Fixes the swing logic for casting the fishing rod

@Entry
public static CameraVersion cameraVersion = CameraVersion.v1_8; // Change the camera position to be as it was in said version range

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package me.mixces.animatium.mixins;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import me.mixces.animatium.config.AnimatiumConfig;
import me.mixces.animatium.mixins.accessor.CameraAccessor;
import me.mixces.animatium.util.HandUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.FishingBobberEntityRenderer;
import net.minecraft.client.render.entity.state.FishingBobberEntityState;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.FishingBobberEntity;
import net.minecraft.item.FishingRodItem;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
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.callback.CallbackInfo;

@Mixin(FishingBobberEntityRenderer.class)
public abstract class MixinFishingBobberEntityRenderer extends EntityRenderer<FishingBobberEntity, FishingBobberEntityState> {
protected MixinFishingBobberEntityRenderer(EntityRendererFactory.Context ctx) {
super(ctx);
}

@Inject(method = "render(Lnet/minecraft/client/render/entity/state/FishingBobberEntityState;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;peek()Lnet/minecraft/client/util/math/MatrixStack$Entry;", ordinal = 0))
private void animatium$shiftFishingBobber(FishingBobberEntityState fishingBobberEntityState, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) {
if (AnimatiumConfig.oldFishingBobberPosition) {
HandUtils instance = new HandUtils(MinecraftClient.getInstance().player, dispatcher);
//TODO: Fix line
matrixStack.translate(instance.handMultiplier() * 0.5F, 0.0F, 0.0F);
}
}

@WrapOperation(method = "getHandPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getCameraPosVec(F)Lnet/minecraft/util/math/Vec3d;"))
private Vec3d animatium$useInterpolatedEyeHeight(PlayerEntity instance, float v, Operation<Vec3d> original) {
if (AnimatiumConfig.fishingRodLineInterpolation) {
CameraAccessor cameraAccessor = (CameraAccessor) dispatcher.camera;
float eyeHeight = MathHelper.lerp(v, cameraAccessor.getLastCameraY(), cameraAccessor.getCameraY());
return this.animatium$getCameraPosVec(instance, v, eyeHeight);
}
return original.call(instance, v);
}

@ModifyExpressionValue(method = "getHandPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isInSneakingPose()Z"))
private boolean animatium$removeLineOffset(boolean original) {
return !AnimatiumConfig.noMoveFishingRodLine && original;
}

@ModifyExpressionValue(method = "getHandPos", at = @At(value = "CONSTANT", args = "doubleValue=0.8"))
private double animatium$moveLineHorizontally(double original) {
return original + (AnimatiumConfig.oldFishingRodLinePositionThirdPerson ? 0.05 : 0.0);
}

@WrapOperation(method = "getArmHoldingRod", at = @At(value = "CONSTANT", args = "classValue=net/minecraft/item/FishingRodItem"))
private static boolean animatium$fixCastLineCheck(Object object, Operation<Boolean> original, @Local(argsOnly = true) PlayerEntity player) {
return original.call(object) || (AnimatiumConfig.fixCastLineCheck && !(player.getOffHandStack().getItem() instanceof FishingRodItem));
}

@ModifyArg(method = "updateRenderState(Lnet/minecraft/entity/projectile/FishingBobberEntity;Lnet/minecraft/client/render/entity/state/FishingBobberEntityState;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/FishingBobberEntityRenderer;getHandPos(Lnet/minecraft/entity/player/PlayerEntity;FF)Lnet/minecraft/util/math/Vec3d;"), index = 1)
private float animatium$mirrorRodSwing(float f) {
HandUtils instance = new HandUtils(MinecraftClient.getInstance().player, dispatcher);
int multiplier = instance.handMultiplier();
return f * (AnimatiumConfig.fixCastLineSwing ? multiplier : 1);
}

@Unique
private Vec3d animatium$getCameraPosVec(PlayerEntity entity, float tickDelta, float eyeHeight) {
double d = MathHelper.lerp(tickDelta, entity.prevX, entity.getX());
double e = MathHelper.lerp(tickDelta, entity.prevY, entity.getY()) + eyeHeight;
double f = MathHelper.lerp(tickDelta, entity.prevZ, entity.getZ());
return new Vec3d(d, e, f);
}
}
16 changes: 16 additions & 0 deletions src/main/java/me/mixces/animatium/mixins/MixinThrownEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.mixces.animatium.mixins;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import me.mixces.animatium.config.AnimatiumConfig;
import net.minecraft.entity.projectile.thrown.ThrownEntity;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(ThrownEntity.class)
public abstract class MixinThrownEntity {
@ModifyExpressionValue(method = "shouldRender", at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lnet/minecraft/entity/projectile/thrown/ThrownEntity;age:I"))
private int animatium$disableProjectileAgeCheck(int original) {
return original + (AnimatiumConfig.disableProjectileAgeCheck ? 2 : 0);
}
}
24 changes: 24 additions & 0 deletions src/main/java/me/mixces/animatium/util/HandUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.mixces.animatium.util;

import com.google.common.base.MoreObjects;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.util.Arm;
import net.minecraft.util.Hand;

public class HandUtils {
private final EntityRenderDispatcher dispatcher;
private final ClientPlayerEntity player;

public HandUtils(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) {
this.player = player;
this.dispatcher = dispatcher;
}

public int handMultiplier() {
Hand hand = MoreObjects.firstNonNull(player.preferredHand, Hand.MAIN_HAND);
Arm arm = hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite();
int i = dispatcher.gameOptions.getPerspective().isFirstPerson() ? 1 : -1;
return arm == Arm.RIGHT ? i : -i;
}
}
8 changes: 4 additions & 4 deletions src/main/resources/animatium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"MixinDebugHud",
"MixinEntityRenderer",
"MixinEntryListWidget",
"MixinFishingBobberEntityRenderer",
"MixinGameRenderer",
"MixinHeldItemRenderer",
"MixinInGameHud",
Expand All @@ -23,16 +24,15 @@
"MixinScrollableWidget",
"MixinSliderWidget",
"MixinTextRendererDrawer",
"MixinThrownEntity",
"MixinWorldRenderer",
"accessor.CameraAccessor",
"accessor.ClientWorldPropertiesAccessor",
"accessor.EntryListWidgetAccessor",
"accessor.PlayerEntityAccessor",
"accessor.SkyRenderingAccessor"
],
"injectors": {
"defaultRequire": 1
},
"mixins": [
"accessor.PlayerEntityAccessor"
]
}
}
14 changes: 14 additions & 0 deletions src/main/resources/assets/animatium/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@
"animatium.midnightconfig.debugHudTextShadow.tooltip": "TODO",
"animatium.midnightconfig.oldChatPosition": "Old chat position (1.8)",
"animatium.midnightconfig.oldChatPosition.tooltip": "TODO",
"animatium.midnightconfig.disableProjectileAgeCheck": "Render projectile at all ages",
"animatium.midnightconfig.disableProjectileAgeCheck.tooltip": "TODO",
"animatium.midnightconfig.oldFishingBobberPosition": "Bring back the old fishing bobber position",
"animatium.midnightconfig.oldFishingBobberPosition.tooltip": "TODO",
"animatium.midnightconfig.fishingRodLineInterpolation": "Correctly interpolate the fishing rod cast line with the eye height",
"animatium.midnightconfig.fishingRodLineInterpolation.tooltip": "TODO",
"animatium.midnightconfig.noMoveFishingRodLine": "Disable fishing line movement while sneaking in third person",
"animatium.midnightconfig.noMoveFishingRodLine.tooltip": "TODO",
"animatium.midnightconfig.oldFishingRodLinePositionThirdPerson": "Old third person fishing rod cast line position",
"animatium.midnightconfig.oldFishingRodLinePositionThirdPerson.tooltip": "TODO",
"animatium.midnightconfig.fixCastLineCheck": "Fix arm-related fishing rod cast line check (Fixes MC-109263)",
"animatium.midnightconfig.fixCastLineCheck.tooltip": "TODO",
"animatium.midnightconfig.fixCastLineSwing": "Fix left handed fishing rod swing bug",
"animatium.midnightconfig.fixCastLineSwing.tooltip": "TODO",
"animatium.midnightconfig.cameraVersion": "Change camera position to be as it was in",
"animatium.midnightconfig.cameraVersion.tooltip": "TODO",

Expand Down

0 comments on commit f9c9c54

Please sign in to comment.