From 47b447f195f4cafa68c696eb35a71279d3af0f22 Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 9 Mar 2016 21:08:50 +0000 Subject: [PATCH] Add the option to use a hologram patch to fix invisible holograms being in wrong place, by default disabled. --- .../us/myles/ViaVersion/ViaVersionPlugin.java | 8 +++++ .../transformers/OutgoingTransformer.java | 32 ++++++++++++++++++- src/main/resources/config.yml | 7 +++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index d9acdea3d..12625e8b2 100644 --- a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -230,6 +230,14 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { return getConfig().getBoolean("shield-blocking", true); } + public boolean isHologramPatch() { + return getConfig().getBoolean("hologram-patch", false); + } + + public double getHologramYOffset() { + return getConfig().getDouble("hologram-y", -1D); + } + public boolean isAutoTeam() { // Collision has to be enabled first if (!isPreventCollision()) return false; diff --git a/src/main/java/us/myles/ViaVersion/transformers/OutgoingTransformer.java b/src/main/java/us/myles/ViaVersion/transformers/OutgoingTransformer.java index f1369429b..179d2b455 100644 --- a/src/main/java/us/myles/ViaVersion/transformers/OutgoingTransformer.java +++ b/src/main/java/us/myles/ViaVersion/transformers/OutgoingTransformer.java @@ -39,6 +39,7 @@ public class OutgoingTransformer { private final Map clientEntityTypes = new HashMap<>(); private final Map vehicleMap = new HashMap<>(); private final Set validBlocking = new HashSet<>(); + private final Set knownHolograms = new HashSet<>(); private boolean autoTeam = false; public OutgoingTransformer(ConnectionInfo info) { @@ -216,13 +217,15 @@ public class OutgoingTransformer { return; } if (packet == PacketType.PLAY_ENTITY_TELEPORT) { - // Port this so that it relative moves :P int id = PacketUtil.readVarInt(input); PacketUtil.writeVarInt(id, output); int x = input.readInt(); output.writeDouble(x / 32D); int y = input.readInt(); + if(plugin.isHologramPatch() & knownHolograms.contains(id)){ + y = (int) ((y) + (plugin.getHologramYOffset() * 32D)); + } output.writeDouble(y / 32D); int z = input.readInt(); output.writeDouble(z / 32D); @@ -243,6 +246,9 @@ public class OutgoingTransformer { int x = input.readByte(); output.writeShort(x * 128); int y = input.readByte(); + if(plugin.isHologramPatch() & knownHolograms.contains(id)){ + y = (int) ((y) + plugin.getHologramYOffset()); + } output.writeShort(y * 128); int z = input.readByte(); output.writeShort(z * 128); @@ -263,12 +269,16 @@ public class OutgoingTransformer { short x = (short) (input.readByte()); output.writeShort(x * 128); short y = (short) (input.readByte()); + if(plugin.isHologramPatch() & knownHolograms.contains(id)){ + y = (short) (y - 1); + } output.writeShort(y * 128); short z = (short) (input.readByte()); output.writeShort(z * 128); boolean onGround = input.readBoolean(); output.writeBoolean(onGround); + return; } @@ -372,6 +382,7 @@ public class OutgoingTransformer { int[] toDestroy = PacketUtil.readVarInts(count, input); for (int entityID : toDestroy) { clientEntityTypes.remove(entityID); + knownHolograms.remove(entityID); PacketUtil.writeVarInt(entityID, output); } return; @@ -845,6 +856,25 @@ public class OutgoingTransformer { } } } + if(type == EntityType.ARMOR_STAND && plugin.isHologramPatch()){ + if(entry.getOldID() == 0){ + byte data = (byte) entry.getValue(); + if((data & 0x20) == 0x20){ + if(!knownHolograms.contains(entityID)) { + knownHolograms.add(entityID); + // Send movement + ByteBuf buf = info.getChannel().alloc().buffer(); + PacketUtil.writeVarInt(PacketType.PLAY_ENTITY_RELATIVE_MOVE.getNewPacketID(), buf); + PacketUtil.writeVarInt(entityID, buf); + buf.writeShort(0); + buf.writeShort((short) (128D * (plugin.getHologramYOffset() * 32D))); + buf.writeShort(0); + buf.writeBoolean(true); + info.sendRawPacket(buf, false); + } + } + } + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c5cd024c6..0478e117a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -11,4 +11,9 @@ auto-team: true # When enabled if certain metadata can't be read we won't tell you about it suppress-metadata-errors: false # When enabled 1.9 will be able to block by using shields -shield-blocking: true \ No newline at end of file +shield-blocking: true +# Should we enable our hologram patch? +# If they're in the wrong place enable this +hologram-patch: false +# This is the offset, should work as default when enabled. +hologram-y: -1 \ No newline at end of file