Skip to content

Commit

Permalink
Add client side configuration to hide inactive hand while attacking i…
Browse files Browse the repository at this point in the history
…n first person #70
  • Loading branch information
ZsoltMolnarrr committed Aug 29, 2022
1 parent 8d7b1c4 commit f0699b4
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public class FirstPersonRenderHelper {
public static boolean isRenderingFirstPersonPlayerModel = false;
public static boolean isAttackingWithOffHand = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public class ClientConfig implements ConfigData {
@ConfigEntry.Gui.Tooltip
public boolean isShowingArmsInFirstPerson = false;
@ConfigEntry.Gui.Tooltip
public boolean isShowingOtherHandFirstPerson = true;
@ConfigEntry.Gui.Tooltip
public boolean isSweepingParticleEnabled = true;
@ConfigEntry.Gui.Tooltip
public boolean isSmoothAnimationTransitionEnabled = true;
@ConfigEntry.Gui.Tooltip
public boolean isTooltipAttackRangeEnabled = true;
@ConfigEntry.Gui.Tooltip
public boolean isSweepingParticleEnabled = true;
@ConfigEntry.Gui.Tooltip
@ConfigEntry.BoundedDiscrete(min = 0, max = 100)
public int weaponSwingSoundVolume = 100;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.bettercombat.client.BetterCombatKeybindings;
import net.bettercombat.client.MinecraftClientExtension;
import net.bettercombat.client.PlayerAttackAnimatable;
import net.bettercombat.client.animation.FirstPersonRenderHelper;
import net.bettercombat.client.collision.TargetFinder;
import net.bettercombat.config.ClientConfigWrapper;
import net.bettercombat.logic.AttackHand;
Expand Down Expand Up @@ -203,6 +204,7 @@ private void startUpswing(WeaponAttributes attributes) {
// System.out.println("Starting upswingTicks: " + upswingTicks);
String animationName = hand.attack().animation();
boolean isOffHand = hand.isOffHand();
FirstPersonRenderHelper.isAttackingWithOffHand = isOffHand;
((PlayerAttackAnimatable) player).playAttackAnimation(animationName, isOffHand, attackCooldownTicks);
ClientPlayNetworking.send(
Packets.AttackAnimation.ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package net.bettercombat.mixin.client.firstpersonrender;

import dev.kosmx.playerAnim.api.layered.IAnimation;
import net.bettercombat.client.BetterCombatClient;
import net.bettercombat.client.PlayerAttackAnimatable;
import net.bettercombat.client.animation.FirstPersonRenderHelper;
import net.bettercombat.client.animation.IExtendedAnimation;
import net.bettercombat.compatibility.CompatibilityFlags;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.HeldItemRenderer;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand Down Expand Up @@ -36,4 +42,27 @@ private void dontRenderItem(float tickDelta, MatrixStack matrices, VertexConsume
}
}
}

@Inject(method = "renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V",
at = @At("HEAD"), cancellable = true)
private void renderItem_HEAD(LivingEntity entity, ItemStack stack, ModelTransformation.Mode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
var player = MinecraftClient.getInstance().player;
if (entity != player) {
return;
}
if (FirstPersonRenderHelper.isRenderingFirstPersonPlayerModel) {
if (!BetterCombatClient.config.isShowingOtherHandFirstPerson) {
var isMainHandStack = player.getMainHandStack() == stack;
if (FirstPersonRenderHelper.isAttackingWithOffHand) {
if (isMainHandStack) {
ci.cancel();
}
} else {
if (!isMainHandStack) {
ci.cancel();
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ private void hideBonesInFirstPerson(AbstractClientPlayerEntity entity,
if (entity == MinecraftClient.getInstance().player) {
var player = MinecraftClient.getInstance().player;
setPartsVisible(false);
this.model.rightArm.visible = showArms;
this.model.rightSleeve.visible = showArms && player.isPartVisible(PlayerModelPart.RIGHT_SLEEVE);
this.model.leftArm.visible = showArms;
this.model.leftSleeve.visible = showArms && player.isPartVisible(PlayerModelPart.LEFT_SLEEVE);
var showRightArm = showArms;
var showLeftArm = showArms;
if (!BetterCombatClient.config.isShowingOtherHandFirstPerson) {
showRightArm = showRightArm && !FirstPersonRenderHelper.isAttackingWithOffHand;
showLeftArm = showLeftArm && FirstPersonRenderHelper.isAttackingWithOffHand;
}
this.model.rightArm.visible = showRightArm;
this.model.rightSleeve.visible = showRightArm && player.isPartVisible(PlayerModelPart.RIGHT_SLEEVE);
this.model.leftArm.visible = showLeftArm;
this.model.leftSleeve.visible = showLeftArm && player.isPartVisible(PlayerModelPart.LEFT_SLEEVE);
}
// No `else` case needed to show parts, since the default state should be correct already
}
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/bettercombat/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"text.autoconfig.bettercombat.option.client.hudHighlightColor.@Tooltip" : "Color applied to HUD elements if needed.",
"text.autoconfig.bettercombat.option.client.isShowingArmsInFirstPerson": "Show arms in first person",
"text.autoconfig.bettercombat.option.client.isShowingArmsInFirstPerson.@Tooltip": "Render arms for attack animations played in first person view",
"text.autoconfig.bettercombat.option.client.isShowingOtherHandFirstPerson": "Show inactive hand in first person",
"text.autoconfig.bettercombat.option.client.isShowingOtherHandFirstPerson.@Tooltip": "Render hand you are not attacking with in first person view",
"text.autoconfig.bettercombat.option.client.isSmoothAnimationTransitionEnabled": "Smooth animation transitions",
"text.autoconfig.bettercombat.option.client.isSmoothAnimationTransitionEnabled.@Tooltip": "Attack animations smoothly transition at the cost of accuracy",
"text.autoconfig.bettercombat.option.client.isTooltipAttackRangeEnabled": "Item tooltip: attack range",
Expand Down

0 comments on commit f0699b4

Please sign in to comment.