diff --git a/all/pom.xml b/all/pom.xml index c470c4e7..7db043b3 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -15,7 +15,7 @@ viabackwards-parent nl.matsv - 2.3.2-DEV + 2.4.0-SNAPSHOT 4.0.0 diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 1ec0e931..91da18e2 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -15,7 +15,7 @@ viabackwards-parent nl.matsv - 2.3.2-DEV + 2.4.0-SNAPSHOT 4.0.0 @@ -32,7 +32,7 @@ org.spigotmc spigot-api - 1.11-R0.1-SNAPSHOT + 1.13-R0.1-SNAPSHOT provided diff --git a/bungee/pom.xml b/bungee/pom.xml index 45e927d0..510c7df9 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -15,7 +15,7 @@ viabackwards-parent nl.matsv - 2.3.2-DEV + 2.4.0-SNAPSHOT 4.0.0 @@ -34,7 +34,7 @@ net.md-5 bungeecord-api - 1.11-SNAPSHOT + 1.13-SNAPSHOT provided diff --git a/core/pom.xml b/core/pom.xml index 5262b834..265ab1a0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -15,7 +15,7 @@ viabackwards-parent nl.matsv - 2.3.2-DEV + 2.4.0-SNAPSHOT 4.0.0 diff --git a/core/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java b/core/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java index 70200830..8074c8e7 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java @@ -11,7 +11,24 @@ package nl.matsv.viabackwards.api; import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.packets.State; public abstract class BackwardsProtocol extends Protocol { + public void out(State state, int oldPacketID, int newPacketID) { + this.registerOutgoing(state, oldPacketID, newPacketID, null); + } + + public void out(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) { + this.registerOutgoing(state, oldPacketID, newPacketID, packetRemapper); + } + + public void in(State state, int oldPacketID, int newPacketID) { + this.registerIncoming(state, oldPacketID, newPacketID, null); + } + + public void in(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) { + this.registerIncoming(state, oldPacketID, newPacketID, packetRemapper); + } } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java index 3bbddc28..df716c7c 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java @@ -14,6 +14,7 @@ import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1; import nl.matsv.viabackwards.protocol.protocol1_12_1to1_12_2.Protocol1_12_1To1_12_2; +import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_12to1_12_1.Protocol1_12To1_12_1; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; @@ -38,6 +39,7 @@ public interface ViaBackwardsPlatform { ProtocolRegistry.registerProtocol(new Protocol1_11_1To1_12(), Collections.singletonList(ProtocolVersion.v1_11_1.getId()), ProtocolVersion.v1_12.getId()); ProtocolRegistry.registerProtocol(new Protocol1_12To1_12_1(), Collections.singletonList(ProtocolVersion.v1_12.getId()), ProtocolVersion.v1_12_1.getId()); ProtocolRegistry.registerProtocol(new Protocol1_12_1To1_12_2(), Collections.singletonList(ProtocolVersion.v1_12_1.getId()), ProtocolVersion.v1_12_2.getId()); + ProtocolRegistry.registerProtocol(new Protocol1_12_2To1_13(), Collections.singletonList(ProtocolVersion.v1_12_2.getId()), ProtocolVersion.v1_13.getId()); } } @@ -53,9 +55,9 @@ public interface ViaBackwardsPlatform { boolean upToDate = false; try { Class clazz = Class.forName("us.myles.ViaVersion.api.protocol.ProtocolVersion"); - Field v1_12_2 = clazz.getField("v1_12_2"); + Field v1_13 = clazz.getField("v1_13"); - upToDate = (v1_12_2 != null); + upToDate = (v1_13 != null); } catch (ClassNotFoundException | NoSuchFieldException ignored) { } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java new file mode 100644 index 00000000..dd04b730 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2016 Matsv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13; + +import nl.matsv.viabackwards.api.BackwardsProtocol; +import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings; +import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPackets1_13; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.remapper.PacketHandler; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; + +public class Protocol1_12_2To1_13 extends BackwardsProtocol { + @Override + protected void registerPackets() { + new BlockItemPackets1_13().register(this); + + // Thanks to https://wiki.vg/index.php?title=Pre-release_protocol&oldid=14150 + + + out(State.PLAY, 0x00, 0x00, cancel()); + out(State.PLAY, 0x04, 0x04, cancel());// Spawn Painting TODO MODIFIED + out(State.PLAY, 0x07, 0x07, cancel()); // Statistics TODO MODIFIED + out(State.PLAY, 0x09, 0x09, cancel()); // Update Block Entity TODO MODIFIED + out(State.PLAY, 0x0B, 0x0B, cancel()); // Block Change TODO MODIFIED + out(State.PLAY, 0x0E, 0x0F); // Chat Message (clientbound) + out(State.PLAY, 0x0F, 0x10, cancel()); // Multi Block Change TODO MODIFIED + out(State.PLAY, 0x10, 0x0E, cancel()); // Tab-Complete (clientbound) TODO MODIFIED + out(State.PLAY, 0x11, -1, cancel()); // Declare Commands TODO NEW + out(State.PLAY, 0x12, 0x11, cancel()); // Confirm Transaction (clientbound) + out(State.PLAY, 0x13, 0x12, cancel()); // Close Window (clientbound) + out(State.PLAY, 0x14, 0x13, cancel()); // Open Window + out(State.PLAY, 0x15, 0x14, cancel()); // Window Items + out(State.PLAY, 0x16, 0x15, cancel()); // Window Property + out(State.PLAY, 0x17, 0x16, cancel()); // Set Slot + out(State.PLAY, 0x18, 0x17); // Set Cooldown + out(State.PLAY, 0x19, 0x18); // Plugin Message (clientbound) TODO MODIFIED + out(State.PLAY, 0x1A, 0x19, cancel()); // Named Sound Effect TODO MODIFIED + out(State.PLAY, 0x1B, 0x1A); // Disconnect (play) + out(State.PLAY, 0x1C, 0x1B); // Entity Status + out(State.PLAY, 0x1D, -1, cancel()); // NBT Query Response TODO NEW + out(State.PLAY, 0x1E, 0x1C); // Explosion + out(State.PLAY, 0x1F, 0x1D); // Unload Chunk + out(State.PLAY, 0x20, 0x1E); // Change Game State + out(State.PLAY, 0x21, 0x1F); // Keep Alive (clientbound) + + // Chunk Data -> moved to BlockItemPackets + + + + out(State.PLAY, 0x23, 0x21, cancel()); // Effect TODO MODIFIED + out(State.PLAY, 0x24, 0x22, cancel()); // Spawn Particle TODO MODIFIED + out(State.PLAY, 0x25, 0x23, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // 0 - Entity ID + map(Type.UNSIGNED_BYTE); // 1 - Gamemode + map(Type.INT); // 2 - Dimension + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); + int dimensionId = wrapper.get(Type.INT, 1); + clientChunks.setEnvironment(dimensionId); + } + }); + } + }); // Join Game + out(State.PLAY, 0x26, 0x24, cancel()); // Map TODO MODIFIED + out(State.PLAY, 0x27, 0x25); // Entity + out(State.PLAY, 0x28, 0x26); // Entity Relative Move + out(State.PLAY, 0x29, 0x27); // Entity Look And Relative Move + out(State.PLAY, 0x2A, 0x28); // Entity Look + out(State.PLAY, 0x2B, 0x29); // Vehicle Move (clientbound) + out(State.PLAY, 0x2C, 0x2A); // Open Sign Editor + out(State.PLAY, 0x2D, 0x2B, cancel()); // Craft Recipe Response TODO MODIFIED + out(State.PLAY, 0x2E, 0x2C); // Player Abilities (clientbound) + out(State.PLAY, 0x2F, 0x2D); // Combat Event + out(State.PLAY, 0x30, 0x2E); // Player List Item + out(State.PLAY, 0x31, -1, cancel()); // Face Player TODO NEW + out(State.PLAY, 0x32, 0x2F); // Player Position And Look (clientbound) + out(State.PLAY, 0x33, 0x30); // Use Bed + out(State.PLAY, 0x34, 0x31, cancel()); // Unlock Recipes TODO MODIFIED + out(State.PLAY, 0x35, 0x32); // Destroy Entities + out(State.PLAY, 0x36, 0x33); // Remove Entity Effect + out(State.PLAY, 0x37, 0x34); // Resource Pack Send + out(State.PLAY, 0x38, 0x35); // Respawn + out(State.PLAY, 0x39, 0x36); // Entity Head Look + out(State.PLAY, 0x3A, 0x37); // Select Advancement Tab + out(State.PLAY, 0x3B, 0x38); // World Border + out(State.PLAY, 0x3C, 0x39); // Camera + out(State.PLAY, 0x3D, 0x3A, cancel()); // Held Item Change (clientbound) + out(State.PLAY, 0x3E, 0x3B); // Display Scoreboard + out(State.PLAY, 0x3F, 0x3C, cancel()); // Entity Metadata + out(State.PLAY, 0x40, 0x3D); // Attach Entity + out(State.PLAY, 0x41, 0x3E); // Entity Velocity + out(State.PLAY, 0x42, 0x3F, cancel()); // Entity Equipment + out(State.PLAY, 0x43, 0x40); // Set Experience + out(State.PLAY, 0x44, 0x41); // Update Health + out(State.PLAY, 0x45, 0x42, cancel()); // Scoreboard Objective TODO MODIFIED + out(State.PLAY, 0x46, 0x43); // Set Passengers + out(State.PLAY, 0x47, 0x44, cancel()); // Teams TODO MODIFIED + out(State.PLAY, 0x48, 0x45); // Update Score + out(State.PLAY, 0x49, 0x46); // Spawn Position + out(State.PLAY, 0x4A, 0x47); // Time Update + out(State.PLAY, 0x4B, 0x48); // Title + out(State.PLAY, 0x4C, -1, cancel()); // Stop Sound TODO NEW + out(State.PLAY, 0x4D, 0x49); // Sound Effect + out(State.PLAY, 0x4E, 0x4A); // Player List Header And Footer + out(State.PLAY, 0x4F, 0x4B, cancel()); // Collect Item + out(State.PLAY, 0x50, 0x4C); // Entity Teleport + out(State.PLAY, 0x51, 0x4D, cancel()); // Advancements + out(State.PLAY, 0x52, 0x4E); // Entity Properties + out(State.PLAY, 0x53, 0x4F); // Entity Effect + out(State.PLAY, 0x54, -1, cancel()); // Declare Recipes TODO NEW + out(State.PLAY, 0x55, -1, cancel()); // Tags TODO NEW + + + in(State.PLAY, 0x01, -1, cancel()); // Query Block NBT TODO NEW + in(State.PLAY, 0x05, 0x01); // Tab-Complete (serverbound) TODO MODIFIED + in(State.PLAY, 0x06, 0x05); //Confirm Transaction (serverbound) + in(State.PLAY, 0x07, 0x06); // Enchant Item + in(State.PLAY, 0x08, 0x07); // Click Window + in(State.PLAY, 0x09, 0x08); // Close Window (serverbound) + in(State.PLAY, 0x0A, 0x09, cancel()); // Plugin message (serverbound) TODO MODIFIED + in(State.PLAY, 0x0B, -1, cancel()); // Edit Book TODO NEW + in(State.PLAY, 0x0C, -1, cancel()); // Query Entity NBT TODO NEW + in(State.PLAY, 0x0D, 0x0A); // Use Entity + in(State.PLAY, 0x0E, 0x0B); // Keep Alive (serverbound) + in(State.PLAY, 0x0F, 0x0C); // Player + in(State.PLAY, 0x10, 0x0D); // Player Position + in(State.PLAY, 0x11, 0x0E); // Player Position And Look (serverbound) + in(State.PLAY, 0x12, 0x0F); // Player Look + in(State.PLAY, 0x13, 0x10); // Vehicle Move (serverbound) + in(State.PLAY, 0x14, 0x11); // Steer Boat + in(State.PLAY, 0x15, -1, cancel()); // Pick Item TODO NEW + in(State.PLAY, 0x16, 0x12, cancel()); // Craft Recipe Request TODO MODIFIED + in(State.PLAY, 0x17, 0x13); // Player Abilities (serverbound) + in(State.PLAY, 0x18, 0x14); // Player Digging + in(State.PLAY, 0x19, 0x15); // Entity Action + in(State.PLAY, 0x1A, 0x16); // Steer Vehicle + in(State.PLAY, 0x1B, 0x17); // Recipe Book Data + in(State.PLAY, 0x1C, -1, cancel()); // Name Item TODO NEW + in(State.PLAY, 0x1D, 0x18); // Resource Pack Status + in(State.PLAY, 0x1E, 0x19); // Advancement Tab + in(State.PLAY, 0x1F, -1); // Select Trade + in(State.PLAY, 0x20, -1); // Set Beacon Effect + in(State.PLAY, 0x21, 0x1A); // Held Item Change (serverbound) + in(State.PLAY, 0x22, -1, cancel()); // Update Command Block TODO NEW + in(State.PLAY, 0x23, -1, cancel()); // Update Command Block Minecart TODO NEW + in(State.PLAY, 0x24, 0x1B); // Creative Inventory Action + in(State.PLAY, 0x25, -1, cancel()); // Update Structure Block TODO NEW + in(State.PLAY, 0x26, 0x1C); // Update Sign + in(State.PLAY, 0x27, 0x1D); // Animation (serverbound) + in(State.PLAY, 0x28, 0x1E); // Spectate + in(State.PLAY, 0x29, 0x1F); // Player Block Placement + in(State.PLAY, 0x2A, 0x20); // Use Item + + } + + @Override + public void init(UserConnection user) { + // Register ClientWorld + if (!user.has(ClientWorld.class)) + user.put(new ClientWorld(user)); + + } + + public PacketRemapper cancel() { + return new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper packetWrapper) throws Exception { + packetWrapper.cancel(); + } + }); + } + }; + } + + static { + BackwardsMappings.init(); + } + +} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/BackwardsMappings.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/BackwardsMappings.java new file mode 100644 index 00000000..34d146ca --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/BackwardsMappings.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016 Matsv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data; + +import us.myles.ViaVersion.api.Via; +import us.myles.viaversion.libs.gson.JsonElement; +import us.myles.viaversion.libs.gson.JsonObject; + +import java.util.Arrays; +import java.util.Map; + +import static us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData.loadData; + +public class BackwardsMappings { + public static BlockMappings blockMappings; + + public static void init() { + us.myles.viaversion.libs.gson.JsonObject mapping1_12 = loadData("mapping-1.12.json"); + us.myles.viaversion.libs.gson.JsonObject mapping1_13 = loadData("mapping-1.13.json"); + + Via.getPlatform().getLogger().info("Loading block mapping..."); + blockMappings = new BlockMappingsShortArray(mapping1_13.getAsJsonObject("blocks"), mapping1_12.getAsJsonObject("blocks")); + } + + + private static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { + for (Map.Entry entry : oldIdentifiers.entrySet()) { + Map.Entry value = findValue(newIdentifiers, entry.getValue().getAsString()); + if (value == null) { + if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { + Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( "); + } + continue; + } + output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey()); + } + } + + + private static Map.Entry findValue(JsonObject object, String needle) { + for (Map.Entry entry : object.entrySet()) { + String value = entry.getValue().getAsString(); + if (value.equals(needle)) { + return entry; + } + } + return null; + } + + public interface BlockMappings { + int getNewBlock(int old); + } + + private static class BlockMappingsShortArray implements BlockMappings { + private short[] oldToNew = new short[4084 * 6]; + + private BlockMappingsShortArray(JsonObject oldMapping, JsonObject newMapping) { + Arrays.fill(oldToNew, (short) -1); + mapIdentifiers(oldToNew, oldMapping, newMapping); + } + + @Override + public int getNewBlock(int old) { + return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1; + } + } +} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java new file mode 100644 index 00000000..e3310d8b --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2016 Matsv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets; + +import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter; +import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; +import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.Via; +import us.myles.ViaVersion.api.minecraft.chunks.Chunk; +import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; +import us.myles.ViaVersion.api.remapper.PacketHandler; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.packets.State; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; +import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; + +public class BlockItemPackets1_13 extends BlockItemRewriter { + @Override + protected void registerPackets(Protocol1_12_2To1_13 protocol) { + + // Chunk packet + protocol.out(State.PLAY, 0x22, 0x20, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + + Chunk1_9_3_4Type type_old = new Chunk1_9_3_4Type(clientWorld); + Chunk1_13Type type = new Chunk1_13Type(clientWorld); + Chunk chunk = wrapper.read(type); + + for (int i = 0; i < chunk.getSections().length; i++) { + ChunkSection section = chunk.getSections()[i]; + if (section == null) { + continue; + } + + for (int p = 0; p < section.getPalette().size(); p++) { + int old = section.getPalette().get(p); + if (old != 0) { + section.getPalette().set(p, toNewId(old)); + } + } + } + + // Rewrite biome id 255 to plains + if (chunk.isBiomeData()) { + for (int i = 0; i < 256; i++) { + chunk.getBiomeData()[i] = 1; // Plains + } + } + + chunk.getBlockEntities().clear(); + wrapper.write(type_old, chunk); + } + }); + } + } + ); + } + + public static int toNewId(int oldId) { + if (oldId < 0) { + oldId = 0; // Some plugins use negative numbers to clear blocks, remap them to air. + } + int newId = BackwardsMappings.blockMappings.getNewBlock(oldId); + if (newId != -1) + return newId; + + Via.getPlatform().getLogger().warning("Missing block completely " + oldId); + // Default stone + return 1 << 4; + } + + @Override + protected void registerRewrites() { + + } +} diff --git a/pom.xml b/pom.xml index 6a9fe0c8..e45c11f9 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ nl.matsv viabackwards-parent - 2.3.2-DEV + 2.4.0-SNAPSHOT pom Allow newer clients to join older server versions. @@ -65,7 +65,7 @@ us.myles viaversion - 1.3.0 + 1.6.0 provided diff --git a/sponge/pom.xml b/sponge/pom.xml index 200b3c10..f2c67031 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -15,7 +15,7 @@ viabackwards-parent nl.matsv - 2.3.2-DEV + 2.4.0-SNAPSHOT 4.0.0