From 116706c09fce3905ab21330c64bcfa91fff44ce0 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Tue, 28 Jan 2020 12:36:27 +0100 Subject: [PATCH 1/2] Option to (not) remap infested blocks to their normal variants Fixes #1642 --- .../bukkit/platform/BukkitViaConfig.java | 5 +++++ .../bungee/platform/BungeeViaConfig.java | 5 +++++ .../us/myles/ViaVersion/api/ViaVersionConfig.java | 7 +++++++ .../protocol1_13to1_12_2/data/MappingData.java | 14 ++++++++------ .../main/resources/assets/viaversion/config.yml | 2 ++ .../sponge/platform/SpongeViaConfig.java | 5 +++++ .../velocity/platform/VelocityViaConfig.java | 5 +++++ 7 files changed, 37 insertions(+), 6 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java index fa486666b..4ebe06601 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java @@ -245,6 +245,11 @@ public class BukkitViaConfig extends Config implements ViaVersionConfig { return getBoolean("fix-low-snow-collision", false); } + @Override + public boolean isInfestedBlocksFix() { + return getBoolean("fix-infested-block-breaking", true); + } + @Override public int get1_13TabCompleteDelay() { return getInt("1_13-tab-complete-delay", 0); diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java index 99f37deab..3ae2b9049 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java @@ -298,6 +298,11 @@ public class BungeeViaConfig extends Config implements ViaVersionConfig { return getBoolean("fix-low-snow-collision", false); } + @Override + public boolean isInfestedBlocksFix() { + return getBoolean("fix-infested-block-breaking", true); + } + @Override public int get1_13TabCompleteDelay() { return getInt("1_13-tab-complete-delay", 0); 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 48f0514b7..6e8f449e1 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -303,6 +303,13 @@ public interface ViaVersionConfig { */ boolean isSnowCollisionFix(); + /** + * When activated, infested blocks will be mapped to their normal stone variants for 1.13+ clients. + * + * @return True if enabled + */ + boolean isInfestedBlocksFix(); + /** * When greater than 0, enables tab complete request delaying by x ticks * diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java index a9d3636bf..ac1199f2e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java @@ -202,12 +202,14 @@ public class MappingData { } // Remap infested blocks, as they are instantly breakabale in 1.13+ and can't be broken by those clients on older servers - oldToNew[1552] = 1; // stone - oldToNew[1553] = 14; // cobblestone - oldToNew[1554] = 3983; // stone bricks - oldToNew[1555] = 3984; // mossy stone bricks - oldToNew[1556] = 3985; // cracked stone bricks - oldToNew[1557] = 3986; // chiseled stone bricks + if (Via.getConfig().isInfestedBlocksFix()) { + oldToNew[1552] = 1; // stone + oldToNew[1553] = 14; // cobblestone + oldToNew[1554] = 3983; // stone bricks + oldToNew[1555] = 3984; // mossy stone bricks + oldToNew[1556] = 3985; // cracked stone bricks + oldToNew[1557] = 3986; // chiseled stone bricks + } } @Override diff --git a/common/src/main/resources/assets/viaversion/config.yml b/common/src/main/resources/assets/viaversion/config.yml index 5394a40f7..660c9c57d 100644 --- a/common/src/main/resources/assets/viaversion/config.yml +++ b/common/src/main/resources/assets/viaversion/config.yml @@ -118,6 +118,8 @@ disable-1_13-auto-complete: false 1_13-tab-complete-delay: 0 # For 1.13 clients the smallest (1 layer) snow doesn't have collision, this will send these as 2 snowlayers for 1.13+ clients to prevent them bugging through them fix-low-snow-collision: false +# Infested blocks are instantly breakable for 1.13+ clients, resulting in them being unable to break them on sub 1.13 servers. This remaps them to their normal stone variants +fix-infested-block-breaking: true # In 1.14 the client page limit has been upped to 100 (from 50). Some anti-exploit plugins ban when clients go higher than 50. This option cuts edited books to 50 pages. truncate-1_14-books: false # This prevents clients using 1.9-1.13 on 1.8 servers from receiving no knockback/having velocity bugs whilst sneaking under a block. diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java index c6b2be549..287322974 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java @@ -251,6 +251,11 @@ public class SpongeViaConfig extends Config implements ViaVersionConfig { return getBoolean("fix-low-snow-collision", false); } + @Override + public boolean isInfestedBlocksFix() { + return getBoolean("fix-infested-block-breaking", true); + } + @Override public int get1_13TabCompleteDelay() { return getInt("1_13-tab-complete-delay", 0); diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java index ccffda7cb..4930f8e77 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java @@ -303,6 +303,11 @@ public class VelocityViaConfig extends Config implements ViaVersionConfig { return getBoolean("fix-low-snow-collision", false); } + @Override + public boolean isInfestedBlocksFix() { + return getBoolean("fix-infested-block-breaking", true); + } + @Override public int get1_13TabCompleteDelay() { return getInt("1_13-tab-complete-delay", 0); From 7e164b40c75f75ff7f63c06f91ee198315643170 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 10 Feb 2020 14:50:22 +0100 Subject: [PATCH 2/2] Add vines blockconnection to prevent unwanted climbing Fixes #1640 --- .../bukkit/platform/BukkitViaConfig.java | 5 ++ .../bungee/platform/BungeeViaConfig.java | 5 ++ .../ViaVersion/api/ViaVersionConfig.java | 7 +++ .../blockconnections/ConnectionData.java | 4 ++ .../VineConnectionHandler.java | 48 +++++++++++++++++++ .../resources/assets/viaversion/config.yml | 4 +- .../sponge/platform/SpongeViaConfig.java | 5 ++ .../velocity/platform/VelocityViaConfig.java | 5 ++ 8 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/VineConnectionHandler.java diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java index 4ebe06601..c7f986125 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaConfig.java @@ -240,6 +240,11 @@ public class BukkitViaConfig extends Config implements ViaVersionConfig { return getBoolean("flowerstem-when-block-above", false); } + @Override + public boolean isVineClimbFix() { + return getBoolean("vine-climb-fix", false); + } + @Override public boolean isSnowCollisionFix() { return getBoolean("fix-low-snow-collision", false); diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java index 3ae2b9049..521086e3b 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java @@ -293,6 +293,11 @@ public class BungeeViaConfig extends Config implements ViaVersionConfig { return getBoolean("flowerstem-when-block-above", false); } + @Override + public boolean isVineClimbFix() { + return getBoolean("vine-climb-fix", false); + } + @Override public boolean isSnowCollisionFix() { return getBoolean("fix-low-snow-collision", false); 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 6e8f449e1..7f37a8ea8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -296,6 +296,13 @@ public interface ViaVersionConfig { */ boolean isStemWhenBlockAbove(); + /** + * Vines not connected to any blocks will be mapped to air for 1.13+ clients to prevent them from climbing up. + * + * @return True if enabled + */ + boolean isVineClimbFix(); + /** * When activated, the 1-layer snow will be sent as 2-layer snow to 1.13+ clients to have collision. * diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java index 8fc49d24f..523d56c16 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java @@ -252,6 +252,10 @@ public class ConnectionData { initActions.addAll(ChorusPlantConnectionHandler.init()); initActions.add(TripwireConnectionHandler.init()); initActions.add(SnowyGrassConnectionHandler.init()); + if (Via.getConfig().isVineClimbFix()) { + initActions.add(VineConnectionHandler.init()); + } + for (String key : keyToId.keySet()) { WrappedBlockData wrappedBlockData = WrappedBlockData.fromString(key); for (ConnectorInitAction action : initActions) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/VineConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/VineConnectionHandler.java new file mode 100644 index 000000000..7d11ed845 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/VineConnectionHandler.java @@ -0,0 +1,48 @@ +package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections; + +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.minecraft.BlockFace; +import us.myles.ViaVersion.api.minecraft.Position; + +import java.util.HashSet; +import java.util.Set; + +class VineConnectionHandler extends ConnectionHandler { + private static final Set vines = new HashSet<>(); + + static ConnectionData.ConnectorInitAction init() { + final VineConnectionHandler connectionHandler = new VineConnectionHandler(); + return new ConnectionData.ConnectorInitAction() { + @Override + public void check(WrappedBlockData blockData) { + if (!blockData.getMinecraftKey().equals("minecraft:vine")) return; + + vines.add(blockData.getSavedBlockStateId()); + ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler); + } + }; + } + + @Override + public int connect(UserConnection user, Position position, int blockState) { + if (isAttachedToBlock(user, position)) return blockState; + + Position upperPos = position.getRelative(BlockFace.TOP); + int upperBlock = getBlockData(user, upperPos); + if (vines.contains(upperBlock) && isAttachedToBlock(user, upperPos)) return blockState; + + // Map to air if not attached to block, and upper block is also not a vine attached to a block + return 0; + } + + private boolean isAttachedToBlock(UserConnection user, Position position) { + return isAttachedToBlock(user, position, BlockFace.EAST) + || isAttachedToBlock(user, position, BlockFace.WEST) + || isAttachedToBlock(user, position, BlockFace.NORTH) + || isAttachedToBlock(user, position, BlockFace.SOUTH); + } + + private boolean isAttachedToBlock(UserConnection user, Position position, BlockFace blockFace) { + return ConnectionData.occludingStates.contains(getBlockData(user, position.getRelative(blockFace))); + } +} diff --git a/common/src/main/resources/assets/viaversion/config.yml b/common/src/main/resources/assets/viaversion/config.yml index 660c9c57d..dd3bf4748 100644 --- a/common/src/main/resources/assets/viaversion/config.yml +++ b/common/src/main/resources/assets/viaversion/config.yml @@ -135,7 +135,7 @@ fix-1_14-health-nan: true # Should 1.15+ clients respawn instantly / without showing a death screen? use-1_15-instant-respawn: false # -# Enable serverside block-connections for 1.13+ clients +# Enable serverside block-connections for 1.13+ clients - all of the options in this section are built around this option serverside-blockconnections: false # Sets the method for the block connections (world for highly experimental (USE AT OWN RISK) world-level or packet for packet-level) blockconnection-method: packet @@ -144,6 +144,8 @@ reduce-blockstorage-memory: false # When activated with serverside-blockconnections, flower parts with blocks above will be sent as stems # Useful for lobbyservers where users can't build and those stems are used decoratively flowerstem-when-block-above: false +# Vines that are not connected to blocks will be mapped to air, else 1.13+ would still be able to climb up on them. +vine-climb-fix: false # #----------------------------------------------------------# # 1.9+ CLIENTS ON 1.8 SERVERS OPTIONS # diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java index 287322974..f9dd42721 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java @@ -246,6 +246,11 @@ public class SpongeViaConfig extends Config implements ViaVersionConfig { return getBoolean("flowerstem-when-block-above", false); } + @Override + public boolean isVineClimbFix() { + return getBoolean("vine-climb-fix", false); + } + @Override public boolean isSnowCollisionFix() { return getBoolean("fix-low-snow-collision", false); diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java index 4930f8e77..48c48f1df 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaConfig.java @@ -298,6 +298,11 @@ public class VelocityViaConfig extends Config implements ViaVersionConfig { return getBoolean("flowerstem-when-block-above", false); } + @Override + public boolean isVineClimbFix() { + return getBoolean("vine-climb-fix", false); + } + @Override public boolean isSnowCollisionFix() { return getBoolean("fix-low-snow-collision", false);