2021-03-22 23:06:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
2023-01-12 12:45:53 +01:00
|
|
|
* Copyright (C) 2016-2023 ViaVersion and contributors
|
2021-03-22 23:06:40 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-04-26 20:52:34 +02:00
|
|
|
package com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets;
|
2019-08-29 19:56:30 +02:00
|
|
|
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
|
|
|
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
2023-02-04 19:42:26 +01:00
|
|
|
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
|
|
|
import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
|
2021-04-27 13:41:39 +02:00
|
|
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
2021-04-26 21:16:10 +02:00
|
|
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
|
|
|
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.api.type.Type;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type;
|
2021-04-27 13:41:39 +02:00
|
|
|
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
2019-08-29 19:56:30 +02:00
|
|
|
|
|
|
|
public class WorldPackets {
|
|
|
|
|
2020-08-16 16:24:06 +02:00
|
|
|
public static void register(Protocol1_15To1_14_4 protocol) {
|
2023-02-04 18:29:22 +01:00
|
|
|
BlockRewriter<ClientboundPackets1_14> blockRewriter = new BlockRewriter<>(protocol, Type.POSITION1_14);
|
2019-12-11 09:30:51 +01:00
|
|
|
|
2020-06-05 20:30:09 +02:00
|
|
|
blockRewriter.registerBlockAction(ClientboundPackets1_14.BLOCK_ACTION);
|
|
|
|
blockRewriter.registerBlockChange(ClientboundPackets1_14.BLOCK_CHANGE);
|
|
|
|
blockRewriter.registerMultiBlockChange(ClientboundPackets1_14.MULTI_BLOCK_CHANGE);
|
|
|
|
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_14.ACKNOWLEDGE_PLAYER_DIGGING);
|
2019-08-29 19:56:30 +02:00
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
protocol.registerClientbound(ClientboundPackets1_14.CHUNK_DATA, new PacketRemapper() {
|
2019-09-04 17:49:27 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
handler(new PacketHandler() {
|
|
|
|
@Override
|
|
|
|
public void handle(PacketWrapper wrapper) throws Exception {
|
2020-08-10 21:22:01 +02:00
|
|
|
Chunk chunk = wrapper.read(new Chunk1_14Type());
|
|
|
|
wrapper.write(new Chunk1_15Type(), chunk);
|
2019-09-04 17:49:27 +02:00
|
|
|
|
2020-04-04 00:32:00 +02:00
|
|
|
if (chunk.isFullChunk()) {
|
2019-12-02 11:20:48 +01:00
|
|
|
int[] biomeData = chunk.getBiomeData();
|
|
|
|
int[] newBiomeData = new int[1024];
|
2019-12-11 20:36:49 +01:00
|
|
|
if (biomeData != null) {
|
|
|
|
// Now in 4x4x4 areas - take the biome of each "middle"
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
for (int j = 0; j < 4; ++j) {
|
|
|
|
int x = (j << 2) + 2;
|
|
|
|
int z = (i << 2) + 2;
|
|
|
|
int oldIndex = (z << 4 | x);
|
|
|
|
newBiomeData[i << 2 | j] = biomeData[oldIndex];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ... and copy it to the new y layers
|
|
|
|
for (int i = 1; i < 64; ++i) {
|
|
|
|
System.arraycopy(newBiomeData, 0, newBiomeData, i * 16, 16);
|
2019-12-02 11:20:48 +01:00
|
|
|
}
|
2019-12-07 11:31:00 +01:00
|
|
|
}
|
2019-12-02 11:20:48 +01:00
|
|
|
|
|
|
|
chunk.setBiomeData(newBiomeData);
|
|
|
|
}
|
|
|
|
|
2021-01-05 09:42:32 +01:00
|
|
|
for (int s = 0; s < chunk.getSections().length; s++) {
|
2019-09-04 17:49:27 +02:00
|
|
|
ChunkSection section = chunk.getSections()[s];
|
2023-02-04 19:42:26 +01:00
|
|
|
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);
|
2019-09-04 17:49:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-08-16 16:24:06 +02:00
|
|
|
blockRewriter.registerEffect(ClientboundPackets1_14.EFFECT, 1010, 2001);
|
2021-04-28 12:59:37 +02:00
|
|
|
protocol.registerClientbound(ClientboundPackets1_14.SPAWN_PARTICLE, new PacketRemapper() {
|
2019-08-29 19:56:30 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
map(Type.INT); // 0 - Particle ID
|
|
|
|
map(Type.BOOLEAN); // 1 - Long Distance
|
2019-12-03 14:22:54 +01:00
|
|
|
map(Type.FLOAT, Type.DOUBLE); // 2 - X
|
|
|
|
map(Type.FLOAT, Type.DOUBLE); // 3 - Y
|
|
|
|
map(Type.FLOAT, Type.DOUBLE); // 4 - Z
|
2019-08-29 19:56:30 +02:00
|
|
|
map(Type.FLOAT); // 5 - Offset X
|
|
|
|
map(Type.FLOAT); // 6 - Offset Y
|
|
|
|
map(Type.FLOAT); // 7 - Offset Z
|
|
|
|
map(Type.FLOAT); // 8 - Particle Data
|
|
|
|
map(Type.INT); // 9 - Particle Count
|
|
|
|
handler(new PacketHandler() {
|
|
|
|
@Override
|
|
|
|
public void handle(PacketWrapper wrapper) throws Exception {
|
|
|
|
int id = wrapper.get(Type.INT, 0);
|
2019-09-04 17:49:27 +02:00
|
|
|
if (id == 3 || id == 23) {
|
|
|
|
int data = wrapper.passthrough(Type.VAR_INT);
|
2020-08-16 16:24:06 +02:00
|
|
|
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
|
2019-09-04 17:49:27 +02:00
|
|
|
} else if (id == 32) {
|
2021-06-04 12:15:14 +02:00
|
|
|
protocol.getItemRewriter().handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
|
2019-08-29 19:56:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|