From d484545bef8b893d47113d07525f109e468a742a Mon Sep 17 00:00:00 2001 From: Matsv Date: Mon, 5 Feb 2018 20:51:34 +0100 Subject: [PATCH 1/2] Change keepAlive's initial value to fix Gerrygames/ViaRewind#14 --- .../KeepAliveTracker.java | 28 +++++++++++++++++++ .../Protocol1_12_1To1_12_2.java | 6 ++-- .../KeepAliveTracker.java | 18 ------------ 3 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/KeepAliveTracker.java delete mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/KeepAliveTracker.java diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/KeepAliveTracker.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/KeepAliveTracker.java new file mode 100644 index 00000000..300d2bc7 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/KeepAliveTracker.java @@ -0,0 +1,28 @@ +/* + * 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_1to1_12_2; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import us.myles.ViaVersion.api.data.StoredObject; +import us.myles.ViaVersion.api.data.UserConnection; + +@Getter +@Setter +@ToString +public class KeepAliveTracker extends StoredObject { + private long keepAlive = Integer.MAX_VALUE; + + public KeepAliveTracker(UserConnection user) { + super(user); + } +} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java index 67d5eb18..820f21b3 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java @@ -11,7 +11,6 @@ package nl.matsv.viabackwards.protocol.protocol1_12_1to1_12_2; import nl.matsv.viabackwards.api.BackwardsProtocol; -import nl.matsv.viabackwards.protocol.protocol1_12to1_12_1.KeepAliveTracker; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.remapper.PacketHandler; @@ -36,7 +35,8 @@ public class Protocol1_12_1To1_12_2 extends BackwardsProtocol { } }); } - }); // Keep alive + }); + // Incoming // 0xb - Keep alive registerIncoming(State.PLAY, 0xb, 0xb, new PacketRemapper() { @@ -53,7 +53,7 @@ public class Protocol1_12_1To1_12_2 extends BackwardsProtocol { } packetWrapper.write(Type.LONG, realKeepAlive); // Reset KeepAliveTracker (to prevent sending same valid value in a row causing a timeout) - packetWrapper.user().get(KeepAliveTracker.class).setKeepAlive(Long.MIN_VALUE); + packetWrapper.user().get(KeepAliveTracker.class).setKeepAlive(Integer.MAX_VALUE); } }); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/KeepAliveTracker.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/KeepAliveTracker.java deleted file mode 100644 index 07b02154..00000000 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/KeepAliveTracker.java +++ /dev/null @@ -1,18 +0,0 @@ -package nl.matsv.viabackwards.protocol.protocol1_12to1_12_1; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import us.myles.ViaVersion.api.data.StoredObject; -import us.myles.ViaVersion.api.data.UserConnection; - -@Getter -@Setter -@ToString -public class KeepAliveTracker extends StoredObject { - private long keepAlive; - - public KeepAliveTracker(UserConnection user) { - super(user); - } -} From 7296017ab8e55c585f66482accc426b7c444460c Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Tue, 20 Nov 2018 15:32:49 +0100 Subject: [PATCH 2/2] ViaVersion 2.0.0 compatibility --- .../api/rewriters/BlockItemRewriter.java | 65 ++++++++++++------- .../packets/BlockItemPackets1_11.java | 4 +- .../packets/BlockItemPackets1_12.java | 4 +- .../packets/BlockItemPackets1_10.java | 4 +- pom.xml | 2 +- 5 files changed, 50 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java index c8ebd273..3ad77ff2 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java @@ -138,10 +138,18 @@ public abstract class BlockItemRewriter extends Rew if (!(tag.contains("x") && tag.contains("y") && tag.contains("z"))) continue; Pos pos = new Pos( - (int) tag.get("x").getValue() % 16, + (int) tag.get("x").getValue() & 0xF, (int) tag.get("y").getValue(), - (int) tag.get("z").getValue() % 16); + (int) tag.get("z").getValue() & 0xF); tags.put(pos, tag); + + // Handle given Block Entities + ChunkSection section = chunk.getSections()[pos.getY() >> 4]; + if (section == null) continue; + int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ()); + int btype = block >> 4; + if (!hasBlockEntityHandler(btype)) continue; + replacementData.get(btype).getBlockEntityHandler().handleOrNewCompoundTag(block, tag); } for (int i = 0; i < chunk.getSections().length; i++) { @@ -149,32 +157,45 @@ public abstract class BlockItemRewriter extends Rew if (section == null) continue; + boolean hasBlockEntityHandler = false; + + // Map blocks + for (int j = 0; j < section.getPaletteSize(); j++) { + int block = section.getPaletteEntry(j); + int btype = block >> 4; + int meta = block & 0xF; + + if (containsBlock(btype)) { + Block b = handleBlock(btype, meta); + section.setPaletteEntry(j, (b.getId() << 4) | (b.getData() & 0xF)); + } + + hasBlockEntityHandler = hasBlockEntityHandler || hasBlockEntityHandler(btype); + } + + if (!hasBlockEntityHandler) continue; + + // We need to handle a Block Entity :( for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { - int block = section.getBlock(x, y, z); + int block = section.getFlatBlock(x, y, z); int btype = block >> 4; int meta = block & 15; - if (containsBlock(btype)) { - Block b = handleBlock(btype, meta); // Type / data - section.setBlock(x, y, z, b.getId(), b.getData()); - } - // Entity Tags - if (hasBlockEntityHandler(btype)) { - Pos pos = new Pos(x, (y + (i << 4)), z); - CompoundTag tag = null; - if (tags.containsKey(pos)) { - tag = tags.get(pos); - } else { - tag = new CompoundTag(""); - tag.put(new IntTag("x", x + (chunk.getX() << 4))); - tag.put(new IntTag("y", y + (i << 4))); - tag.put(new IntTag("z", z + (chunk.getZ() << 4))); - chunk.getBlockEntities().add(tag); - } - replacementData.get(btype).getBlockEntityHandler().handleOrNewCompoundTag(block, tag); - } + if (!hasBlockEntityHandler(btype)) continue; + + Pos pos = new Pos(x, (y + (i << 4)), z); + + // Already handled above + if (tags.containsKey(pos)) continue; + + CompoundTag tag = new CompoundTag(""); + tag.put(new IntTag("x", x + (chunk.getX() << 4))); + tag.put(new IntTag("y", y + (i << 4))); + tag.put(new IntTag("z", z + (chunk.getZ() << 4))); + replacementData.get(btype).getBlockEntityHandler().handleOrNewCompoundTag(block, tag); + chunk.getBlockEntities().add(tag); } } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java index 80509d0a..10519452 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java @@ -22,13 +22,13 @@ import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors; import nl.matsv.viabackwards.utils.Block; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; 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_1_2to1_9_3_4.chunks.Chunk1_9_3_4; 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; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; @@ -226,7 +226,7 @@ public class BlockItemPackets1_11 extends BlockItemRewriter ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); // Use the 1.10 Chunk type since nothing changed. - Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type); + Chunk chunk = wrapper.passthrough(type); handleChunk(chunk); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java index bd60e6fd..fc87650f 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java @@ -15,13 +15,13 @@ import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors; import nl.matsv.viabackwards.utils.Block; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; 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_1_2to1_9_3_4.chunks.Chunk1_9_3_4; 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; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; @@ -171,7 +171,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); - Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type); + Chunk chunk = wrapper.passthrough(type); handleChunk(chunk); } diff --git a/pom.xml b/pom.xml index 37264eec..9a000266 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ us.myles viaversion - 1.4.1 + 2.0.0-SNAPSHOT provided