Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 00:00:33 +01:00
Use legacy chunk rewriter functions (#750)
Dieser Commit ist enthalten in:
Ursprung
dd4ab8082e
Commit
f9890db702
@ -22,11 +22,7 @@ import com.viaversion.viaversion.api.minecraft.BlockFace;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
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.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
|
||||
@ -41,17 +37,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);
|
||||
|
@ -20,12 +20,8 @@ package com.viaversion.viabackwards.protocol.v1_15to1_14_4.rewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_15to1_14_4.Protocol1_15To1_14_4;
|
||||
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.minecraft.item.Item;
|
||||
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_14;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_15;
|
||||
@ -89,18 +85,7 @@ public class BlockItemPacketRewriter1_15 extends BackwardsItemRewriter<Clientbou
|
||||
chunk.setBiomeData(newBiomeData);
|
||||
}
|
||||
|
||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < palette.size(); j++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j));
|
||||
palette.setIdByIndex(j, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
blockRewriter.handleChunk(chunk);
|
||||
});
|
||||
|
||||
blockRewriter.registerLevelEvent(ClientboundPackets1_15.LEVEL_EVENT, 1010, 2001);
|
||||
|
@ -21,12 +21,7 @@ import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.Protocol1_16_2To1_16_1;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8;
|
||||
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.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;
|
||||
@ -75,24 +70,8 @@ public class BlockItemPacketRewriter1_16_2 extends BackwardsItemRewriter<Clientb
|
||||
blockRewriter.registerBlockBreakAck(ClientboundPackets1_16_2.BLOCK_BREAK_ACK);
|
||||
blockRewriter.registerBlockEvent(ClientboundPackets1_16_2.BLOCK_EVENT);
|
||||
blockRewriter.registerBlockUpdate(ClientboundPackets1_16_2.BLOCK_UPDATE);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_16_2.LEVEL_CHUNK, wrapper -> {
|
||||
Chunk chunk = wrapper.read(ChunkType1_16_2.TYPE);
|
||||
wrapper.write(ChunkType1_16.TYPE, chunk);
|
||||
|
||||
blockRewriter.registerLevelChunk(ClientboundPackets1_16_2.LEVEL_CHUNK, ChunkType1_16_2.TYPE, ChunkType1_16.TYPE, (connection, chunk) -> {
|
||||
chunk.setIgnoreOldLightData(true);
|
||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < palette.size(); j++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j));
|
||||
palette.setIdByIndex(j, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
|
||||
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
|
||||
if (blockEntity != null) {
|
||||
|
@ -17,7 +17,6 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.v1_16to1_15_2.rewriter;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.MapColorRewriter;
|
||||
@ -25,10 +24,6 @@ import com.viaversion.viabackwards.protocol.v1_16to1_15_2.Protocol1_16To1_15_2;
|
||||
import com.viaversion.viabackwards.protocol.v1_16to1_15_2.data.MapColorMappings1_15_2;
|
||||
import com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.storage.BiomeStorage;
|
||||
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.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
@ -105,6 +100,45 @@ public class BlockItemPacketRewriter1_16 extends BackwardsItemRewriter<Clientbou
|
||||
blockRewriter.registerBlockEvent(ClientboundPackets1_16.BLOCK_EVENT);
|
||||
blockRewriter.registerBlockUpdate(ClientboundPackets1_16.BLOCK_UPDATE);
|
||||
blockRewriter.registerChunkBlocksUpdate(ClientboundPackets1_16.CHUNK_BLOCKS_UPDATE);
|
||||
blockRewriter.registerLevelChunk(ClientboundPackets1_16.LEVEL_CHUNK, ChunkType1_16.TYPE, ChunkType1_15.TYPE, (connection, chunk) -> {
|
||||
CompoundTag heightMaps = chunk.getHeightMap();
|
||||
for (Tag heightMapTag : heightMaps.values()) {
|
||||
if (!(heightMapTag instanceof LongArrayTag heightMap)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int[] heightMapData = new int[256];
|
||||
CompactArrayUtil.iterateCompactArrayWithPadding(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
|
||||
heightMap.setValue(CompactArrayUtil.createCompactArray(9, heightMapData.length, i -> heightMapData[i]));
|
||||
}
|
||||
|
||||
if (chunk.isBiomeData()) {
|
||||
if (connection.getProtocolInfo().serverProtocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_16_2)) {
|
||||
BiomeStorage biomeStorage = connection.get(BiomeStorage.class);
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
int biome = chunk.getBiomeData()[i];
|
||||
int legacyBiome = biomeStorage.legacyBiome(biome);
|
||||
if (legacyBiome == -1) {
|
||||
protocol.getLogger().warning("Biome sent that does not exist in the biome registry: " + biome);
|
||||
legacyBiome = 1;
|
||||
}
|
||||
chunk.getBiomeData()[i] = legacyBiome;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
int biome = chunk.getBiomeData()[i];
|
||||
switch (biome) {
|
||||
case 170, 171, 172, 173 -> chunk.getBiomeData()[i] = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chunk.getBlockEntities() == null) return;
|
||||
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
|
||||
handleBlockEntity(blockEntity);
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_16.SET_EQUIPMENT, ClientboundPackets1_15.SET_EQUIPPED_ITEM, wrapper -> {
|
||||
int entityId = wrapper.passthrough(Types.VAR_INT);
|
||||
@ -143,62 +177,6 @@ public class BlockItemPacketRewriter1_16 extends BackwardsItemRewriter<Clientbou
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_16.LEVEL_CHUNK, wrapper -> {
|
||||
Chunk chunk = wrapper.read(ChunkType1_16.TYPE);
|
||||
wrapper.write(ChunkType1_15.TYPE, chunk);
|
||||
|
||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < palette.size(); j++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j));
|
||||
palette.setIdByIndex(j, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
|
||||
CompoundTag heightMaps = chunk.getHeightMap();
|
||||
for (Tag heightMapTag : heightMaps.values()) {
|
||||
if (!(heightMapTag instanceof LongArrayTag heightMap)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int[] heightMapData = new int[256];
|
||||
CompactArrayUtil.iterateCompactArrayWithPadding(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
|
||||
heightMap.setValue(CompactArrayUtil.createCompactArray(9, heightMapData.length, i -> heightMapData[i]));
|
||||
}
|
||||
|
||||
if (chunk.isBiomeData()) {
|
||||
if (wrapper.user().getProtocolInfo().serverProtocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_16_2)) {
|
||||
BiomeStorage biomeStorage = wrapper.user().get(BiomeStorage.class);
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
int biome = chunk.getBiomeData()[i];
|
||||
int legacyBiome = biomeStorage.legacyBiome(biome);
|
||||
if (legacyBiome == -1) {
|
||||
protocol.getLogger().warning("Biome sent that does not exist in the biome registry: " + biome);
|
||||
legacyBiome = 1;
|
||||
}
|
||||
chunk.getBiomeData()[i] = legacyBiome;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
int biome = chunk.getBiomeData()[i];
|
||||
switch (biome) {
|
||||
case 170, 171, 172, 173 -> chunk.getBiomeData()[i] = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chunk.getBlockEntities() == null) return;
|
||||
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
|
||||
handleBlockEntity(blockEntity);
|
||||
}
|
||||
});
|
||||
|
||||
blockRewriter.registerLevelEvent(ClientboundPackets1_16.LEVEL_EVENT, 1010, 2001);
|
||||
|
||||
registerLevelParticles(ClientboundPackets1_16.LEVEL_PARTICLES, Types.DOUBLE);
|
||||
|
@ -28,8 +28,6 @@ import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
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.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
@ -350,18 +348,7 @@ public final class BlockItemPacketRewriter1_17 extends BackwardsItemRewriter<Cli
|
||||
heightMap.setValue(CompactArrayUtil.createCompactArrayWithPadding(9, heightMapData.length, i -> heightMapData[i]));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ChunkSection section = sections[i];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DataPalette palette = section.palette(PaletteType.BLOCKS);
|
||||
for (int j = 0; j < palette.size(); j++) {
|
||||
int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j));
|
||||
palette.setIdByIndex(j, mappedBlockStateId);
|
||||
}
|
||||
}
|
||||
blockRewriter.handleChunk(chunk);
|
||||
|
||||
chunk.getBlockEntities().removeIf(compound -> {
|
||||
NumberTag tag = compound.getNumberTag("y");
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren