Skip to content

Commit

Permalink
Add more hold up features. Fix #213
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Dec 24, 2024
1 parent 19dd2c3 commit c7f2c58
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.tr7zw.notenoughanimations.versionless.animations;

public enum HoldUpTarget {
NONE, CAMERA
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/assets/notenoughanimations/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 2 additions & 2 deletions src/main/resources/assets/notenoughanimations/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Тип блокировки вращения тела игрока относительно головы",
Expand Down Expand Up @@ -70,4 +70,4 @@
"text.nea.enable.bowAnimation.CUSTOM_V1": "Настройка 1",
"text.nea.enable.burningAnimation": "Анимация горения",
"text.nea.enable.burningAnimation.tooltip": "Добавляет анимацию когда игрок находится в огне"
}
}

0 comments on commit c7f2c58

Please sign in to comment.