From e6671513f29e540c8b3db880c3dd5ed0495dc9a8 Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 13 Apr 2016 16:54:18 +0100 Subject: [PATCH] Improve an issue to do with block breaking ghosting back, note this is not a fully fix, but improves the issue quite a bit. --- .../us/myles/ViaVersion/ViaVersionPlugin.java | 4 ++ .../ViaVersion/api/ViaVersionConfig.java | 7 +++ .../ViaVersion/api/minecraft/Position.java | 2 + .../packets/WorldPackets.java | 46 ++++++++++++++++++- .../storage/EntityTracker.java | 2 + src/main/resources/config.yml | 4 +- 6 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index 0437c13af..465b1ab5d 100644 --- a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -393,6 +393,10 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe return getConfig().getDouble("hologram-y", -1D); } + public boolean isBlockBreakPatch() { + return getConfig().getBoolean("block-break-patch", true); + } + public boolean isAutoTeam() { // Collision has to be enabled first return isPreventCollision() && getConfig().getBoolean("auto-team", true); diff --git a/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java b/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java index 378d1ceef..78c8e9cb1 100644 --- a/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -93,4 +93,11 @@ public interface ViaVersionConfig { * @return true if automatic teaming is enabled */ boolean isAutoTeam(); + + /** + * Get if our block break patch is enabled to prevent weird ghost glitches. + * + * @return true if it is enabled. + */ + boolean isBlockBreakPatch(); } diff --git a/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java b/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java index 33ec6d103..558b6f9bc 100644 --- a/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java +++ b/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java @@ -1,12 +1,14 @@ package us.myles.ViaVersion.api.minecraft; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @AllArgsConstructor @Getter @ToString +@EqualsAndHashCode public class Position { private Long x; private Long y; diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java index 58a679ce5..97ca0125c 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -6,7 +6,6 @@ import org.spacehq.opennbt.tag.builtin.StringTag; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.minecraft.Position; -import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketHandler; @@ -174,11 +173,34 @@ public class WorldPackets { }); } }); + + // Block Change Packet + protocol.registerOutgoing(State.PLAY, 0x23, 0x0B, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.POSITION); + map(Type.VAR_INT); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Position pos = wrapper.user().get(EntityTracker.class).getCurrentlyDigging(); + if (pos != null) { + if (wrapper.get(Type.POSITION, 0).equals(pos)) { + // cancel this one + if (wrapper.get(Type.VAR_INT, 0) != 0) { + wrapper.cancel(); + wrapper.user().get(EntityTracker.class).setCurrentlyDigging(null); + } + } + } + } + }); + } + }); /* Packets which do not have any field remapping or handlers */ protocol.registerOutgoing(State.PLAY, 0x25, 0x08); // Block Break Animation Packet protocol.registerOutgoing(State.PLAY, 0x24, 0x0A); // Block Action Packet - protocol.registerOutgoing(State.PLAY, 0x23, 0x0B); // Block Change Packet protocol.registerOutgoing(State.PLAY, 0x22, 0x10); // Multi Block Change Packet protocol.registerOutgoing(State.PLAY, 0x27, 0x1C); // Explosion Packet protocol.registerOutgoing(State.PLAY, 0x2A, 0x22); // Particle Packet @@ -228,6 +250,26 @@ public class WorldPackets { } } }); + // Digging patch (prevents it glitching) + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + if(!ViaVersion.getConfig().isBlockBreakPatch()) return; + + EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); + final Position block = wrapper.get(Type.POSITION, 0); + int status = wrapper.get(Type.UNSIGNED_BYTE, 0); + if (status == 0) { + entityTracker.setCurrentlyDigging(null); + } + if (status == 1) { + entityTracker.setCurrentlyDigging(null); + } + if (status == 2) { + entityTracker.setCurrentlyDigging(block); + } + } + }); } }); diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java index 5e881dccb..cc5217c46 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java @@ -44,6 +44,8 @@ public class EntityTracker extends StoredObject { private Long lastPlaceBlock = -1L; @Setter private int entityID; + @Setter + private Position currentlyDigging = null; private boolean teamExists = false; public EntityTracker(UserConnection user) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1a318b0c3..cf13d3e19 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -26,4 +26,6 @@ use-new-effect-indicator: true use-new-deathmessages: false # This will suppress the following error: 'Unable to get entity for ID: xxxx' # This error message means one of you plugins is sending bad packets! -suppress-entityid-errors: false \ No newline at end of file +suppress-entityid-errors: false +# Our patch for block breaking issue, if you have issues with block updates then disable this. +block-break-patch: true \ No newline at end of file