Skip to content

Commit

Permalink
hope this doesnt explode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Feb 29, 2024
1 parent 7dde0ef commit bcb387e
Show file tree
Hide file tree
Showing 39 changed files with 719 additions and 453 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ loom {
runs {
remove server
}

accessWidenerPath = file("src/main/resources/legacyanimations.accesswidener")
}

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ loader_version=0.15.6

# Mod Properties
mod_version=1.0.0
maven_group=com.mixces.oldanimations
archives_base_name=oldanimations
maven_group=com.mixces.legacyanimations
archives_base_name=legacyanimations

# Dependencies
fabric_version=0.95.0+1.20.4
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/mixces/legacyanimations/LegacyAnimations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mixces.legacyanimations;

import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import net.fabricmc.api.ModInitializer;

public class LegacyAnimations implements ModInitializer {

@Override
public void onInitialize() {
LegacyAnimationsSettings.CONFIG.load();
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mixces.oldanimations.config;
package com.mixces.legacyanimations.config;

import dev.isxander.yacl3.api.ConfigCategory;
import dev.isxander.yacl3.api.Option;
Expand All @@ -12,11 +12,11 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;

public class OldAnimationsSettings {
public class LegacyAnimationsSettings {

public static final ConfigClassHandler<OldAnimationsSettings> CONFIG = ConfigClassHandler.createBuilder(OldAnimationsSettings.class)
public static final ConfigClassHandler<LegacyAnimationsSettings> CONFIG = ConfigClassHandler.createBuilder(LegacyAnimationsSettings.class)
.serializer(config -> GsonConfigSerializerBuilder.create(config)
.setPath(FabricLoader.getInstance().getConfigDir().resolve("oldanimations.json"))
.setPath(FabricLoader.getInstance().getConfigDir().resolve("legacyanimations.json"))
.build())
.build();

Expand All @@ -39,9 +39,13 @@ public class OldAnimationsSettings {
@SerialEntry
public boolean oldDeath = true;
@SerialEntry
public boolean potionGlint = true;
public boolean oldSwim = true;
@SerialEntry
public boolean oldHearts = true;
@SerialEntry
public boolean oldDebug = true;
@SerialEntry
public boolean perspectiveCrosshair = true;


@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -105,9 +109,9 @@ public static Screen configScreen(Screen parent) {
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("Potion Glint Effect"))
.description(OptionDescription.of(Text.of("Returns the glint effect on potions.")))
.binding(defaults.potionGlint, () -> config.potionGlint, newVal -> config.potionGlint = newVal)
.name(Text.literal("Old Swimming Animation"))
.description(OptionDescription.of(Text.of("Reverts the swimming animation to it's former glory.")))
.binding(defaults.oldSwim, () -> config.oldSwim, newVal -> config.oldSwim = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
Expand All @@ -116,6 +120,18 @@ public static Screen configScreen(Screen parent) {
.binding(defaults.oldDebug, () -> config.oldDebug, newVal -> config.oldDebug = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("Old Health Flashing"))
.description(OptionDescription.of(Text.of("Brings back the old hotbar health flashing appearance.")))
.binding(defaults.oldHearts, () -> config.oldHearts, newVal -> config.oldHearts = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("Third Person Mode Crosshair"))
.description(OptionDescription.of(Text.of("Brings back the crosshair in third person mode.")))
.binding(defaults.perspectiveCrosshair, () -> config.perspectiveCrosshair, newVal -> config.perspectiveCrosshair = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.build())
)).generateScreen(parent);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mixces.oldanimations.config;
package com.mixces.legacyanimations.config;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
Expand All @@ -9,6 +9,6 @@
public class ModMenuIntegration implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return OldAnimationsSettings::configScreen;
return LegacyAnimationsSettings::configScreen;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mixces.legacyanimations.mixin;

import net.minecraft.client.render.Camera;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(Camera.class)
public interface AccessorCamera {

@Accessor float getCameraY();

@Accessor float getLastCameraY();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
package com.mixces.legacyanimations.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.sugar.Local;
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.Arm;
import net.minecraft.util.Hand;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(BipedEntityModel.class)
public abstract class BipedEntityModelMixin<T extends LivingEntity> {

@Shadow protected abstract void positionRightArm(T entity);
@Shadow protected abstract void positionLeftArm(T entity);
@Shadow public BipedEntityModel.ArmPose leftArmPose;
@Shadow public BipedEntityModel.ArmPose rightArmPose;

@ModifyExpressionValue(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/LivingEntity;isUsingItem()Z",
ordinal = 0
)
)
public boolean removeCondition(boolean original) {
return !LegacyAnimationsSettings.CONFIG.instance().oldSneaking && original;
}

@WrapWithCondition(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;positionRightArm(Lnet/minecraft/entity/LivingEntity;)V"
)
)
public boolean removeMethodCall1(BipedEntityModel<?> instance, T entity) {
return !LegacyAnimationsSettings.CONFIG.instance().oldSneaking;
}

@WrapWithCondition(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;positionLeftArm(Lnet/minecraft/entity/LivingEntity;)V"
)
)
public boolean removeMethodCall2(BipedEntityModel<?> instance, T entity) {
return !LegacyAnimationsSettings.CONFIG.instance().oldSneaking;
}

@Inject(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
at = @At(
value = "JUMP",
opcode = Opcodes.IF_ACMPEQ,
ordinal = 0
)
)
private void positionRightArm_oldBowSwing(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) {
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking) {
boolean bl3 = livingEntity.getMainArm() == Arm.RIGHT;
if (livingEntity.isUsingItem()) {
boolean bl4 = livingEntity.getActiveHand() == Hand.MAIN_HAND;
if (bl4 == bl3) {
positionRightArm(livingEntity);
} else {
positionLeftArm(livingEntity);
}
} else {
boolean bl4 = bl3 ? leftArmPose.isTwoHanded() : rightArmPose.isTwoHanded();
if (bl3 != bl4) {
positionLeftArm(livingEntity);
positionRightArm(livingEntity);
} else {
positionRightArm(livingEntity);
positionLeftArm(livingEntity);
}
}
}
}

@ModifyConstant(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
constant = @Constant(
floatValue = 12.2F
)
)
private float oldSneakValue1(float constant) {
return LegacyAnimationsSettings.CONFIG.instance().oldSneaking ? 9.0F : constant;
}

@ModifyConstant(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
slice = @Slice(
from = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/model/ModelPart;pitch:F",
ordinal = 15
),
to = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/model/ModelPart;pivotY:F",
ordinal = 6
)
),
constant = @Constant(
floatValue = 0.0F
)
)
private float oldSneakValue2(float constant) {
return LegacyAnimationsSettings.CONFIG.instance().oldSneaking ? 0.1F : constant;
}

@ModifyConstant(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
constant = @Constant(
floatValue = 4.2F
)
)
private float oldSneakValue3(float constant) {
return LegacyAnimationsSettings.CONFIG.instance().oldSneaking ? 1.0F : constant;
}

@WrapWithCondition(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
slice = @Slice(
from = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/model/ModelPart;pivotY:F",
ordinal = 3
),
to = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/model/ModelPart;pitch:F",
ordinal = 15
)
),
at = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/model/ModelPart;pivotY:F"
)
)
public boolean removeFields1(ModelPart instance, float value) {
return !LegacyAnimationsSettings.CONFIG.instance().oldSneaking;
}

@WrapWithCondition(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
slice = @Slice(
from = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/model/ModelPart;pivotY:F",
ordinal = 9
),
to = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;rightArmPose:Lnet/minecraft/client/render/entity/model/BipedEntityModel$ArmPose;",
ordinal = 1
)
),
at = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/model/ModelPart;pivotY:F"
)
)
public boolean removeFields2(ModelPart instance, float value) {
return !LegacyAnimationsSettings.CONFIG.instance().oldSneaking;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mixces.legacyanimations.mixin;

import net.minecraft.client.render.item.BuiltinModelItemRenderer;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(BuiltinModelItemRenderer.class)
public class BuiltinModelItemRendererMixin {

// @Inject(method = "render", at = @At(value = "HEAD"), cancellable = true)
// private void render_disableShield(ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, CallbackInfo ci) {
// if (LegacyAnimationsSettings.CONFIG.instance().hideShields) {
// if (
// mode == ModelTransformationMode.FIRST_PERSON_LEFT_HAND ||
// mode == ModelTransformationMode.FIRST_PERSON_RIGHT_HAND ||
// mode == ModelTransformationMode.THIRD_PERSON_LEFT_HAND ||
// mode == ModelTransformationMode.THIRD_PERSON_RIGHT_HAND
// )
// {
// if (stack.isOf(Items.SHIELD)) {
// ci.cancel();
// }
// }
// }
// }

}
27 changes: 27 additions & 0 deletions src/main/java/com/mixces/legacyanimations/mixin/CameraMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.mixces.legacyanimations.mixin;

import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import net.minecraft.client.render.Camera;
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.callback.CallbackInfo;

@Mixin(Camera.class)
public abstract class CameraMixin {

@Shadow private float cameraY;
@Shadow private Entity focusedEntity;

@Inject(method = "updateEyeHeight", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/render/Camera;cameraY:F"), cancellable = true)
private void addOldSneakCalculation(CallbackInfo ci) {
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking && focusedEntity.getStandingEyeHeight() < cameraY) {
cameraY = focusedEntity.getStandingEyeHeight();
ci.cancel();
}
}

}
Loading

0 comments on commit bcb387e

Please sign in to comment.