From c7f2c588a4ed0fe4e13ae3076791fa46c3ee87e7 Mon Sep 17 00:00:00 2001 From: tr7zw Date: Tue, 24 Dec 2024 15:47:44 +0100 Subject: [PATCH] Add more hold up features. Fix #213 --- .../versionless/animations/HoldUpTarget.java | 5 +++++ .../versionless/config/Config.java | 4 ++++ .../animations/hands/LookAtItemAnimation.java | 21 +++++++++++++++++-- .../config/ConfigScreenProvider.java | 9 ++++++++ .../notenoughanimations/lang/en_us.json | 10 ++++++++- .../notenoughanimations/lang/ru_ru.json | 4 ++-- 6 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 NEAVersionless/src/main/java/dev/tr7zw/notenoughanimations/versionless/animations/HoldUpTarget.java diff --git a/NEAVersionless/src/main/java/dev/tr7zw/notenoughanimations/versionless/animations/HoldUpTarget.java b/NEAVersionless/src/main/java/dev/tr7zw/notenoughanimations/versionless/animations/HoldUpTarget.java new file mode 100644 index 0000000..826e6b1 --- /dev/null +++ b/NEAVersionless/src/main/java/dev/tr7zw/notenoughanimations/versionless/animations/HoldUpTarget.java @@ -0,0 +1,5 @@ +package dev.tr7zw.notenoughanimations.versionless.animations; + +public enum HoldUpTarget { + NONE, CAMERA +} diff --git a/NEAVersionless/src/main/java/dev/tr7zw/notenoughanimations/versionless/config/Config.java b/NEAVersionless/src/main/java/dev/tr7zw/notenoughanimations/versionless/config/Config.java index 43499a9..a8668aa 100644 --- a/NEAVersionless/src/main/java/dev/tr7zw/notenoughanimations/versionless/config/Config.java +++ b/NEAVersionless/src/main/java/dev/tr7zw/notenoughanimations/versionless/config/Config.java @@ -7,6 +7,7 @@ import dev.tr7zw.notenoughanimations.versionless.RotationLock; import dev.tr7zw.notenoughanimations.versionless.animations.BowAnimation; import dev.tr7zw.notenoughanimations.versionless.animations.HoldUpModes; +import dev.tr7zw.notenoughanimations.versionless.animations.HoldUpTarget; public class Config { @@ -35,6 +36,9 @@ public class Config { "minecraft:golden_sword", "minecraft:iron_sword", "minecraft:diamond_sword", "minecraft:netherite_sword")); public boolean enableCrawlingAnimation = true; public HoldUpModes holdUpItemsMode = HoldUpModes.CONFIG; + public HoldUpTarget holdUpTarget = HoldUpTarget.CAMERA; + public float holdUpCameraOffset = 0.1f; + public boolean holdUpOnlySelf = false; public float holdUpItemOffset = 0; public boolean itemSwapAnimation = true; public boolean tweakElytraAnimation = true; diff --git a/src/main/java/dev/tr7zw/notenoughanimations/animations/hands/LookAtItemAnimation.java b/src/main/java/dev/tr7zw/notenoughanimations/animations/hands/LookAtItemAnimation.java index 4ed7bbf..ed10a7b 100644 --- a/src/main/java/dev/tr7zw/notenoughanimations/animations/hands/LookAtItemAnimation.java +++ b/src/main/java/dev/tr7zw/notenoughanimations/animations/hands/LookAtItemAnimation.java @@ -9,7 +9,9 @@ import dev.tr7zw.notenoughanimations.versionless.NEABaseMod; import dev.tr7zw.notenoughanimations.versionless.animations.BodyPart; import dev.tr7zw.notenoughanimations.versionless.animations.HoldUpModes; +import dev.tr7zw.notenoughanimations.versionless.animations.HoldUpTarget; import dev.tr7zw.util.NMSHelper; +import net.minecraft.client.Minecraft; import net.minecraft.client.model.PlayerModel; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.util.Mth; @@ -45,6 +47,9 @@ private void bind() { @Override public boolean isValid(AbstractClientPlayer entity, PlayerData data) { + if (NEABaseMod.config.holdUpOnlySelf && entity != Minecraft.getInstance().player) { + return false; + } boolean allItems = NEABaseMod.config.holdUpItemsMode == HoldUpModes.ALL; ItemStack itemInRightHand = entity.getItemInHand( entity.getMainArm() == HumanoidArm.LEFT ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND); @@ -92,8 +97,20 @@ public int getPriority(AbstractClientPlayer entity, PlayerData data) { public void apply(AbstractClientPlayer entity, PlayerData data, PlayerModel model, BodyPart part, float delta, float tickCounter) { HumanoidArm arm = part == BodyPart.LEFT_ARM ? HumanoidArm.LEFT : HumanoidArm.RIGHT; - AnimationUtil.applyArmTransforms(model, arm, -NEABaseMod.config.holdUpItemOffset - - (Mth.lerp(-1f * (NMSHelper.getXRot(entity) - 90f) / 180f, 1f, 1.5f)), -0.2f, 0.3f); + switch (NEABaseMod.config.holdUpTarget) { + case NONE: + AnimationUtil.applyArmTransforms(model, arm, -NEABaseMod.config.holdUpItemOffset + - (Mth.lerp(-1f * (NMSHelper.getXRot(entity) - 90f) / 180f, 1f, 1.5f)), -0.2f, 0.3f); + break; + case CAMERA: + float invert = part == BodyPart.LEFT_ARM ? -1 : 1; + AnimationUtil.applyArmTransforms(model, arm, Mth.clamp(-1.5707964F + model.head.xRot, -2.5f, 0), + Mth.clamp(NEABaseMod.config.holdUpCameraOffset + (model.head.yRot) * invert, -0.2f, + Math.max(0.2f, NEABaseMod.config.holdUpCameraOffset)), + 0.1f); + //System.out.println(Mth.clamp((NEABaseMod.config.holdUpCameraOffset + model.head.yRot) * invert, -0.2f, 0.2f)); + break; + } } } diff --git a/src/main/java/dev/tr7zw/notenoughanimations/config/ConfigScreenProvider.java b/src/main/java/dev/tr7zw/notenoughanimations/config/ConfigScreenProvider.java index c3f7612..98281e0 100644 --- a/src/main/java/dev/tr7zw/notenoughanimations/config/ConfigScreenProvider.java +++ b/src/main/java/dev/tr7zw/notenoughanimations/config/ConfigScreenProvider.java @@ -9,6 +9,7 @@ import dev.tr7zw.notenoughanimations.versionless.RotationLock; import dev.tr7zw.notenoughanimations.versionless.animations.BowAnimation; import dev.tr7zw.notenoughanimations.versionless.animations.HoldUpModes; +import dev.tr7zw.notenoughanimations.versionless.animations.HoldUpTarget; import dev.tr7zw.notenoughanimations.versionless.config.Config; import net.minecraft.client.gui.screens.Screen; //spotless:off @@ -80,6 +81,14 @@ public void initialize() { () -> (double) config.holdUpItemOffset, (i) -> { config.holdUpItemOffset = i.floatValue(); })); + options.add(getEnumOption("text.nea.holdUpTarget", HoldUpTarget.class, () -> config.holdUpTarget, + b -> config.holdUpTarget = b)); + options.add(getDoubleOption("text.nea.holdUpCameraOffset", -0.3f, 0.6f, 0.1f, + () -> (double) config.holdUpCameraOffset, (i) -> { + config.holdUpCameraOffset = i.floatValue(); + })); + options.add(getOnOffOption("text.nea.enable.holdUpOnlySelf", () -> config.holdUpOnlySelf, + b -> config.holdUpOnlySelf = b)); options.add(getOnOffOption("text.nea.enable.itemSwapAnimation", () -> config.itemSwapAnimation, b -> config.itemSwapAnimation = b)); options.add(getOnOffOption("text.nea.enable.tweakElytraAnimation", () -> config.tweakElytraAnimation, diff --git a/src/main/resources/assets/notenoughanimations/lang/en_us.json b/src/main/resources/assets/notenoughanimations/lang/en_us.json index 1252060..14758b4 100644 --- a/src/main/resources/assets/notenoughanimations/lang/en_us.json +++ b/src/main/resources/assets/notenoughanimations/lang/en_us.json @@ -69,5 +69,13 @@ "text.nea.enable.bowAnimation.VANILLA": "Vanilla", "text.nea.enable.bowAnimation.CUSTOM_V1": "Custom V1", "text.nea.enable.burningAnimation": "Burning Animation", - "text.nea.enable.burningAnimation.tooltip": "Adds an animation for when the player is on fire." + "text.nea.enable.burningAnimation.tooltip": "Adds an animation for when the player is on fire.", + "text.nea.holdUpTarget": "Hold Up Target", + "text.nea.holdUpTarget.tooltip": "Changes where the item points at when held up", + "text.nea.holdUpTarget.NONE": "None", + "text.nea.holdUpTarget.CAMERA": "Camera", + "text.nea.holdUpCameraOffset": "Hold Up Camera Offset", + "text.nea.holdUpCameraOffset.tooltip": "Modify how much the arm is offset to the sides when holding up items in Camera mode", + "text.nea.enable.holdUpOnlySelf": "Hold Up Only Self", + "text.nea.enable.holdUpOnlySelf.tooltip": "Only apply the hold up effect to the own player, not other players" } diff --git a/src/main/resources/assets/notenoughanimations/lang/ru_ru.json b/src/main/resources/assets/notenoughanimations/lang/ru_ru.json index 8c2d146..b69b52d 100644 --- a/src/main/resources/assets/notenoughanimations/lang/ru_ru.json +++ b/src/main/resources/assets/notenoughanimations/lang/ru_ru.json @@ -20,7 +20,7 @@ "text.nea.enable.horseanimation.tooltip": "Добавляет анимацию при езде на лошади", "text.nea.enable.dontholditemsinbed": "Прятать предметы при сне", "text.nea.enable.dontholditemsinbed.tooltip": "Не даёт игроку держать предметы, находясь в постели", - "text.nea.enable.freezearmsinbed": "Остановить движение во сне", + "text.nea.enable.freezearmsinbed": "Остановить движение во сне", "text.nea.enable.freezearmsinbed.tooltip": "Не позволяет игроку двигать руками в кровате", "text.nea.rotationlock": "Блокировка вращения", "text.nea.rotationlock.tooltip": "Тип блокировки вращения тела игрока относительно головы", @@ -70,4 +70,4 @@ "text.nea.enable.bowAnimation.CUSTOM_V1": "Настройка 1", "text.nea.enable.burningAnimation": "Анимация горения", "text.nea.enable.burningAnimation.tooltip": "Добавляет анимацию когда игрок находится в огне" - } \ No newline at end of file +}