From d66c2f2f5d79c81109a92aea7e0ddd975922a4f5 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Thu, 17 Jan 2019 16:02:39 -0200 Subject: [PATCH] Connect grass block to snow (cherry picked from commit 69b0d43c9825d896374fc26246410530c5b7495f) --- .../blockconnections/ConnectionData.java | 2 +- .../SnowyGrassConnectionHandler.java | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/SnowyGrassConnectionHandler.java 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 ef39faec2..010e79f98 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 @@ -168,8 +168,8 @@ public class ConnectionData { BasicFenceConnectionHandler.init(); NetherFenceConnectionHandler.init(); WallConnectionHandler.init(); - MelonConnectionHandler.init(); GlassConnectionHandler.init(); + SnowyGrassConnectionHandler.init(); ChestConnectionHandler.init(); DoorConnectionHandler.init(); RedstoneConnectionHandler.init(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/SnowyGrassConnectionHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/SnowyGrassConnectionHandler.java new file mode 100644 index 000000000..aa4e4ccc6 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/SnowyGrassConnectionHandler.java @@ -0,0 +1,49 @@ +package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections; + +import us.myles.ViaVersion.api.Pair; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.minecraft.BlockFace; +import us.myles.ViaVersion.api.minecraft.Position; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class SnowyGrassConnectionHandler extends ConnectionHandler { + private static Map, Integer> grassBlocks = new HashMap<>(); + private static Set snows = new HashSet<>(); + + static void init() { + Set snowyGrassBlocks = new HashSet<>(); + snowyGrassBlocks.add("minecraft:grass_block"); + snowyGrassBlocks.add("minecraft:podzol"); + snowyGrassBlocks.add("minecraft:mycelium"); + + SnowyGrassConnectionHandler handler = new SnowyGrassConnectionHandler(); + for (Map.Entry blockState : ConnectionData.keyToId.entrySet()) { + WrappedBlockData data = WrappedBlockData.fromString(blockState.getKey()); + if (snowyGrassBlocks.contains(data.getMinecraftKey())) { + ConnectionData.connectionHandlerMap.put(blockState.getValue(), handler); + data.set("snowy", "true"); + grassBlocks.put(new Pair<>(blockState.getValue(), true), data.getBlockStateId()); + data.set("snowy", "false"); + grassBlocks.put(new Pair<>(blockState.getValue(), false), data.getBlockStateId()); + } + if (data.getMinecraftKey().equals("minecraft:snow") || data.getMinecraftKey().equals("minecraft:snow_block")) { + ConnectionData.connectionHandlerMap.put(blockState.getValue(), handler); + snows.add(blockState.getValue()); + } + } + } + + @Override + public int connect(UserConnection user, Position position, int blockState) { + int blockUpId = getBlockData(user, position.getRelative(BlockFace.TOP)); + Integer newId = grassBlocks.get(new Pair<>(blockState, snows.contains(blockUpId))); + if (newId != null) { + return newId; + } + return blockState; + } +} \ No newline at end of file