3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

fix ghost shield issue and delayed interaction when switching to another item (#2432)

Dieser Commit ist enthalten in:
LabyStudio 2021-04-12 16:56:53 +02:00 committet von GitHub
Ursprung 0ee80dc41f
Commit 76e739e4f0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 22 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -301,13 +301,17 @@ public class WorldPackets {
// Check if the shield is already there or if we have to give it here
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 (!tracker.isBlocking()) {
tracker.setBlocking(true);
// 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
Item shield = new Item(442, (byte) 1, (short) 0, null);

Datei anzeigen

@ -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.
*/
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);
// Get item in new selected slot
int inventorySlot = this.heldItemSlot + 36; // Hotbar slot index to inventory slot
int itemIdentifier = inventoryTracker.getItemId((short) 0, (short) inventorySlot);
boolean isSword = 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);
}
return Protocol1_9To1_8.isSword(itemIdentifier);
}
@Override