From 3a4014623eccb0187b355d38af5323654a313d84 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Mon, 26 Aug 2024 22:28:12 +0200 Subject: [PATCH] Spawn falling blocks at correct position --- .../rewriter/EntityPacketRewriter1_19_4.java | 80 ++++++++++++++++++- .../storage/EntityTracker1_19_4.java | 32 ++++---- .../storage/LinkedEntityStorage.java | 14 +++- 3 files changed, 105 insertions(+), 21 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java index a733899d..9488f6e2 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java @@ -20,22 +20,26 @@ package com.viaversion.viabackwards.protocol.v1_19_4to1_19_3.rewriter; import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.ListTag; import com.viaversion.nbt.tag.NumberTag; +import com.viaversion.viabackwards.api.entities.storage.EntityPositionHandler; import com.viaversion.viabackwards.api.entities.storage.EntityReplacement; import com.viaversion.viabackwards.api.rewriters.EntityRewriter; import com.viaversion.viabackwards.protocol.v1_19_4to1_19_3.Protocol1_19_4To1_19_3; import com.viaversion.viabackwards.protocol.v1_19_4to1_19_3.storage.LinkedEntityStorage; import com.viaversion.viabackwards.protocol.v1_19_4to1_19_3.storage.EntityTracker1_19_4; +import com.viaversion.viaversion.api.data.entity.StoredEntityData; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_3; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_19_3; import com.viaversion.viaversion.api.type.types.version.Types1_19_4; import com.viaversion.viaversion.libs.gson.JsonElement; +import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.packet.ClientboundPackets1_19_3; import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPackets1_19_4; import com.viaversion.viaversion.util.TagUtil; @@ -48,10 +52,40 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter { + final int entityId = wrapper.get(Types.VAR_INT, 0); + final int entityType = wrapper.get(Types.VAR_INT, 1); + + // First track (and remap) entity, then put storage for block display entity + getSpawnTrackerWithDataHandler1_19(EntityTypes1_19_4.FALLING_BLOCK).handle(wrapper); + if (entityType != EntityTypes1_19_4.BLOCK_DISPLAY.getId()) { + return; + } + + final StoredEntityData data = tracker(wrapper.user()).entityData(entityId); + if (data != null) { + data.put(new LinkedEntityStorage()); + } + }); + } + }); + protocol.registerClientbound(ClientboundPackets1_19_4.LOGIN, new PacketHandlers() { @Override public void register() { @@ -142,6 +176,40 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter { + final int entityId = wrapper.passthrough(Types.VAR_INT); + final double x = wrapper.passthrough(Types.DOUBLE); + final double y = wrapper.passthrough(Types.DOUBLE); + final double z = wrapper.passthrough(Types.DOUBLE); + + final EntityTracker1_19_4 tracker = tracker(wrapper.user()); + final LinkedEntityStorage storage = tracker.linkedEntityStorage(entityId); + if (storage == null) { + return; + } + storage.setCoordinates(x, y, z, false); + }); + + final PacketHandler entityPositionHandler = wrapper -> { + final int entityId = wrapper.passthrough(Types.VAR_INT); + final double x = wrapper.passthrough(Types.SHORT) / EntityPositionHandler.RELATIVE_MOVE_FACTOR; + final double y = wrapper.passthrough(Types.SHORT) / EntityPositionHandler.RELATIVE_MOVE_FACTOR; + final double z = wrapper.passthrough(Types.SHORT) / EntityPositionHandler.RELATIVE_MOVE_FACTOR; + + final EntityTracker1_19_4 tracker = tracker(wrapper.user()); + final LinkedEntityStorage storage = tracker.linkedEntityStorage(entityId); + if (storage == null) { + return; + } + storage.setCoordinates(x, y, z, true); + }; + + protocol.registerClientbound(ClientboundPackets1_19_4.MOVE_ENTITY_POS, entityPositionHandler); + protocol.registerClientbound(ClientboundPackets1_19_4.MOVE_ENTITY_POS_ROT, entityPositionHandler); } @Override @@ -180,10 +248,14 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter