mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-06 15:52:03 +00:00
修复混合数据类型list nbt序列化
This commit is contained in:
@@ -4,7 +4,6 @@ import com.mojang.datafixers.util.Pair;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.ClassFileVersion;
|
||||
import net.bytebuddy.description.field.FieldDescription;
|
||||
import net.bytebuddy.description.method.ParameterDescription;
|
||||
import net.bytebuddy.description.modifier.Visibility;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
|
||||
@@ -156,8 +156,9 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
registerByteBufPacketConsumer(PacketConsumers.LEVEL_PARTICLE, this.packetIds.clientboundLevelParticlesPacket());
|
||||
registerByteBufPacketConsumer(PacketConsumers.LEVEL_EVENT, this.packetIds.clientboundLevelEventPacket());
|
||||
registerByteBufPacketConsumer(VersionHelper.isVersionNewerThan1_20_3() ? PacketConsumers.OPEN_SCREEN_1_20_3 : PacketConsumers.OPEN_SCREEN_1_20, this.packetIds.clientboundOpenScreenPacket());
|
||||
registerByteBufPacketConsumer(VersionHelper.isVersionNewerThan1_20_3() ? PacketConsumers.SET_TITLE_TEXT_1_20_3 : PacketConsumers.SET_TITLE_TEXT_1_20, this.packetIds.clientboundSetTitleTextPacket());
|
||||
registerByteBufPacketConsumer(VersionHelper.isVersionNewerThan1_20_3() ? PacketConsumers.SET_TITLE_TEXT_1_20_3 : PacketConsumers.SET_TITLE_TEXT_1_20, this.packetIds.clientboundSetSubtitleTextPacket());
|
||||
registerByteBufPacketConsumer(VersionHelper.isVersionNewerThan1_20_3() ? PacketConsumers.SET_TEXT_1_20_3 : PacketConsumers.SET_TEXT_1_20, this.packetIds.clientboundSetTitleTextPacket());
|
||||
registerByteBufPacketConsumer(VersionHelper.isVersionNewerThan1_20_3() ? PacketConsumers.SET_TEXT_1_20_3 : PacketConsumers.SET_TEXT_1_20, this.packetIds.clientboundSetSubtitleTextPacket());
|
||||
registerByteBufPacketConsumer(VersionHelper.isVersionNewerThan1_20_3() ? PacketConsumers.SET_TEXT_1_20_3 : PacketConsumers.SET_TEXT_1_20, this.packetIds.clientboundSetActionBarTextPacket());
|
||||
// registerByteBufPacketConsumer(PacketConsumers.REMOVE_ENTITY, this.packetIds.clientboundRemoveEntitiesPacket());
|
||||
registerByteBufPacketConsumer(PacketConsumers.ADD_ENTITY_BYTEBUFFER, this.packetIds.clientboundAddEntityPacket());
|
||||
// registerByteBufPacketConsumer(PacketConsumers.SOUND, this.packetIds.clientboundSoundPacket());
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.netty.buffer.Unpooled;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TranslationArgument;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.craftengine.bukkit.api.CraftEngineFurniture;
|
||||
import net.momirealms.craftengine.bukkit.api.event.FurnitureBreakEvent;
|
||||
import net.momirealms.craftengine.bukkit.api.event.FurnitureInteractEvent;
|
||||
@@ -242,7 +243,7 @@ public class PacketConsumers {
|
||||
}
|
||||
};
|
||||
|
||||
public static final BiConsumer<NetWorkUser, ByteBufPacketEvent> SET_TITLE_TEXT_1_20 = (user, event) -> {
|
||||
public static final BiConsumer<NetWorkUser, ByteBufPacketEvent> SET_TEXT_1_20 = (user, event) -> {
|
||||
try {
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
String json = buf.readUtf();
|
||||
@@ -257,18 +258,20 @@ public class PacketConsumers {
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeUtf(AdventureHelper.componentToJson(component));
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundSet(Sub)TitleTextPacket", e);
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundSet[(Sub)Title/ActionBar]TextPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
public static final BiConsumer<NetWorkUser, ByteBufPacketEvent> SET_TITLE_TEXT_1_20_3 = (user, event) -> {
|
||||
public static final BiConsumer<NetWorkUser, ByteBufPacketEvent> SET_TEXT_1_20_3 = (user, event) -> {
|
||||
try {
|
||||
FriendlyByteBuf buf = event.getBuffer();
|
||||
Tag nbt = buf.readNbt(false);
|
||||
if (nbt == null) return;
|
||||
System.out.println(nbt.getAsString());
|
||||
Map<String, String> tokens = CraftEngine.instance().imageManager().matchTags(nbt.getAsString());
|
||||
if (tokens.isEmpty()) return;
|
||||
Component component = NBTComponentSerializer.nbt().deserialize(nbt);
|
||||
System.out.println(GsonComponentSerializer.gson().serialize(component));
|
||||
for (Map.Entry<String, String> token : tokens.entrySet()) {
|
||||
component = component.replaceText(b -> b.matchLiteral(token.getKey()).replacement(AdventureHelper.miniMessage().deserialize(token.getValue())));
|
||||
}
|
||||
@@ -276,7 +279,7 @@ public class PacketConsumers {
|
||||
buf.writeVarInt(event.packetID());
|
||||
buf.writeNbt(NBTComponentSerializer.nbt().serialize(component), false);
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundSet(Sub)TitleTextPacket", e);
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundSet[(Sub)Title/ActionBar]TextPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -23,4 +23,6 @@ public interface PacketIds {
|
||||
int clientboundSetTitleTextPacket();
|
||||
|
||||
int clientboundSetSubtitleTextPacket();
|
||||
|
||||
int clientboundSetActionBarTextPacket();
|
||||
}
|
||||
|
||||
@@ -58,4 +58,9 @@ public class PacketIds1_20 implements PacketIds {
|
||||
public int clientboundSetSubtitleTextPacket() {
|
||||
return 93;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clientboundSetActionBarTextPacket() {
|
||||
return 70;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,4 +58,9 @@ public class PacketIds1_20_2 implements PacketIds {
|
||||
public int clientboundSetSubtitleTextPacket() {
|
||||
return 95;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clientboundSetActionBarTextPacket() {
|
||||
return 72;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,4 +58,9 @@ public class PacketIds1_20_3 implements PacketIds {
|
||||
public int clientboundSetSubtitleTextPacket() {
|
||||
return 97;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clientboundSetActionBarTextPacket() {
|
||||
return 74;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,4 +58,9 @@ public class PacketIds1_20_5 implements PacketIds {
|
||||
public int clientboundSetSubtitleTextPacket() {
|
||||
return 99;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clientboundSetActionBarTextPacket() {
|
||||
return 76;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,4 +58,9 @@ public class PacketIds1_21 implements PacketIds {
|
||||
public int clientboundSetSubtitleTextPacket() {
|
||||
return PacketIdFinder.clientboundByName("minecraft:set_subtitle_text");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clientboundSetActionBarTextPacket() {
|
||||
return PacketIdFinder.clientboundByName("minecraft:set_action_bar_text");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ lz4_version=1.8.0
|
||||
geantyref_version=1.3.16
|
||||
zstd_version=1.5.7-2
|
||||
commons_io_version=2.18.0
|
||||
sparrow_nbt_version=0.4.6
|
||||
sparrow_nbt_version=0.5
|
||||
sparrow_util_version=0.37
|
||||
fastutil_version=8.5.15
|
||||
netty_version=4.1.119.Final
|
||||
|
||||
Reference in New Issue
Block a user