From 4b911b09b7bc9dab8ea087225bd4095227acdc6f Mon Sep 17 00:00:00 2001 From: Chase Cooper Date: Sun, 19 Apr 2026 22:56:54 -0400 Subject: [PATCH] Sword blocking mechanics and interactoin locks (#1532) - Fixed #1532 by makingthe blocking correctly reduces damage; per Java 1.8 mechs. - Fixed an attack going through while blocking. - Fixed a bug where you could mine while blocking. - Swing animation while blocking was overrided; per Java 1.8 mechs. --- Minecraft.Client/LocalPlayer.cpp | 10 ++++++++-- Minecraft.Client/MultiPlayerGameMode.cpp | 9 +++++++++ Minecraft.World/Player.cpp | 17 ++++++++++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Minecraft.Client/LocalPlayer.cpp b/Minecraft.Client/LocalPlayer.cpp index 852b83081..f40a5867f 100644 --- a/Minecraft.Client/LocalPlayer.cpp +++ b/Minecraft.Client/LocalPlayer.cpp @@ -1279,6 +1279,12 @@ void LocalPlayer::handleMouseDown(int button, bool down) if (!down) missTime = 0; if (button == 0 && missTime > 0) return; + if (isBlocking()) + { + minecraft->gameMode->stopDestroyBlock(); + return; + } + if (down && minecraft->hitResult != nullptr && minecraft->hitResult->type == HitResult::TILE && button == 0) { int x = minecraft->hitResult->x; @@ -1476,7 +1482,7 @@ bool LocalPlayer::handleMouseClick(int button) bool returnItemPlaced = false; if (button == 0 && missTime > 0) return false; - if (button == 0) + if (button == 0 && !isBlocking()) { //app.DebugPrintf("handleMouseClick - Player %d is swinging\n",GetXboxPad()); swing(); @@ -1510,7 +1516,7 @@ bool LocalPlayer::handleMouseClick(int button) } else if (minecraft->hitResult->type == HitResult::ENTITY) { - if (button == 0) + if (button == 0 && !isBlocking()) { minecraft->gameMode->attack(minecraft->localplayers[GetXboxPad()], minecraft->hitResult->entity); } diff --git a/Minecraft.Client/MultiPlayerGameMode.cpp b/Minecraft.Client/MultiPlayerGameMode.cpp index 96071d283..130879a8c 100644 --- a/Minecraft.Client/MultiPlayerGameMode.cpp +++ b/Minecraft.Client/MultiPlayerGameMode.cpp @@ -116,6 +116,8 @@ void MultiPlayerGameMode::startDestroyBlock(int x, int y, int z, int face) { if(!minecraft->player->isAllowedToMine()) return; + if(minecraft->player->isBlocking()) return; + if (localPlayerMode->isAdventureRestricted()) { if (!minecraft->player->mayDestroyBlockAt(x, y, z)) @@ -181,6 +183,13 @@ void MultiPlayerGameMode::stopDestroyBlock() void MultiPlayerGameMode::continueDestroyBlock(int x, int y, int z, int face) { if(!minecraft->player->isAllowedToMine()) return; + if(minecraft->player->isBlocking()) + { + isDestroying = false; + destroyProgress = 0; + minecraft->level->destroyTileProgress(minecraft->player->entityId, xDestroyBlock, yDestroyBlock, zDestroyBlock, -1); + return; + } ensureHasSentCarriedItem(); // connection.send(new PlayerActionPacket(PlayerActionPacket.CONTINUE_DESTROY_BLOCK, x, y, z, face)); diff --git a/Minecraft.World/Player.cpp b/Minecraft.World/Player.cpp index db6ee06e1..ee327b1d8 100644 --- a/Minecraft.World/Player.cpp +++ b/Minecraft.World/Player.cpp @@ -243,9 +243,13 @@ void Player::updateFrameTick() // 4J Stu - Fix for #45508 - TU5: Gameplay: Eating one piece of food will result in a second piece being eaten as well // Original code was item != useItem. Changed this now to use the equals function, and add the nullptr check as well for the other possible not equals (useItem is not nullptr if we are here) // This is because the useItem and item could be different objects due to an inventory update from the server, but still be the same item (with the same id,count and auxvalue) - if (item == nullptr || !item->equals(useItem) ) + if (item == nullptr || !item->equals(useItem)) { - stopUsingItem(); + const UseAnim anim = useItem->getUseAnimation(); + if (anim != UseAnim_block) + { + stopUsingItem(); + } } else { @@ -1467,7 +1471,7 @@ void Player::actuallyHurt(DamageSource *source, float dmg) if (isInvulnerable()) return; if (!source->isBypassArmor() && isBlocking() && dmg > 0) { - dmg = (1 + dmg) * .5f; + dmg = dmg * 0.5f; } dmg = getDamageAfterArmorAbsorb(source, dmg); dmg = getDamageAfterMagicAbsorb(source, dmg); @@ -2482,6 +2486,13 @@ void Player::startUsingItem(shared_ptr instance, int duration) setUsingItemFlag(true); } + if (instance->getUseAnimation() == UseAnim_block) + { + swinging = false; + swingTime = 0; + attackAnim = 0.0f; + } + // 4J-JEV, hook for ItemUsed event, and ironbelly achievement. awardStat(GenericStats::itemsUsed(instance->getItem()->id), GenericStats::param_itemsUsed(dynamic_pointer_cast(shared_from_this()),instance));