From 18b561c8d16b8dcd0dd84f232adda8faefb2054f 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/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 +- 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/moulberry/axiom/VersionHelper.java b/src/main/java/com/moulberry/axiom/VersionHelper.java index 2c3992c..28aa8bf 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(id, new FriendlyByteBuf(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 0a160f7..d6352c4 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 5d0fa96..f150720 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 6fd8984..dfc8c8d 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 ed11a67..862c3b7 100644 --- a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java @@ -34,7 +34,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) {