|
21 | 21 | import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter; |
22 | 22 | import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter; |
23 | 23 | import com.viaversion.viabackwards.protocol.v1_19to1_18_2.Protocol1_19To1_18_2; |
| 24 | +import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.BlockAckStorage; |
24 | 25 | import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.LastDeathPosition; |
25 | 26 | import com.viaversion.viaversion.api.connection.UserConnection; |
26 | 27 | import com.viaversion.viaversion.api.data.ParticleMappings; |
27 | 28 | import com.viaversion.viaversion.api.data.entity.EntityTracker; |
| 29 | +import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; |
| 30 | +import com.viaversion.viaversion.api.minecraft.BlockPosition; |
28 | 31 | import com.viaversion.viaversion.api.minecraft.GlobalBlockPosition; |
29 | 32 | import com.viaversion.viaversion.api.minecraft.chunks.Chunk; |
30 | 33 | import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; |
|
36 | 39 | import com.viaversion.viaversion.api.type.Types; |
37 | 40 | import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18; |
38 | 41 | import com.viaversion.viaversion.protocols.v1_16_4to1_17.packet.ServerboundPackets1_17; |
| 42 | +import com.viaversion.viaversion.protocols.v1_17_1to1_18.packet.ClientboundPackets1_18; |
39 | 43 | import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ClientboundPackets1_19; |
40 | 44 | import com.viaversion.viaversion.rewriter.RecipeRewriter; |
41 | 45 | import com.viaversion.viaversion.util.MathUtil; |
@@ -84,14 +88,88 @@ public void register() { |
84 | 88 | } |
85 | 89 | }); |
86 | 90 |
|
87 | | - protocol.registerClientbound(ClientboundPackets1_19.BLOCK_CHANGED_ACK, null, new PacketHandlers() { |
| 91 | + protocol.registerClientbound(ClientboundPackets1_19.BLOCK_CHANGED_ACK, ClientboundPackets1_18.BLOCK_UPDATE, new PacketHandlers() { |
88 | 92 | @Override |
89 | 93 | public void register() { |
90 | | - read(Types.VAR_INT); // Sequence |
91 | | - handler(PacketWrapper::cancel); // This is fine:tm: |
| 94 | + handler(wrapper -> { |
| 95 | + final BlockAckStorage blockAckStorage = wrapper.user().get(BlockAckStorage.class); |
| 96 | + final int sequence = wrapper.read(Types.VAR_INT); |
| 97 | + final BlockPosition pos = blockAckStorage.remove(sequence); |
| 98 | + if (pos == null) { |
| 99 | + wrapper.cancel(); |
| 100 | + return; |
| 101 | + } |
| 102 | + |
| 103 | + final int minSectionY = protocol.getEntityRewriter().tracker(wrapper.user()).currentMinY() >> 4; |
| 104 | + final int blockState = blockAckStorage.getBlockStateAt(pos, minSectionY); |
| 105 | + if (blockState < 0) { |
| 106 | + wrapper.cancel(); |
| 107 | + return; |
| 108 | + } |
| 109 | + |
| 110 | + wrapper.write(Types.BLOCK_POSITION1_14, pos); |
| 111 | + wrapper.write(Types.VAR_INT, blockState); |
| 112 | + }); |
| 113 | + } |
| 114 | + }); |
| 115 | + |
| 116 | + protocol.replaceClientbound(ClientboundPackets1_19.BLOCK_UPDATE, new PacketHandlers() { |
| 117 | + @Override |
| 118 | + public void register() { |
| 119 | + handler(wrapper -> { |
| 120 | + final BlockAckStorage blockAckStorage = wrapper.user().get(BlockAckStorage.class); |
| 121 | + final BlockPosition pos = wrapper.passthrough(Types.BLOCK_POSITION1_14); |
| 122 | + final int blockId = wrapper.read(Types.VAR_INT); |
| 123 | + final int mappedId = protocol.getMappingData().getNewBlockStateId(blockId); |
| 124 | + wrapper.write(Types.VAR_INT, mappedId); |
| 125 | + final int minSectionY = protocol.getEntityRewriter().tracker(wrapper.user()).currentMinY() >> 4; |
| 126 | + blockAckStorage.updateBlockState(pos.x(), pos.y(), pos.z(), minSectionY, mappedId); |
| 127 | + }); |
| 128 | + } |
| 129 | + }); |
| 130 | + |
| 131 | + protocol.replaceClientbound(ClientboundPackets1_19.SECTION_BLOCKS_UPDATE, new PacketHandlers() { |
| 132 | + @Override |
| 133 | + public void register() { |
| 134 | + handler(wrapper -> { |
| 135 | + final long sectionPos = wrapper.passthrough(Types.LONG); |
| 136 | + wrapper.passthrough(Types.BOOLEAN); // Suppress light updates |
| 137 | + |
| 138 | + final int sectionY = (int) ((sectionPos << 44) >> 44); |
| 139 | + final int chunkZ = (int) ((sectionPos << 22) >> 42); |
| 140 | + final int chunkX = (int) (sectionPos >> 42); |
| 141 | + |
| 142 | + final int minSectionY = protocol.getEntityRewriter().tracker(wrapper.user()).currentMinY() >> 4; |
| 143 | + final BlockAckStorage blockAckStorage = wrapper.user().get(BlockAckStorage.class); |
| 144 | + for (final BlockChangeRecord record : wrapper.passthrough(Types.VAR_LONG_BLOCK_CHANGE_ARRAY)) { |
| 145 | + final int mappedId = protocol.getMappingData().getNewBlockStateId(record.getBlockId()); |
| 146 | + record.setBlockId(mappedId); |
| 147 | + blockAckStorage.updateBlockState( |
| 148 | + (chunkX << 4) | record.getSectionX(), |
| 149 | + (sectionY << 4) + record.getSectionY(), |
| 150 | + (chunkZ << 4) | record.getSectionZ(), |
| 151 | + minSectionY, |
| 152 | + mappedId |
| 153 | + ); |
| 154 | + } |
| 155 | + }); |
92 | 156 | } |
93 | 157 | }); |
94 | 158 |
|
| 159 | + protocol.replaceClientbound(ClientboundPackets1_19.LEVEL_CHUNK_WITH_LIGHT, wrapper -> { |
| 160 | + final BlockAckStorage blockAckStorage = wrapper.user().get(BlockAckStorage.class); |
| 161 | + final Chunk chunk = protocol.getBlockRewriter().handleChunk1_18(wrapper); |
| 162 | + protocol.getBlockRewriter().handleBlockEntities(chunk, wrapper.user()); |
| 163 | + blockAckStorage.cacheChunk(chunk.getX(), chunk.getZ(), chunk.getSections()); |
| 164 | + }); |
| 165 | + |
| 166 | + protocol.registerClientbound(ClientboundPackets1_19.FORGET_LEVEL_CHUNK, wrapper -> { |
| 167 | + final BlockAckStorage blockAckStorage = wrapper.user().get(BlockAckStorage.class); |
| 168 | + final int chunkX = wrapper.passthrough(Types.INT); |
| 169 | + final int chunkZ = wrapper.passthrough(Types.INT); |
| 170 | + blockAckStorage.forgetChunk(chunkX, chunkZ); |
| 171 | + }); |
| 172 | + |
95 | 173 | protocol.replaceClientbound(ClientboundPackets1_19.LEVEL_PARTICLES, new PacketHandlers() { |
96 | 174 | @Override |
97 | 175 | public void register() { |
@@ -126,34 +204,46 @@ public void register() { |
126 | 204 | } |
127 | 205 | }); |
128 | 206 |
|
129 | | - // The server does nothing but track the sequence, so we can just set it as 0 |
130 | 207 | protocol.registerServerbound(ServerboundPackets1_17.PLAYER_ACTION, new PacketHandlers() { |
131 | 208 | @Override |
132 | 209 | public void register() { |
133 | | - map(Types.VAR_INT); // Action |
134 | | - map(Types.BLOCK_POSITION1_14); // Block position |
135 | | - map(Types.UNSIGNED_BYTE); // Direction |
136 | | - create(Types.VAR_INT, 0); // Sequence |
| 210 | + handler(wrapper -> { |
| 211 | + final BlockAckStorage blockAckStorage = wrapper.user().get(BlockAckStorage.class); |
| 212 | + final int action = wrapper.passthrough(Types.VAR_INT); |
| 213 | + final BlockPosition pos = wrapper.passthrough(Types.BLOCK_POSITION1_14); |
| 214 | + wrapper.passthrough(Types.UNSIGNED_BYTE); // Direction |
| 215 | + final int sequence = blockAckStorage.nextSequence(); |
| 216 | + wrapper.write(Types.VAR_INT, sequence); // Sequence |
| 217 | + if (action < 3) { |
| 218 | + blockAckStorage.add(sequence, pos); |
| 219 | + } |
| 220 | + }); |
137 | 221 | } |
138 | 222 | }); |
139 | 223 | protocol.registerServerbound(ServerboundPackets1_17.USE_ITEM_ON, new PacketHandlers() { |
140 | 224 | @Override |
141 | 225 | public void register() { |
142 | | - map(Types.VAR_INT); // Hand |
143 | | - map(Types.BLOCK_POSITION1_14); // Block position |
144 | | - map(Types.VAR_INT); // Direction |
145 | | - map(Types.FLOAT); // X |
146 | | - map(Types.FLOAT); // Y |
147 | | - map(Types.FLOAT); // Z |
148 | | - map(Types.BOOLEAN); // Inside |
149 | | - create(Types.VAR_INT, 0); // Sequence |
| 226 | + handler(wrapper -> { |
| 227 | + final BlockAckStorage blockAckStorage = wrapper.user().get(BlockAckStorage.class); |
| 228 | + wrapper.passthrough(Types.VAR_INT); // Hand |
| 229 | + wrapper.passthrough(Types.BLOCK_POSITION1_14); // Block position |
| 230 | + wrapper.passthrough(Types.VAR_INT); // Direction |
| 231 | + wrapper.passthrough(Types.FLOAT); // X |
| 232 | + wrapper.passthrough(Types.FLOAT); // Y |
| 233 | + wrapper.passthrough(Types.FLOAT); // Z |
| 234 | + wrapper.passthrough(Types.BOOLEAN); // Inside |
| 235 | + wrapper.write(Types.VAR_INT, blockAckStorage.nextSequence()); // Sequence |
| 236 | + }); |
150 | 237 | } |
151 | 238 | }); |
152 | 239 | protocol.registerServerbound(ServerboundPackets1_17.USE_ITEM, new PacketHandlers() { |
153 | 240 | @Override |
154 | 241 | public void register() { |
155 | | - map(Types.VAR_INT); // Hand |
156 | | - create(Types.VAR_INT, 0); // Sequence |
| 242 | + handler(wrapper -> { |
| 243 | + final BlockAckStorage blockAckStorage = wrapper.user().get(BlockAckStorage.class); |
| 244 | + wrapper.passthrough(Types.VAR_INT); // Hand |
| 245 | + wrapper.write(Types.VAR_INT, blockAckStorage.nextSequence()); // Sequence |
| 246 | + }); |
157 | 247 | } |
158 | 248 | }); |
159 | 249 |
|
|
0 commit comments