2022-01-19 18:05:36 +01:00
|
|
|
/*
|
|
|
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
2024-01-01 12:39:45 +01:00
|
|
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
2022-01-19 18:05:36 +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/>.
|
|
|
|
*/
|
|
|
|
package com.viaversion.viaversion.protocols.protocol1_18_2to1_18;
|
|
|
|
|
2022-02-09 19:12:28 +01:00
|
|
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|
|
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
|
|
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
|
|
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
2022-01-19 18:05:36 +01:00
|
|
|
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
|
|
|
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
2023-02-12 10:54:47 +01:00
|
|
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
2022-02-09 19:12:28 +01:00
|
|
|
import com.viaversion.viaversion.api.type.Type;
|
2022-01-19 18:05:36 +01:00
|
|
|
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
|
|
|
|
import com.viaversion.viaversion.rewriter.TagRewriter;
|
|
|
|
|
|
|
|
public final class Protocol1_18_2To1_18 extends AbstractProtocol<ClientboundPackets1_18, ClientboundPackets1_18, ServerboundPackets1_17, ServerboundPackets1_17> {
|
|
|
|
|
|
|
|
public Protocol1_18_2To1_18() {
|
|
|
|
super(ClientboundPackets1_18.class, ClientboundPackets1_18.class, ServerboundPackets1_17.class, ServerboundPackets1_17.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void registerPackets() {
|
2023-02-04 18:29:22 +01:00
|
|
|
final TagRewriter<ClientboundPackets1_18> tagRewriter = new TagRewriter<>(this);
|
2022-01-19 18:05:36 +01:00
|
|
|
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:fall_damage_resetting");
|
|
|
|
tagRewriter.registerGeneric(ClientboundPackets1_18.TAGS);
|
2022-02-09 19:12:28 +01:00
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_18.ENTITY_EFFECT, new PacketHandlers() {
|
2022-02-18 17:42:26 +01:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2022-02-18 17:42:26 +01:00
|
|
|
map(Type.VAR_INT); // Entity id
|
|
|
|
map(Type.BYTE, Type.VAR_INT); // Effect id
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_18.REMOVE_ENTITY_EFFECT, new PacketHandlers() {
|
2022-02-18 17:42:26 +01:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2022-02-18 17:42:26 +01:00
|
|
|
map(Type.VAR_INT); // Entity id
|
|
|
|
map(Type.BYTE, Type.VAR_INT); // Effect id
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_18.JOIN_GAME, new PacketHandlers() {
|
2022-02-09 19:12:28 +01:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2022-02-09 19:12:28 +01:00
|
|
|
map(Type.INT); // Entity ID
|
|
|
|
map(Type.BOOLEAN); // Hardcore
|
2023-12-03 18:35:19 +01:00
|
|
|
map(Type.BYTE); // Gamemode
|
2022-02-09 19:12:28 +01:00
|
|
|
map(Type.BYTE); // Previous Gamemode
|
|
|
|
map(Type.STRING_ARRAY); // World List
|
2023-10-06 13:37:52 +02:00
|
|
|
map(Type.NAMED_COMPOUND_TAG); // Registry
|
|
|
|
map(Type.NAMED_COMPOUND_TAG); // Current dimension data
|
2022-02-09 19:12:28 +01:00
|
|
|
handler(wrapper -> {
|
2023-10-06 13:37:52 +02:00
|
|
|
final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
2024-03-09 12:57:55 +01:00
|
|
|
final CompoundTag dimensionsHolder = registry.getCompoundTag("minecraft:dimension_type");
|
2024-03-07 12:08:27 +01:00
|
|
|
final ListTag<CompoundTag> dimensions = dimensionsHolder.getListTag("value", CompoundTag.class);
|
|
|
|
for (final CompoundTag dimension : dimensions) {
|
2024-03-09 12:57:55 +01:00
|
|
|
addTagPrefix(dimension.getCompoundTag("element"));
|
2022-02-09 19:12:28 +01:00
|
|
|
}
|
|
|
|
|
2023-10-06 13:37:52 +02:00
|
|
|
addTagPrefix(wrapper.get(Type.NAMED_COMPOUND_TAG, 1));
|
2022-02-09 19:12:28 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-10-06 13:37:52 +02:00
|
|
|
registerClientbound(ClientboundPackets1_18.RESPAWN, wrapper -> addTagPrefix(wrapper.passthrough(Type.NAMED_COMPOUND_TAG)));
|
2022-02-09 19:12:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addTagPrefix(CompoundTag tag) {
|
|
|
|
final Tag infiniburnTag = tag.get("infiniburn");
|
|
|
|
if (infiniburnTag instanceof StringTag) {
|
|
|
|
final StringTag infiniburn = (StringTag) infiniburnTag;
|
|
|
|
infiniburn.setValue("#" + infiniburn.getValue());
|
|
|
|
}
|
2022-01-19 18:05:36 +01:00
|
|
|
}
|
|
|
|
}
|