Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-20 06:50:08 +01:00
Add rewriter function for legacy chunk types to BlockRewriter (#3854)
Dieser Commit ist enthalten in:
Ursprung
b3d02491c6
Commit
1399c901d2
@ -38,17 +38,7 @@ public class WorldPacketRewriter1_13_1 {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
Chunk chunk = wrapper.passthrough(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()));
|
||||
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(i));
|
||||
palette.setIdByIndex(i, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
blockRewriter.handleChunk(chunk);
|
||||
});
|
||||
|
||||
blockRewriter.registerBlockEvent(ClientboundPackets1_13.BLOCK_EVENT);
|
||||
|
@ -17,10 +17,6 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_14;
|
||||
@ -38,11 +34,7 @@ public final class WorldPacketRewriter1_15 {
|
||||
blockRewriter.registerBlockUpdate(ClientboundPackets1_14_4.BLOCK_UPDATE);
|
||||
blockRewriter.registerChunkBlocksUpdate(ClientboundPackets1_14_4.CHUNK_BLOCKS_UPDATE);
|
||||
blockRewriter.registerBlockBreakAck(ClientboundPackets1_14_4.BLOCK_BREAK_ACK);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_14_4.LEVEL_CHUNK, wrapper -> {
|
||||
Chunk chunk = wrapper.read(ChunkType1_14.TYPE);
|
||||
wrapper.write(ChunkType1_15.TYPE, chunk);
|
||||
|
||||
blockRewriter.registerLevelChunk(ClientboundPackets1_14_4.LEVEL_CHUNK, ChunkType1_14.TYPE, ChunkType1_15.TYPE, (connection, chunk) -> {
|
||||
if (chunk.isFullChunk()) {
|
||||
int[] biomeData = chunk.getBiomeData();
|
||||
int[] newBiomeData = new int[1024];
|
||||
@ -64,19 +56,6 @@ public final class WorldPacketRewriter1_15 {
|
||||
|
||||
chunk.setBiomeData(newBiomeData);
|
||||
}
|
||||
|
||||
for (int s = 0; s < chunk.getSections().length; s++) {
|
||||
ChunkSection section = chunk.getSections()[s];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(i));
|
||||
palette.setIdByIndex(i, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
blockRewriter.registerLevelEvent(ClientboundPackets1_14_4.LEVEL_EVENT, 1010, 2001);
|
||||
|
@ -24,10 +24,6 @@ import com.viaversion.nbt.tag.LongArrayTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_15;
|
||||
@ -50,35 +46,9 @@ public class WorldPacketRewriter1_16 {
|
||||
blockRewriter.registerBlockUpdate(ClientboundPackets1_15.BLOCK_UPDATE);
|
||||
blockRewriter.registerChunkBlocksUpdate(ClientboundPackets1_15.CHUNK_BLOCKS_UPDATE);
|
||||
blockRewriter.registerBlockBreakAck(ClientboundPackets1_15.BLOCK_BREAK_ACK);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_15.LIGHT_UPDATE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // x
|
||||
map(Types.VAR_INT); // y
|
||||
handler(wrapper -> wrapper.write(Types.BOOLEAN, true)); // Take neighbour's light into account as well
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_15.LEVEL_CHUNK, wrapper -> {
|
||||
Chunk chunk = wrapper.read(ChunkType1_15.TYPE);
|
||||
wrapper.write(ChunkType1_16.TYPE, chunk);
|
||||
|
||||
blockRewriter.registerLevelChunk(ClientboundPackets1_15.LEVEL_CHUNK, ChunkType1_15.TYPE, ChunkType1_16.TYPE, (connection, chunk) -> {
|
||||
chunk.setIgnoreOldLightData(chunk.isFullChunk());
|
||||
|
||||
for (int s = 0; s < chunk.getSections().length; s++) {
|
||||
ChunkSection section = chunk.getSections()[s];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(i));
|
||||
palette.setIdByIndex(i, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
|
||||
CompoundTag heightMaps = chunk.getHeightMap();
|
||||
for (Tag heightMapTag : heightMaps.values()) {
|
||||
LongArrayTag heightMap = (LongArrayTag) heightMapTag;
|
||||
@ -89,7 +59,16 @@ public class WorldPacketRewriter1_16 {
|
||||
|
||||
if (chunk.getBlockEntities() == null) return;
|
||||
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
|
||||
handleBlockEntity(protocol, wrapper.user(), blockEntity);
|
||||
handleBlockEntity(protocol, connection, blockEntity);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_15.LIGHT_UPDATE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Types.VAR_INT); // x
|
||||
map(Types.VAR_INT); // y
|
||||
handler(wrapper -> wrapper.write(Types.BOOLEAN, true)); // Take neighbour's light into account as well
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -19,12 +19,7 @@ package com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_16_2;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16_2;
|
||||
@ -45,24 +40,7 @@ public class WorldPacketRewriter1_16_2 {
|
||||
blockRewriter.registerBlockEvent(ClientboundPackets1_16.BLOCK_EVENT);
|
||||
blockRewriter.registerBlockUpdate(ClientboundPackets1_16.BLOCK_UPDATE);
|
||||
blockRewriter.registerBlockBreakAck(ClientboundPackets1_16.BLOCK_BREAK_ACK);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_16.LEVEL_CHUNK, wrapper -> {
|
||||
Chunk chunk = wrapper.read(ChunkType1_16.TYPE);
|
||||
wrapper.write(ChunkType1_16_2.TYPE, chunk);
|
||||
|
||||
for (int s = 0; s < chunk.getSections().length; s++) {
|
||||
ChunkSection section = chunk.getSections()[s];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(i));
|
||||
palette.setIdByIndex(i, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
});
|
||||
blockRewriter.registerLevelChunk(ClientboundPackets1_16.LEVEL_CHUNK, ChunkType1_16.TYPE, ChunkType1_16_2.TYPE);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_16.CHUNK_BLOCKS_UPDATE, ClientboundPackets1_16_2.SECTION_BLOCKS_UPDATE, wrapper -> {
|
||||
wrapper.cancel();
|
||||
|
@ -125,18 +125,8 @@ public final class WorldPacketRewriter1_17 {
|
||||
// 1.17 uses a bitset for the mask
|
||||
chunk.setChunkMask(BitSet.valueOf(new long[]{chunk.getBitmask()}));
|
||||
|
||||
for (int s = 0; s < chunk.getSections().length; s++) {
|
||||
ChunkSection section = chunk.getSections()[s];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(i));
|
||||
palette.setIdByIndex(i, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
// Rewrite block state ids
|
||||
blockRewriter.handleChunk(chunk);
|
||||
});
|
||||
|
||||
blockRewriter.registerLevelEvent(ClientboundPackets1_16_2.LEVEL_EVENT, 1010, 2001);
|
||||
|
@ -17,19 +17,12 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.v1_18_2to1_19.rewriter;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
|
||||
import com.viaversion.viaversion.protocols.v1_17_1to1_18.packet.ClientboundPackets1_18;
|
||||
import com.viaversion.viaversion.protocols.v1_18_2to1_19.Protocol1_18_2To1_19;
|
||||
import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ServerboundPackets1_19;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.util.MathUtil;
|
||||
|
||||
public final class WorldPacketRewriter1_19 {
|
||||
|
||||
@ -39,26 +32,10 @@ public final class WorldPacketRewriter1_19 {
|
||||
blockRewriter.registerBlockUpdate(ClientboundPackets1_18.BLOCK_UPDATE);
|
||||
blockRewriter.registerSectionBlocksUpdate(ClientboundPackets1_18.SECTION_BLOCKS_UPDATE);
|
||||
blockRewriter.registerLevelEvent(ClientboundPackets1_18.LEVEL_EVENT, 1010, 2001);
|
||||
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_18.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_18::new);
|
||||
|
||||
protocol.cancelClientbound(ClientboundPackets1_18.BLOCK_BREAK_ACK);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_18.LEVEL_CHUNK_WITH_LIGHT, wrapper -> {
|
||||
final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
|
||||
Preconditions.checkArgument(tracker.biomesSent() != -1, "Biome count not set");
|
||||
Preconditions.checkArgument(tracker.currentWorldSectionHeight() != -1, "Section height not set");
|
||||
final ChunkType1_18 chunkType = new ChunkType1_18(tracker.currentWorldSectionHeight(),
|
||||
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()),
|
||||
MathUtil.ceilLog2(tracker.biomesSent()));
|
||||
final Chunk chunk = wrapper.passthrough(chunkType);
|
||||
for (final ChunkSection section : chunk.getSections()) {
|
||||
final DataPalette blockPalette = section.palette(PaletteType.BLOCKS);
|
||||
for (int i = 0; i < blockPalette.size(); i++) {
|
||||
final int id = blockPalette.idByIndex(i);
|
||||
blockPalette.setIdByIndex(i, protocol.getMappingData().getNewBlockStateId(id));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_19.SET_BEACON, wrapper -> {
|
||||
// Primary effect
|
||||
if (wrapper.read(Types.BOOLEAN)) {
|
||||
|
@ -20,7 +20,6 @@ package com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
@ -29,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
|
||||
|
@ -173,6 +173,37 @@ public class BlockRewriter<C extends ClientboundPacketType> {
|
||||
});
|
||||
}
|
||||
|
||||
public void registerLevelChunk(C packetType, Type<Chunk> chunkType, Type<Chunk> newChunkType) {
|
||||
registerLevelChunk(packetType, chunkType, newChunkType, null);
|
||||
}
|
||||
|
||||
public void registerLevelChunk(C packetType, Type<Chunk> chunkType, Type<Chunk> newChunkType, @Nullable BiConsumer<UserConnection, Chunk> chunkRewriter) {
|
||||
protocol.registerClientbound(packetType, wrapper -> {
|
||||
Chunk chunk = wrapper.read(chunkType);
|
||||
wrapper.write(newChunkType, chunk);
|
||||
|
||||
handleChunk(chunk);
|
||||
if (chunkRewriter != null) {
|
||||
chunkRewriter.accept(wrapper.user(), chunk);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleChunk(Chunk chunk) {
|
||||
for (int s = 0; s < chunk.getSections().length; s++) {
|
||||
ChunkSection section = chunk.getSections()[s];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(i));
|
||||
palette.setIdByIndex(i, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerLevelChunk1_19(C packetType, ChunkTypeSupplier chunkTypeSupplier) {
|
||||
registerLevelChunk1_19(packetType, chunkTypeSupplier, null);
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren