From 8e20df57a9a803dfb9d1448994dfd73105f9e93c Mon Sep 17 00:00:00 2001 From: RaynLegends Date: Thu, 1 Jun 2017 18:23:16 +0200 Subject: [PATCH] Improved the shield handling (1.9->1.8) --- .../packets/WorldPackets.java | 22 ++++++++++--------- .../storage/EntityTracker.java | 2 ++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java index 5ab050a9e..826eee605 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -306,18 +306,20 @@ public class WorldPackets { Item item = Protocol1_9TO1_8.getHandItem(wrapper.user()); // Blocking patch if (Via.getConfig().isShieldBlocking()) { - if (item != null) { - if (Protocol1_9TO1_8.isSword(item.getId())) { - if (hand == 0) { - EntityTracker tracker = wrapper.user().get(EntityTracker.class); - if (!tracker.isBlocking()) { - tracker.setBlocking(true); - Item shield = new Item((short) 442, (byte) 1, (short) 0, null); - tracker.setSecondHand(shield); - } - wrapper.cancel(); + EntityTracker tracker = wrapper.user().get(EntityTracker.class); + + if (item != null && Protocol1_9TO1_8.isSword(item.getId())) { + if (hand == 0) { + if (!tracker.isBlocking()) { + tracker.setBlocking(true); + Item shield = new Item((short) 442, (byte) 1, (short) 0, null); + tracker.setSecondHand(shield); } + wrapper.cancel(); } + } else { + tracker.setSecondHand(null); + tracker.setBlocking(false); } } wrapper.write(Type.ITEM, item); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java index 052f0d70f..53489b689 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java @@ -162,6 +162,8 @@ public class EntityTracker extends StoredObject { if (validBlocking.contains(entityID)) { Item shield = new Item((short) 442, (byte) 1, (short) 0, null); setSecondHand(entityID, shield); + } else { + setSecondHand(entityID, null); } } else { setSecondHand(entityID, null);