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_16to1_15_2.packets;
|
2020-02-05 20:09:06 +01:00
|
|
|
|
2020-03-20 19:20:48 +01:00
|
|
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|
|
|
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
2020-04-22 21:42:11 +02:00
|
|
|
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
|
2020-03-20 19:20:48 +01:00
|
|
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
|
|
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
2022-10-16 21:22:48 +02:00
|
|
|
import com.google.gson.JsonElement;
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.api.minecraft.Position;
|
|
|
|
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-26 21:16:10 +02:00
|
|
|
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.api.type.types.UUIDIntArrayType;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type;
|
2021-04-27 13:41:39 +02:00
|
|
|
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.util.CompactArrayUtil;
|
2020-02-05 20:09:06 +01:00
|
|
|
|
2021-03-14 16:57:37 +01:00
|
|
|
import java.util.Map;
|
2020-03-20 19:20:48 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2020-02-05 20:09:06 +01:00
|
|
|
public class WorldPackets {
|
|
|
|
|
2020-08-16 16:24:06 +02:00
|
|
|
public static void register(Protocol1_16To1_15_2 protocol) {
|
2023-02-04 18:29:22 +01:00
|
|
|
BlockRewriter<ClientboundPackets1_15> blockRewriter = new BlockRewriter<>(protocol, Type.POSITION1_14);
|
2020-02-05 20:09:06 +01:00
|
|
|
|
2020-06-05 20:30:09 +02:00
|
|
|
blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION);
|
|
|
|
blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE);
|
|
|
|
blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE);
|
|
|
|
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING);
|
2020-02-05 20:09:06 +01:00
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
protocol.registerClientbound(ClientboundPackets1_15.UPDATE_LIGHT, new PacketRemapper() {
|
2020-06-10 19:34:22 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
map(Type.VAR_INT); // x
|
|
|
|
map(Type.VAR_INT); // y
|
|
|
|
handler(wrapper -> wrapper.write(Type.BOOLEAN, true)); // Take neighbour's light into account as well
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
protocol.registerClientbound(ClientboundPackets1_15.CHUNK_DATA, new PacketRemapper() {
|
2020-02-05 20:09:06 +01:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
handler(wrapper -> {
|
2020-08-10 21:22:01 +02:00
|
|
|
Chunk chunk = wrapper.read(new Chunk1_15Type());
|
|
|
|
wrapper.write(new Chunk1_16Type(), chunk);
|
2020-06-16 18:38:16 +02:00
|
|
|
|
|
|
|
chunk.setIgnoreOldLightData(chunk.isFullChunk());
|
|
|
|
|
2021-01-05 09:42:32 +01:00
|
|
|
for (int s = 0; s < chunk.getSections().length; s++) {
|
2020-02-05 20:09:06 +01: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);
|
2020-02-05 20:09:06 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-20 19:20:48 +01:00
|
|
|
|
2020-04-22 21:46:14 +02:00
|
|
|
CompoundTag heightMaps = chunk.getHeightMap();
|
2021-03-14 16:57:37 +01:00
|
|
|
for (Tag heightMapTag : heightMaps.values()) {
|
2020-04-22 21:47:14 +02:00
|
|
|
LongArrayTag heightMap = (LongArrayTag) heightMapTag;
|
2020-04-22 21:46:14 +02:00
|
|
|
int[] heightMapData = new int[256];
|
|
|
|
CompactArrayUtil.iterateCompactArray(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
|
|
|
|
heightMap.setValue(CompactArrayUtil.createCompactArrayWithPadding(9, heightMapData.length, i -> heightMapData[i]));
|
|
|
|
}
|
|
|
|
|
2020-03-20 19:20:48 +01:00
|
|
|
if (chunk.getBlockEntities() == null) return;
|
|
|
|
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
|
2022-10-16 21:22:48 +02:00
|
|
|
handleBlockEntity(protocol, blockEntity);
|
2020-03-20 19:20:48 +01:00
|
|
|
}
|
2020-02-05 20:09:06 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
protocol.registerClientbound(ClientboundPackets1_15.BLOCK_ENTITY_DATA, new PacketRemapper() {
|
2020-06-25 11:18:07 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
handler(wrapper -> {
|
|
|
|
Position position = wrapper.passthrough(Type.POSITION1_14);
|
|
|
|
short action = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
|
|
|
CompoundTag tag = wrapper.passthrough(Type.NBT);
|
2022-10-16 21:22:48 +02:00
|
|
|
handleBlockEntity(protocol, tag);
|
2020-06-25 11:18:07 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-08-16 16:24:06 +02:00
|
|
|
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
|
2020-02-06 12:37:57 +01:00
|
|
|
}
|
|
|
|
|
2022-10-16 21:22:48 +02:00
|
|
|
private static void handleBlockEntity(Protocol1_16To1_15_2 protocol, CompoundTag compoundTag) {
|
2020-06-25 11:18:07 +02:00
|
|
|
StringTag idTag = compoundTag.get("id");
|
|
|
|
if (idTag == null) return;
|
|
|
|
|
|
|
|
String id = idTag.getValue();
|
|
|
|
if (id.equals("minecraft:conduit")) {
|
2020-06-25 12:52:59 +02:00
|
|
|
Tag targetUuidTag = compoundTag.remove("target_uuid");
|
|
|
|
if (!(targetUuidTag instanceof StringTag)) return;
|
2020-06-25 11:18:07 +02:00
|
|
|
|
|
|
|
// target_uuid -> Target
|
2020-06-25 12:52:59 +02:00
|
|
|
UUID targetUuid = UUID.fromString((String) targetUuidTag.getValue());
|
2021-03-14 16:57:37 +01:00
|
|
|
compoundTag.put("Target", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(targetUuid)));
|
2020-06-25 11:18:07 +02:00
|
|
|
} else if (id.equals("minecraft:skull") && compoundTag.get("Owner") instanceof CompoundTag) {
|
|
|
|
CompoundTag ownerTag = compoundTag.remove("Owner");
|
|
|
|
StringTag ownerUuidTag = ownerTag.remove("Id");
|
|
|
|
if (ownerUuidTag != null) {
|
|
|
|
UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue());
|
2021-03-14 16:57:37 +01:00
|
|
|
ownerTag.put("Id", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(ownerUuid)));
|
2020-06-25 11:18:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Owner -> SkullOwner
|
2021-03-14 16:57:37 +01:00
|
|
|
CompoundTag skullOwnerTag = new CompoundTag();
|
|
|
|
for (Map.Entry<String, Tag> entry : ownerTag.entrySet()) {
|
|
|
|
skullOwnerTag.put(entry.getKey(), entry.getValue());
|
2020-06-25 11:18:07 +02:00
|
|
|
}
|
2021-03-14 16:57:37 +01:00
|
|
|
compoundTag.put("SkullOwner", skullOwnerTag);
|
2022-10-16 21:22:48 +02:00
|
|
|
} else if (id.equals("minecraft:sign")) {
|
|
|
|
for (int i = 1; i <= 4; i++) {
|
|
|
|
Tag line = compoundTag.get("Text" + i);
|
|
|
|
if (line instanceof StringTag) {
|
|
|
|
JsonElement text = protocol.getComponentRewriter().processText(((StringTag) line).getValue());
|
|
|
|
compoundTag.put("Text" + i, new StringTag(text.toString()));
|
|
|
|
}
|
|
|
|
}
|
2022-11-20 12:31:01 +01:00
|
|
|
} else if (id.equals("minecraft:mob_spawner")) {
|
|
|
|
Tag spawnDataTag = compoundTag.get("SpawnData");
|
|
|
|
if (spawnDataTag instanceof CompoundTag) {
|
|
|
|
Tag spawnDataIdTag = ((CompoundTag) spawnDataTag).get("id");
|
|
|
|
if (spawnDataIdTag instanceof StringTag) {
|
|
|
|
StringTag spawnDataIdStringTag = ((StringTag) spawnDataIdTag);
|
|
|
|
if (spawnDataIdStringTag.getValue().equals("minecraft:zombie_pigman")) {
|
|
|
|
spawnDataIdStringTag.setValue("minecraft:zombified_piglin");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-25 11:18:07 +02:00
|
|
|
}
|
|
|
|
}
|
2020-02-05 20:09:06 +01:00
|
|
|
}
|