Skip to content

Commit

Permalink
port to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Nov 8, 2024
1 parent eaf9580 commit 2a31ad7
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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<C2SDeletePreset> ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_delete"));
public static Id<C2SDeletePreset> ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_delete"));
public static PacketCodec<PacketByteBuf, C2SDeletePreset> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SDeletePreset::listener, PacketCodecs.STRING, C2SDeletePreset::name, C2SDeletePreset::new);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +12,7 @@
* Disable a specified module.
*/
public record C2SDisableModule(int listener, Identifier id) implements CustomPayload {
public static Id<C2SDisableModule> ID = new Id<>(Identifier.of(Switchy.ID, "c2s_modules_disable"));
public static Id<C2SDisableModule> ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_modules_disable"));
public static PacketCodec<PacketByteBuf, C2SDisableModule> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SDisableModule::listener, Identifier.PACKET_CODEC, C2SDisableModule::id, C2SDisableModule::new);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +12,7 @@
* Enable a specified module.
*/
public record C2SEnableModule(int listener, Identifier id) implements CustomPayload {
public static Id<C2SEnableModule> ID = new Id<>(Identifier.of(Switchy.ID, "c2s_modules_enable"));
public static Id<C2SEnableModule> ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_modules_enable"));
public static PacketCodec<PacketByteBuf, C2SEnableModule> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SEnableModule::listener, Identifier.PACKET_CODEC, C2SEnableModule::id, C2SEnableModule::new);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +13,7 @@
* Request serialized presets for exporting.
*/
public record C2SExportPresets(int listener, NbtCompound presetsNbt) implements CustomPayload {
public static Id<C2SExportPresets> ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_export"));
public static Id<C2SExportPresets> ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_export"));
public static PacketCodec<PacketByteBuf, C2SExportPresets> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SExportPresets::listener, PacketCodecs.NBT_COMPOUND, C2SExportPresets::presetsNbt, C2SExportPresets::new);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<C2SImportPresets> ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_import"));
public static Id<C2SImportPresets> ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_import"));
public static PacketCodec<PacketByteBuf, C2SImportPresets> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SImportPresets::listener, PacketCodecs.BOOL, C2SImportPresets::confirm, PacketCodecs.NBT_COMPOUND, C2SImportPresets::presetsNbt, C2SImportPresets::new);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +12,7 @@
* Create a new preset
*/
public record C2SNewPreset(int listener, String name) implements CustomPayload {
public static Id<C2SNewPreset> ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_new"));
public static Id<C2SNewPreset> ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_new"));
public static PacketCodec<PacketByteBuf, C2SNewPreset> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SNewPreset::listener, PacketCodecs.STRING, C2SNewPreset::name, C2SNewPreset::new);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +12,7 @@
* Request serialized presets for previewing.
*/
public record C2SPreviewPresets(int listener) implements CustomPayload {
public static Id<C2SPreviewPresets> ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_preview"));
public static Id<C2SPreviewPresets> ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_preview"));
public static PacketCodec<PacketByteBuf, C2SPreviewPresets> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SPreviewPresets::listener, C2SPreviewPresets::new);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +12,7 @@
* Rename the specified preset
*/
public record C2SRenamePreset(int listener, String oldName, String newName) implements CustomPayload {
public static Id<C2SRenamePreset> ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_rename"));
public static Id<C2SRenamePreset> ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_rename"));
public static PacketCodec<PacketByteBuf, C2SRenamePreset> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SRenamePreset::listener, PacketCodecs.STRING, C2SRenamePreset::oldName, PacketCodecs.STRING, C2SRenamePreset::newName, C2SRenamePreset::new);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +12,7 @@
* Switch to a specified preset.
*/
public record C2SSwitchPreset(int listener, String name) implements CustomPayload {
public static Id<C2SSwitchPreset> ID = new Id<>(Identifier.of(Switchy.ID, "c2s_presets_switch"));
public static Id<C2SSwitchPreset> ID = new Id<>(Feedback.identifier(Switchy.ID, "c2s_presets_switch"));
public static PacketCodec<PacketByteBuf, C2SSwitchPreset> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, C2SSwitchPreset::listener, PacketCodecs.STRING, C2SSwitchPreset::name, C2SSwitchPreset::new);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<S2CExportPresets> ID = new Id<>(Identifier.of(Switchy.ID, "s2c_presets_export"));
public static Id<S2CExportPresets> ID = new Id<>(Feedback.identifier(Switchy.ID, "s2c_presets_export"));
public static PacketCodec<PacketByteBuf, S2CExportPresets> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, S2CExportPresets::listener, PacketCodecs.NBT_COMPOUND, S2CExportPresets::feedbackNbt, PacketCodecs.NBT_COMPOUND, S2CExportPresets::presetsNbt, S2CExportPresets::new);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<S2CPreviewPresets> ID = new Id<>(Identifier.of(Switchy.ID, "s2c_presets_preview"));
public static Id<S2CPreviewPresets> ID = new Id<>(Feedback.identifier(Switchy.ID, "s2c_presets_preview"));
public static PacketCodec<PacketByteBuf, S2CPreviewPresets> CODEC = PacketCodec.tuple(PacketCodecs.VAR_INT, S2CPreviewPresets::listener, PacketCodecs.NBT_COMPOUND, S2CPreviewPresets::feedbackNbt, PacketCodecs.NBT_COMPOUND, S2CPreviewPresets::presetsNbt, S2CPreviewPresets::new);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +13,7 @@
* Replicates a switch event to the client
*/
public record S2CSwitchEvent(NbtCompound eventNbt) implements CustomPayload {
public static Id<S2CSwitchEvent> ID = new Id<>(Identifier.of(Switchy.ID, "s2c_events_switch"));
public static Id<S2CSwitchEvent> ID = new Id<>(Feedback.identifier(Switchy.ID, "s2c_events_switch"));
public static PacketCodec<PacketByteBuf, S2CSwitchEvent> CODEC = PacketCodec.tuple(PacketCodecs.NBT_COMPOUND, S2CSwitchEvent::eventNbt, S2CSwitchEvent::new);

@Override
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/folk/sisby/switchy/util/Feedback.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 2a31ad7

Please sign in to comment.