From a077e31295bf674b00b2365556ce9d35ebebd773 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Thu, 27 Jun 2024 01:35:46 +0800 Subject: [PATCH] Use VersionHelper to create resource location --- src/main/java/com/moulberry/axiom/AxiomPaper.java | 2 +- src/main/java/com/moulberry/axiom/VersionHelper.java | 8 ++++++++ src/main/java/com/moulberry/axiom/View.java | 4 +--- .../java/com/moulberry/axiom/blueprint/BlueprintIo.java | 3 ++- .../moulberry/axiom/blueprint/ServerBlueprintManager.java | 2 +- .../moulberry/axiom/packet/AxiomBigPayloadHandler.java | 6 +++--- .../axiom/packet/BlueprintRequestPacketListener.java | 2 +- .../axiom/packet/RequestChunkDataPacketListener.java | 2 +- 8 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/moulberry/axiom/AxiomPaper.java b/src/main/java/com/moulberry/axiom/AxiomPaper.java index feb4050..e7aac44 100644 --- a/src/main/java/com/moulberry/axiom/AxiomPaper.java +++ b/src/main/java/com/moulberry/axiom/AxiomPaper.java @@ -165,7 +165,7 @@ public class AxiomPaper extends JavaPlugin implements Listener { ProtocolInfo protocol = GameProtocols.SERVERBOUND.bind(k -> new RegistryFriendlyByteBuf(k, MinecraftServer.getServer().registryAccess())); RegistryFriendlyByteBuf friendlyByteBuf = new RegistryFriendlyByteBuf(Unpooled.buffer(), MinecraftServer.getServer().registryAccess()); - protocol.codec().encode(friendlyByteBuf, new ServerboundCustomPayloadPacket(new DiscardedPayload(new ResourceLocation("dummy"), Unpooled.buffer()))); + protocol.codec().encode(friendlyByteBuf, new ServerboundCustomPayloadPacket(new DiscardedPayload(VersionHelper.createResourceLocation("dummy"), Unpooled.buffer()))); int payloadId = friendlyByteBuf.readVarInt(); ChannelInitializeListenerHolder.addListener(Key.key("axiom:handle_big_payload"), new ChannelInitializeListener() { diff --git a/src/main/java/com/moulberry/axiom/VersionHelper.java b/src/main/java/com/moulberry/axiom/VersionHelper.java index 902c9f0..3418349 100644 --- a/src/main/java/com/moulberry/axiom/VersionHelper.java +++ b/src/main/java/com/moulberry/axiom/VersionHelper.java @@ -12,4 +12,12 @@ public class VersionHelper { serverPlayer.connection.send(new ClientboundCustomPayloadPacket(new DiscardedPayload(id, Unpooled.wrappedBuffer(data)))); } + public static ResourceLocation createResourceLocation(String composed) { + return ResourceLocation.parse(composed); + } + + public static ResourceLocation createResourceLocation(String namespace, String path) { + return ResourceLocation.fromNamespaceAndPath(namespace, path); + } + } diff --git a/src/main/java/com/moulberry/axiom/View.java b/src/main/java/com/moulberry/axiom/View.java index 5dd2138..5defc45 100644 --- a/src/main/java/com/moulberry/axiom/View.java +++ b/src/main/java/com/moulberry/axiom/View.java @@ -2,8 +2,6 @@ package com.moulberry.axiom; import com.moulberry.axiom.persistence.UUIDDataType; import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; @@ -113,7 +111,7 @@ public final class View { view.pinLevel = tag.getOrDefault(PIN_LEVEL_KEY, PersistentDataType.BOOLEAN, false); if (tag.has(LEVEL_KEY)) { String level = tag.get(LEVEL_KEY, PersistentDataType.STRING); - view.level = ResourceKey.create(Registries.DIMENSION, new ResourceLocation(level)); + view.level = ResourceKey.create(Registries.DIMENSION, VersionHelper.createResourceLocation(level)); } view.pinLocation = tag.getOrDefault(PIN_LOCATION_KEY, PersistentDataType.BOOLEAN, false); diff --git a/src/main/java/com/moulberry/axiom/blueprint/BlueprintIo.java b/src/main/java/com/moulberry/axiom/blueprint/BlueprintIo.java index 01f56df..bb9a43b 100644 --- a/src/main/java/com/moulberry/axiom/blueprint/BlueprintIo.java +++ b/src/main/java/com/moulberry/axiom/blueprint/BlueprintIo.java @@ -2,6 +2,7 @@ package com.moulberry.axiom.blueprint; import com.mojang.serialization.Codec; import com.mojang.serialization.Dynamic; +import com.moulberry.axiom.VersionHelper; import com.moulberry.axiom.buffer.CompressedBlockEntity; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -88,7 +89,7 @@ public class BlueprintIo { long pos = blockPos.asLong(); String id = blockEntityCompound.getString("id"); - BlockEntityType type = BuiltInRegistries.BLOCK_ENTITY_TYPE.get(new ResourceLocation(id)); + BlockEntityType type = BuiltInRegistries.BLOCK_ENTITY_TYPE.get(VersionHelper.createResourceLocation(id)); if (type != null) { PalettedContainer container = blockMap.get(BlockPos.asLong( diff --git a/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java b/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java index d6939cd..33661c6 100644 --- a/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java +++ b/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java @@ -26,7 +26,7 @@ public class ServerBlueprintManager { } private static final int MAX_SIZE = 1000000; - private static final ResourceLocation PACKET_BLUEPRINT_MANIFEST_IDENTIFIER = new ResourceLocation("axiom:blueprint_manifest"); + private static final ResourceLocation PACKET_BLUEPRINT_MANIFEST_IDENTIFIER = VersionHelper.createResourceLocation("axiom:blueprint_manifest"); public static void sendManifest(List serverPlayers) { if (registry != null) { diff --git a/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java b/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java index 3f3b004..71075ca 100644 --- a/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java +++ b/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java @@ -16,9 +16,9 @@ import java.util.List; public class AxiomBigPayloadHandler extends ByteToMessageDecoder { - private static final ResourceLocation SET_BUFFER = new ResourceLocation("axiom", "set_buffer"); - private static final ResourceLocation UPLOAD_BLUEPRINT = new ResourceLocation("axiom", "upload_blueprint"); - private static final ResourceLocation REQUEST_CHUNK_DATA = new ResourceLocation("axiom", "request_chunk_data"); + private static final ResourceLocation SET_BUFFER = VersionHelper.createResourceLocation("axiom", "set_buffer"); + private static final ResourceLocation UPLOAD_BLUEPRINT = VersionHelper.createResourceLocation("axiom", "upload_blueprint"); + private static final ResourceLocation REQUEST_CHUNK_DATA = VersionHelper.createResourceLocation("axiom", "request_chunk_data"); private final int payloadId; private final Connection connection; private final SetBlockBufferPacketListener setBlockBuffer; diff --git a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java b/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java index 8b920e0..98c7b51 100644 --- a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java @@ -24,7 +24,7 @@ public class BlueprintRequestPacketListener implements PluginMessageListener { this.plugin = plugin; } - private static final ResourceLocation RESPONSE_PACKET_IDENTIFIER = new ResourceLocation("axiom:response_blueprint"); + private static final ResourceLocation RESPONSE_PACKET_IDENTIFIER = VersionHelper.createResourceLocation("axiom:response_blueprint"); @Override public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) { diff --git a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java index b538c44..df58769 100644 --- a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java @@ -35,7 +35,7 @@ import java.io.ByteArrayOutputStream; public class RequestChunkDataPacketListener implements PluginMessageListener { - private static final ResourceLocation RESPONSE_ID = new ResourceLocation("axiom:response_chunk_data"); + private static final ResourceLocation RESPONSE_ID = VersionHelper.createResourceLocation("axiom:response_chunk_data"); private final AxiomPaper plugin; public RequestChunkDataPacketListener(AxiomPaper plugin) {