From 2a31ad7db4947479dcbb153eeb7f80b66af24c4c Mon Sep 17 00:00:00 2001 From: sisby-folk Date: Fri, 8 Nov 2024 17:22:12 +1100 Subject: [PATCH] port to 1.21 --- .../main/java/folk/sisby/switchy/packet/C2SDeletePreset.java | 4 ++-- .../main/java/folk/sisby/switchy/packet/C2SDisableModule.java | 3 ++- .../main/java/folk/sisby/switchy/packet/C2SEnableModule.java | 3 ++- .../main/java/folk/sisby/switchy/packet/C2SExportPresets.java | 3 ++- .../main/java/folk/sisby/switchy/packet/C2SImportPresets.java | 3 ++- .../src/main/java/folk/sisby/switchy/packet/C2SNewPreset.java | 3 ++- .../java/folk/sisby/switchy/packet/C2SPreviewPresets.java | 3 ++- .../main/java/folk/sisby/switchy/packet/C2SRenamePreset.java | 3 ++- .../main/java/folk/sisby/switchy/packet/C2SSwitchPreset.java | 3 ++- .../main/java/folk/sisby/switchy/packet/S2CExportPresets.java | 3 ++- .../java/folk/sisby/switchy/packet/S2CPreviewPresets.java | 3 ++- .../main/java/folk/sisby/switchy/packet/S2CSwitchEvent.java | 3 ++- core/src/main/java/folk/sisby/switchy/util/Feedback.java | 4 ++-- 13 files changed, 26 insertions(+), 15 deletions(-) diff --git a/client/src/main/java/folk/sisby/switchy/packet/C2SDeletePreset.java b/client/src/main/java/folk/sisby/switchy/packet/C2SDeletePreset.java index b5ed8ea..f2f35e9 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/C2SDeletePreset.java +++ b/client/src/main/java/folk/sisby/switchy/packet/C2SDeletePreset.java @@ -1,17 +1,17 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodecs; import net.minecraft.network.packet.CustomPayload; -import net.minecraft.util.Identifier; /** * Delete the specified preset */ public record C2SDeletePreset(int listener, String name) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_delete")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_delete")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SDeletePreset::listener, PacketCodecs.STRING, C2SDeletePreset::name, C2SDeletePreset::new); @Override diff --git a/client/src/main/java/folk/sisby/switchy/packet/C2SDisableModule.java b/client/src/main/java/folk/sisby/switchy/packet/C2SDisableModule.java index c14db95..ca03519 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/C2SDisableModule.java +++ b/client/src/main/java/folk/sisby/switchy/packet/C2SDisableModule.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodecs; @@ -11,7 +12,7 @@ * Disable a specified module. */ public record C2SDisableModule(int listener, Identifier id) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "c2s_modules_disable")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_modules_disable")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SDisableModule::listener, Identifier.PACKET_CODEC, C2SDisableModule::id, C2SDisableModule::new); @Override diff --git a/client/src/main/java/folk/sisby/switchy/packet/C2SEnableModule.java b/client/src/main/java/folk/sisby/switchy/packet/C2SEnableModule.java index 083088a..0a9db7b 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/C2SEnableModule.java +++ b/client/src/main/java/folk/sisby/switchy/packet/C2SEnableModule.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodecs; @@ -11,7 +12,7 @@ * Enable a specified module. */ public record C2SEnableModule(int listener, Identifier id) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "c2s_modules_enable")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_modules_enable")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SEnableModule::listener, Identifier.PACKET_CODEC, C2SEnableModule::id, C2SEnableModule::new); @Override diff --git a/client/src/main/java/folk/sisby/switchy/packet/C2SExportPresets.java b/client/src/main/java/folk/sisby/switchy/packet/C2SExportPresets.java index 3ad6268..f02a91f 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/C2SExportPresets.java +++ b/client/src/main/java/folk/sisby/switchy/packet/C2SExportPresets.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; @@ -12,7 +13,7 @@ * Request serialized presets for exporting. */ public record C2SExportPresets(int listener, NbtCompound presetsNbt) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_export")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_export")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SExportPresets::listener, PacketCodecs.NBT_COMPOUND, C2SExportPresets::presetsNbt, C2SExportPresets::new); @Override diff --git a/client/src/main/java/folk/sisby/switchy/packet/C2SImportPresets.java b/client/src/main/java/folk/sisby/switchy/packet/C2SImportPresets.java index 204594e..6c0199e 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/C2SImportPresets.java +++ b/client/src/main/java/folk/sisby/switchy/packet/C2SImportPresets.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; @@ -13,7 +14,7 @@ * Client: Must be sent twice to finalize - outputs confirmation text in chat. */ public record C2SImportPresets(int listener, boolean confirm, NbtCompound presetsNbt) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_import")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_import")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SImportPresets::listener, PacketCodecs.BOOL, C2SImportPresets::confirm, PacketCodecs.NBT_COMPOUND, C2SImportPresets::presetsNbt, C2SImportPresets::new); @Override diff --git a/client/src/main/java/folk/sisby/switchy/packet/C2SNewPreset.java b/client/src/main/java/folk/sisby/switchy/packet/C2SNewPreset.java index 19e5293..773dee9 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/C2SNewPreset.java +++ b/client/src/main/java/folk/sisby/switchy/packet/C2SNewPreset.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodecs; @@ -11,7 +12,7 @@ * Create a new preset */ public record C2SNewPreset(int listener, String name) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_new")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_new")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SNewPreset::listener, PacketCodecs.STRING, C2SNewPreset::name, C2SNewPreset::new); @Override diff --git a/client/src/main/java/folk/sisby/switchy/packet/C2SPreviewPresets.java b/client/src/main/java/folk/sisby/switchy/packet/C2SPreviewPresets.java index 186034d..32804ce 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/C2SPreviewPresets.java +++ b/client/src/main/java/folk/sisby/switchy/packet/C2SPreviewPresets.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodecs; @@ -11,7 +12,7 @@ * Request serialized presets for previewing. */ public record C2SPreviewPresets(int listener) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_preview")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_preview")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SPreviewPresets::listener, C2SPreviewPresets::new); @Override diff --git a/client/src/main/java/folk/sisby/switchy/packet/C2SRenamePreset.java b/client/src/main/java/folk/sisby/switchy/packet/C2SRenamePreset.java index aeef491..778b7a3 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/C2SRenamePreset.java +++ b/client/src/main/java/folk/sisby/switchy/packet/C2SRenamePreset.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodecs; @@ -11,7 +12,7 @@ * Rename the specified preset */ public record C2SRenamePreset(int listener, String oldName, String newName) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_rename")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_rename")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SRenamePreset::listener, PacketCodecs.STRING, C2SRenamePreset::oldName, PacketCodecs.STRING, C2SRenamePreset::newName, C2SRenamePreset::new); @Override diff --git a/client/src/main/java/folk/sisby/switchy/packet/C2SSwitchPreset.java b/client/src/main/java/folk/sisby/switchy/packet/C2SSwitchPreset.java index 9837688..3017b8d 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/C2SSwitchPreset.java +++ b/client/src/main/java/folk/sisby/switchy/packet/C2SSwitchPreset.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodecs; @@ -11,7 +12,7 @@ * Switch to a specified preset. */ public record C2SSwitchPreset(int listener, String name) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_switch")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_switch")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SSwitchPreset::listener, PacketCodecs.STRING, C2SSwitchPreset::name, C2SSwitchPreset::new); @Override diff --git a/client/src/main/java/folk/sisby/switchy/packet/S2CExportPresets.java b/client/src/main/java/folk/sisby/switchy/packet/S2CExportPresets.java index ff66fb1..c8daac7 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/S2CExportPresets.java +++ b/client/src/main/java/folk/sisby/switchy/packet/S2CExportPresets.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; @@ -12,7 +13,7 @@ * Contains the full presets data for exporting */ public record S2CExportPresets(int listener, NbtCompound feedbackNbt, NbtCompound presetsNbt) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "s2c_presets_export")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "s2c_presets_export")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, S2CExportPresets::listener, PacketCodecs.NBT_COMPOUND, S2CExportPresets::feedbackNbt, PacketCodecs.NBT_COMPOUND, S2CExportPresets::presetsNbt, S2CExportPresets::new); @Override diff --git a/client/src/main/java/folk/sisby/switchy/packet/S2CPreviewPresets.java b/client/src/main/java/folk/sisby/switchy/packet/S2CPreviewPresets.java index 688bf86..7b81ec3 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/S2CPreviewPresets.java +++ b/client/src/main/java/folk/sisby/switchy/packet/S2CPreviewPresets.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; @@ -12,7 +13,7 @@ * Contains preview-appropriate presets data for viewing */ public record S2CPreviewPresets(int listener, NbtCompound feedbackNbt, NbtCompound presetsNbt) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "s2c_presets_preview")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "s2c_presets_preview")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, S2CPreviewPresets::listener, PacketCodecs.NBT_COMPOUND, S2CPreviewPresets::feedbackNbt, PacketCodecs.NBT_COMPOUND, S2CPreviewPresets::presetsNbt, S2CPreviewPresets::new); @Override diff --git a/client/src/main/java/folk/sisby/switchy/packet/S2CSwitchEvent.java b/client/src/main/java/folk/sisby/switchy/packet/S2CSwitchEvent.java index a307682..82b66a2 100644 --- a/client/src/main/java/folk/sisby/switchy/packet/S2CSwitchEvent.java +++ b/client/src/main/java/folk/sisby/switchy/packet/S2CSwitchEvent.java @@ -1,6 +1,7 @@ package folk.sisby.switchy.packet; import folk.sisby.switchy.Switchy; +import folk.sisby.switchy.util.Feedback; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; @@ -12,7 +13,7 @@ * Replicates a switch event to the client */ public record S2CSwitchEvent(NbtCompound eventNbt) implements CustomPayload { - public static Id ID = new Id<>(Identifier.of(Switchy.ID, "s2c_events_switch")); + public static Id ID = new Id<>(Feedback.identifier(Switchy.ID, "s2c_events_switch")); public static PacketCodec CODEC = PacketCodec.tuple(PacketCodecs.NBT_COMPOUND, S2CSwitchEvent::eventNbt, S2CSwitchEvent::new); @Override diff --git a/core/src/main/java/folk/sisby/switchy/util/Feedback.java b/core/src/main/java/folk/sisby/switchy/util/Feedback.java index e55b988..bb95b43 100644 --- a/core/src/main/java/folk/sisby/switchy/util/Feedback.java +++ b/core/src/main/java/folk/sisby/switchy/util/Feedback.java @@ -62,11 +62,11 @@ public static void sendMessage(ServerPlayerEntity player, Text text) { } public static Identifier identifier(String identifier) { - return new Identifier(identifier); + return Identifier.tryParse(identifier); } public static Identifier identifier(String namespace, String key) { - return new Identifier(namespace, key); + return Identifier.of(namespace, key); } /**