Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Author

@lrockreal lrockreal Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly rearranged to avoid repeat computation while adding no-shield logic

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public static boolean canEntityBlock(ItemStack mainHandStack, ItemStack offHandS

// TODO/NOTE: I know this can be condensed more but i'm tired so will recheck later
public static boolean canShieldSwordBlock(ItemStack mainHandStack, ItemStack offHandStack) {
if (SwordBlockingConfig.enabled && (offHandStack.getItem() instanceof ShieldItem || mainHandStack.getItem() instanceof ShieldItem)) {
if (!SwordBlockingConfig.enabled) return false;
boolean hasShield = offHandStack.getItem() instanceof ShieldItem || mainHandStack.getItem() instanceof ShieldItem;
if (!SwordBlockingConfig.requireShield) {
return mainHandStack.getItem().components().has(DataComponents.DAMAGE) || offHandStack.getItem().components().has(DataComponents.DAMAGE);
} else if (hasShield) {
final Item weaponItem = offHandStack.getItem() instanceof ShieldItem ? mainHandStack.getItem() : offHandStack.getItem();
return weaponItem.components().has(DataComponents.DAMAGE);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ public class SwordBlockingConfig extends MidnightConfig {

@Entry
public static boolean blockHitAnimation = false;

@Entry
public static boolean requireShield = true;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With requireShield disabled, any hand with a sword plays the block animation. May want to turn into another config option.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import eu.midnightdust.swordblocking.ducks.ArmedItemStackData;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.renderer.entity.state.HumanoidRenderState;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShieldItem;
Expand All @@ -29,7 +30,14 @@ public abstract class MixinHumanoidModel {
final ItemStack offHandStack = armedItemStackData.swordblocking$getOffHandItem();
final ItemStack mainHandStack = armedItemStackData.swordblocking$getMainHandItem();
if (renderState.isUsingItem && SwordBlockingClient.canEntityBlock(mainHandStack, offHandStack)) {
if (offHandStack.getItem() instanceof ShieldItem) {
if (SwordBlockingConfig.requireShield) {
if (mainHandStack.getItem().components().has(DataComponents.DAMAGE)) {
this.poseRightArm(renderState, HumanoidModel.ArmPose.BLOCK);
}
if (offHandStack.getItem().components().has(DataComponents.DAMAGE)) {
this.poseRightArm(renderState, HumanoidModel.ArmPose.BLOCK);
}
} else if (offHandStack.getItem() instanceof ShieldItem) {
this.poseRightArm(renderState, HumanoidModel.ArmPose.BLOCK);
} else {
this.poseLeftArm(renderState, HumanoidModel.ArmPose.BLOCK);
Expand Down
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on MixinHumanoidModel.java

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import eu.midnightdust.swordblocking.SwordBlockingClient;
import eu.midnightdust.swordblocking.config.SwordBlockingConfig;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShieldItem;
Expand Down Expand Up @@ -60,7 +61,9 @@ public abstract class MixinPlayerRenderer {
return;
}

if (offStack.getItem() instanceof ShieldItem && SwordBlockingClient.canEntityBlock(player.getMainHandItem(), player.getOffhandItem())) {
if (!SwordBlockingConfig.requireShield && handStack.getItem().components().has(DataComponents.DAMAGE)) {
cir.setReturnValue(HumanoidModel.ArmPose.BLOCK);
} else if (offStack.getItem() instanceof ShieldItem && SwordBlockingClient.canEntityBlock(player.getMainHandItem(), player.getOffhandItem())) {
cir.setReturnValue(HumanoidModel.ArmPose.BLOCK);
} else if (handStack.getItem() instanceof ShieldItem && SwordBlockingConfig.hideShield && (cir.getReturnValue() == HumanoidModel.ArmPose.ITEM || cir.getReturnValue() == HumanoidModel.ArmPose.BLOCK)) {
cir.setReturnValue(HumanoidModel.ArmPose.EMPTY);
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/swordblocking/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"swordblocking.midnightconfig.hideOffhandSlot.tooltip": "Hides the offhand slot when a shield is in the offhand.",
"swordblocking.midnightconfig.disableUseEquipAnimation": "Remove the equip animation when blocking.",
"swordblocking.midnightconfig.lockBlockingArmPosition": "Disable arm moving when blocking.",
"swordblocking.midnightconfig.blockHitAnimation": "Enable block hitting animation."
"swordblocking.midnightconfig.blockHitAnimation": "Enable block hitting animation.",
"swordblocking.midnightconfig.requireShield": "Require Shield",
"swordblocking.midnightconfig.requireShield.tooltip": "Require a shield in the offhand or mainhand slot to block."
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/swordblocking/lang/ru_ru.json
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need russian translations for the config option and tooltip

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"swordblocking.midnightconfig.hideOffhandSlot.tooltip": "Скрывает слот второй руки, если в ней находится щит.",
"swordblocking.midnightconfig.disableUseEquipAnimation": "Удалять анимацию оснащения при блокировании.",
"swordblocking.midnightconfig.lockBlockingArmPosition": "Отключить движение руки при блокировании.",
"swordblocking.midnightconfig.blockHitAnimation": "Включить анимацию удара по блоку."
"swordblocking.midnightconfig.blockHitAnimation": "Включить анимацию удара по блоку.",
"swordblocking.midnightconfig.requireShield": "",
"swordblocking.midnightconfig.requireShield.tooltip": ""
}