Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 17:10:13 +01:00
fix ghost shield issue and delayed interaction when switching to another item (#2432)
Dieser Commit ist enthalten in:
Ursprung
0ee80dc41f
Commit
76e739e4f0
@ -301,13 +301,17 @@ public class WorldPackets {
|
|||||||
// Check if the shield is already there or if we have to give it here
|
// Check if the shield is already there or if we have to give it here
|
||||||
boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand();
|
boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand();
|
||||||
|
|
||||||
if (item != null && Protocol1_9To1_8.isSword(item.getIdentifier())) {
|
// Method to identify the sword in hand
|
||||||
|
boolean isSword = showShieldWhenSwordInHand ? tracker.hasSwordInHand()
|
||||||
|
: item != null && Protocol1_9To1_8.isSword(item.getIdentifier());
|
||||||
|
|
||||||
|
if (isSword) {
|
||||||
if (hand == 0) {
|
if (hand == 0) {
|
||||||
if (!tracker.isBlocking()) {
|
if (!tracker.isBlocking()) {
|
||||||
tracker.setBlocking(true);
|
tracker.setBlocking(true);
|
||||||
|
|
||||||
// Check if the shield is already in the offhand
|
// Check if the shield is already in the offhand
|
||||||
if (!showShieldWhenSwordInHand || tracker.getItemInSecondHand() == null) {
|
if (!showShieldWhenSwordInHand && tracker.getItemInSecondHand() == null) {
|
||||||
|
|
||||||
// Set shield in offhand when interacting with main hand
|
// Set shield in offhand when interacting with main hand
|
||||||
Item shield = new Item(442, (byte) 1, (short) 0, null);
|
Item shield = new Item(442, (byte) 1, (short) 0, null);
|
||||||
|
@ -108,20 +108,28 @@ public class EntityTracker1_9 extends EntityTracker {
|
|||||||
* The item in the offhand will be cleared if there is no sword in the main hand.
|
* The item in the offhand will be cleared if there is no sword in the main hand.
|
||||||
*/
|
*/
|
||||||
public void syncShieldWithSword() {
|
public void syncShieldWithSword() {
|
||||||
|
boolean swordInHand = hasSwordInHand();
|
||||||
|
|
||||||
|
// Update if there is no sword in the main hand or if the player has no shield in the second hand but a sword in the main hand
|
||||||
|
if (!swordInHand || this.itemInSecondHand == null) {
|
||||||
|
|
||||||
|
// Update shield in off hand depending if a sword is in the main hand
|
||||||
|
setSecondHand(swordInHand ? new Item(442, (byte) 1, (short) 0, null) : null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the item in the held inventory slot is a sword.
|
||||||
|
* @return player has a sword in the main hand
|
||||||
|
*/
|
||||||
|
public boolean hasSwordInHand() {
|
||||||
InventoryTracker inventoryTracker = getUser().get(InventoryTracker.class);
|
InventoryTracker inventoryTracker = getUser().get(InventoryTracker.class);
|
||||||
|
|
||||||
// Get item in new selected slot
|
// Get item in new selected slot
|
||||||
int inventorySlot = this.heldItemSlot + 36; // Hotbar slot index to inventory slot
|
int inventorySlot = this.heldItemSlot + 36; // Hotbar slot index to inventory slot
|
||||||
int itemIdentifier = inventoryTracker.getItemId((short) 0, (short) inventorySlot);
|
int itemIdentifier = inventoryTracker.getItemId((short) 0, (short) inventorySlot);
|
||||||
|
|
||||||
boolean isSword = Protocol1_9To1_8.isSword(itemIdentifier);
|
return Protocol1_9To1_8.isSword(itemIdentifier);
|
||||||
|
|
||||||
// Update if the state changed
|
|
||||||
if (isSword == (this.itemInSecondHand == null)) {
|
|
||||||
|
|
||||||
// Update shield in off hand depending if a sword is in the main hand
|
|
||||||
setSecondHand(isSword ? new Item(442, (byte) 1, (short) 0, null) : null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren