diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java index c55a407ee..ebc3f132f 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java @@ -185,6 +185,11 @@ public class BukkitConfigAPI extends Config implements ViaVersionConfig { return getString("reload-disconnect-msg", "Server reload, please rejoin!"); } + @Override + public boolean isMinimizeCooldown() { + return getBoolean("minimize-cooldown", true); + } + @Override public URL getDefaultConfigURL() { return BukkitConfigAPI.class.getClassLoader().getResource("assets/viaversion/config.yml"); diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java index 79ae44916..fd90e037f 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java @@ -224,6 +224,11 @@ public class BungeeConfigAPI extends Config implements ViaVersionConfig { return getString("reload-disconnect-msg", "Server reload, please rejoin!"); } + @Override + public boolean isMinimizeCooldown() { + return getBoolean("minimize-cooldown", true); + } + /** * What is the interval for checking servers via ping * -1 for disabled diff --git a/common/src/main/java/us/myles/ViaVersion/api/Triple.java b/common/src/main/java/us/myles/ViaVersion/api/Triple.java new file mode 100644 index 000000000..57e1ca21a --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/api/Triple.java @@ -0,0 +1,17 @@ +package us.myles.ViaVersion.api; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class Triple { + private A first; + private B second; + private C third; + + @Override + public String toString() { + return "Triple{" + first + ", " + second + ", " + third + '}'; + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java index 106ad9d40..e3a6f48b8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -245,4 +245,10 @@ public interface ViaVersionConfig { * @return Disconnect message */ String getReloadDisconnectMsg(); + + /** + * Tries to minimize cooldown animation + * @return True if enabled + */ + boolean isMinimizeCooldown(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java index e36317a60..bc4987780 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java @@ -1,6 +1,9 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; +import com.google.common.collect.ImmutableList; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.Pair; +import us.myles.ViaVersion.api.Triple; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; @@ -17,7 +20,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker; -import java.util.List; +import java.util.*; public class EntityPackets { public static final ValueTransformer toNewShort = new ValueTransformer(Type.SHORT) { @@ -269,9 +272,64 @@ public class EntityPackets { } }); - /* Packets which do not have any field remapping or handlers */ + // Entity Properties Packet + protocol.registerOutgoing(State.PLAY, 0x20, 0x4B, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + if (!Via.getConfig().isMinimizeCooldown()) return; + if (wrapper.get(Type.VAR_INT, 0) != wrapper.user().get(EntityTracker.class).getEntityID()) { + return; + } + int propertiesToRead = wrapper.read(Type.INT); + Map>>> properties = new HashMap<>(propertiesToRead); + for (int i = 0; i < propertiesToRead; i++) { + String key = wrapper.read(Type.STRING); + Double value = wrapper.read(Type.DOUBLE); + int modifiersToRead = wrapper.read(Type.VAR_INT); + List> modifiers = new ArrayList<>(modifiersToRead); + for (int j = 0; j < modifiersToRead; j++) { + modifiers.add( + new Triple<>( + wrapper.read(Type.UUID), + wrapper.read(Type.DOUBLE), // Amount + wrapper.read(Type.BYTE) // Operation + ) + ); + } + properties.put(key, new Pair<>(value, modifiers)); + } - protocol.registerOutgoing(State.PLAY, 0x20, 0x4B); // Entity Properties Packet + // == Why 15.9? == + // Higher values hides the cooldown but it bugs visual animation on hand + // when removing item from hand with inventory gui + properties.put("generic.attackSpeed", new Pair>>(15.9, ImmutableList.of( // Neutralize modifiers + new Triple<>(UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3"), 0.0, (byte) 0), // Tool and weapon modifier + new Triple<>(UUID.fromString("AF8B6E3F-3328-4C0A-AA36-5BA2BB9DBEF3"), 0.0, (byte) 2), // Dig speed + new Triple<>(UUID.fromString("55FCED67-E92A-486E-9800-B47F202C4386"), 0.0, (byte) 2) // Dig slow down + ))); + + wrapper.write(Type.INT, properties.size()); + for (Map.Entry>>> entry : properties.entrySet()) { + wrapper.write(Type.STRING, entry.getKey()); // Key + wrapper.write(Type.DOUBLE, entry.getValue().getKey()); // Value + wrapper.write(Type.VAR_INT, entry.getValue().getValue().size()); + for (Triple modifier : entry.getValue().getValue()) { + wrapper.write(Type.UUID, modifier.getFirst()); + wrapper.write(Type.DOUBLE, modifier.getSecond()); // Amount + wrapper.write(Type.BYTE, modifier.getThird()); // Operation + } + } + } + }); + } + }); + + + /* Packets which do not have any field remapping or handlers */ protocol.registerOutgoing(State.PLAY, 0x1A, 0x1B); // Entity Status Packet protocol.registerOutgoing(State.PLAY, 0x16, 0x27); // Entity Look Packet diff --git a/common/src/main/resources/assets/viaversion/config.yml b/common/src/main/resources/assets/viaversion/config.yml index c72913019..863c66a33 100644 --- a/common/src/main/resources/assets/viaversion/config.yml +++ b/common/src/main/resources/assets/viaversion/config.yml @@ -123,4 +123,6 @@ replace-pistons: false # What id should we replace with, default is air. (careful of players getting stuck standing on them) replacement-piston-id: 0 # Force the string -> json transform -force-json-transform: false \ No newline at end of file +force-json-transform: false +# Minimize the cooldown animation in 1.8 servers +minimize-cooldown: true \ No newline at end of file diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java index a6088b53f..3144149fa 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java @@ -206,6 +206,11 @@ public class SpongeConfigAPI extends Config implements ViaVersionConfig { return getString("reload-disconnect-msg", "Server reload, please rejoin!"); } + @Override + public boolean isMinimizeCooldown() { + return getBoolean("minimize-cooldown", true); + } + @Override public boolean is1_13TeamColourFix() { return getBoolean("team-colour-fix", true);