From a8e81935cc2a9ccfef4a906966b90e730679fd01 Mon Sep 17 00:00:00 2001 From: Matsv Date: Sat, 10 Jun 2017 16:34:08 +0200 Subject: [PATCH] Handle FallingBlocks in 1.9.4-1.11.2 --- .../Protocol1_10To1_11.java | 10 +++++---- ...ityPackets.java => EntityPackets1_11.java} | 21 ++++++++++++++++++- .../Protocol1_11To1_11_1.java | 6 +++--- ...yPackets.java => EntityPackets1_11_1.java} | 2 +- .../packets/EntityPackets1_12.java | 2 +- .../Protocol1_9_4To1_10.java | 9 ++++---- ...ityPackets.java => EntityPackets1_10.java} | 21 ++++++++++++++++++- 7 files changed, 56 insertions(+), 15 deletions(-) rename core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/{EntityPackets.java => EntityPackets1_11.java} (95%) rename core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/packets/{EntityPackets.java => EntityPackets1_11_1.java} (99%) rename core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/{EntityPackets.java => EntityPackets1_10.java} (93%) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java index a9b9ca5b..eef12f9d 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java @@ -14,7 +14,7 @@ import lombok.Getter; import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.BlockItemPackets; -import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.EntityPackets; +import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.EntityPackets1_11; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.PlayerPackets; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.SoundPackets; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.WindowTracker; @@ -23,13 +23,15 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; public class Protocol1_10To1_11 extends BackwardsProtocol { @Getter - private EntityPackets entityPackets; // Required for the item rewriter + private EntityPackets1_11 entityPackets; // Required for the item rewriter + @Getter + private BlockItemPackets blockItemPackets; @Override protected void registerPackets() { - (entityPackets = new EntityPackets()).register(this); + (entityPackets = new EntityPackets1_11()).register(this); new PlayerPackets().register(this); - new BlockItemPackets().register(this); + (blockItemPackets = new BlockItemPackets()).register(this); new SoundPackets().register(this); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets1_11.java similarity index 95% rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets.java rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets1_11.java index 91dc8e29..2bb7a8d2 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets1_11.java @@ -14,10 +14,12 @@ import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.entities.types.AbstractEntityType; +import nl.matsv.viabackwards.api.entities.types.EntityType1_12; import nl.matsv.viabackwards.api.exceptions.RemovedValueException; import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage; +import nl.matsv.viabackwards.utils.Block; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; @@ -34,7 +36,7 @@ import java.util.Optional; import static nl.matsv.viabackwards.api.entities.types.EntityType1_11.*; -public class EntityPackets extends EntityRewriter { +public class EntityPackets1_11 extends EntityRewriter { @Override protected void registerPackets(Protocol1_10To1_11 protocol) { @@ -84,6 +86,23 @@ public class EntityPackets extends EntityRewriter { } } }); + + // Handle FallingBlock blocks + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Optional type = EntityType1_12.ObjectType.findById(wrapper.get(Type.BYTE, 0)); + if (type.isPresent() && type.get().equals(EntityType1_12.ObjectType.FALLING_BLOCK)) { + int objectData = wrapper.get(Type.INT, 0); + int objType = objectData & 4095; + int data = objectData >> 12 & 15; + + Block block = getProtocol().getBlockItemPackets().handleBlock(objType, data); + + wrapper.set(Type.INT, 0, block.getId() | block.getData() << 12); + } + } + }); } }); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/Protocol1_11To1_11_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/Protocol1_11To1_11_1.java index c294c569..8e1774d7 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/Protocol1_11To1_11_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/Protocol1_11To1_11_1.java @@ -13,18 +13,18 @@ package nl.matsv.viabackwards.protocol.protocol1_11to1_11_1; import lombok.Getter; import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; -import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.packets.EntityPackets; +import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.packets.EntityPackets1_11_1; import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.packets.ItemPackets; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @Getter public class Protocol1_11To1_11_1 extends BackwardsProtocol { - private EntityPackets entityPackets; + private EntityPackets1_11_1 entityPackets; @Override protected void registerPackets() { - (entityPackets = new EntityPackets()).register(this); + (entityPackets = new EntityPackets1_11_1()).register(this); new ItemPackets().register(this); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/packets/EntityPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/packets/EntityPackets1_11_1.java similarity index 99% rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/packets/EntityPackets.java rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/packets/EntityPackets1_11_1.java index 4889f37d..828620d0 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/packets/EntityPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11to1_11_1/packets/EntityPackets1_11_1.java @@ -29,7 +29,7 @@ import java.util.Optional; import static nl.matsv.viabackwards.api.entities.types.EntityType1_11.*; -public class EntityPackets extends EntityRewriter { +public class EntityPackets1_11_1 extends EntityRewriter { @Override protected void registerPackets(Protocol1_11To1_11_1 protocol) { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/EntityPackets1_12.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/EntityPackets1_12.java index 6f9ac943..a2a1bd02 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/EntityPackets1_12.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/EntityPackets1_12.java @@ -83,7 +83,7 @@ public class EntityPackets1_12 extends EntityRewriter { } }); - // Replace falling blocks + // Handle FallingBlock blocks handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/Protocol1_9_4To1_10.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/Protocol1_9_4To1_10.java index ed2f8fb8..0ab9276e 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/Protocol1_9_4To1_10.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/Protocol1_9_4To1_10.java @@ -15,20 +15,21 @@ import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets.BlockItemPackets; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets.ChangedPackets; -import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets.EntityPackets; +import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets.EntityPackets1_10; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets.SoundPackets; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; @Getter public class Protocol1_9_4To1_10 extends BackwardsProtocol { - private EntityPackets entityPackets; // Required for the item rewriter + private EntityPackets1_10 entityPackets; // Required for the item rewriter + private BlockItemPackets blockItemPackets; protected void registerPackets() { new ChangedPackets().register(this); new SoundPackets().register(this); - (entityPackets = new EntityPackets()).register(this); - new BlockItemPackets().register(this); + (entityPackets = new EntityPackets1_10()).register(this); + (blockItemPackets = new BlockItemPackets()).register(this); } public void init(UserConnection user) { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/EntityPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/EntityPackets1_10.java similarity index 93% rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/EntityPackets.java rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/EntityPackets1_10.java index ac6a5539..73ef654c 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/EntityPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_9_4to1_10/packets/EntityPackets1_10.java @@ -16,9 +16,11 @@ import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.entities.types.AbstractEntityType; import nl.matsv.viabackwards.api.entities.types.EntityType1_10; import nl.matsv.viabackwards.api.entities.types.EntityType1_11; +import nl.matsv.viabackwards.api.entities.types.EntityType1_12; import nl.matsv.viabackwards.api.exceptions.RemovedValueException; import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; +import nl.matsv.viabackwards.utils.Block; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; @@ -35,7 +37,7 @@ import java.util.Optional; import static nl.matsv.viabackwards.api.entities.types.EntityType1_10.EntityType; import static nl.matsv.viabackwards.api.entities.types.EntityType1_11.getTypeFromId; -public class EntityPackets extends EntityRewriter { +public class EntityPackets1_10 extends EntityRewriter { @Override protected void registerPackets(Protocol1_9_4To1_10 protocol) { @@ -86,6 +88,23 @@ public class EntityPackets extends EntityRewriter { } } }); + + // Handle FallingBlock blocks + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + Optional type = EntityType1_12.ObjectType.findById(wrapper.get(Type.BYTE, 0)); + if (type.isPresent() && type.get().equals(EntityType1_12.ObjectType.FALLING_BLOCK)) { + int objectData = wrapper.get(Type.INT, 0); + int objType = objectData & 4095; + int data = objectData >> 12 & 15; + + Block block = getProtocol().getBlockItemPackets().handleBlock(objType, data); + + wrapper.set(Type.INT, 0, block.getId() | block.getData() << 12); + } + } + }); } });