diff --git a/leaves-server/minecraft-patches/features/0074-Replay-Mod-API.patch b/leaves-server/minecraft-patches/features/0074-Replay-Mod-API.patch index 92a1f57f..779398d5 100644 --- a/leaves-server/minecraft-patches/features/0074-Replay-Mod-API.patch +++ b/leaves-server/minecraft-patches/features/0074-Replay-Mod-API.patch @@ -142,7 +142,7 @@ index 7763d4c818606ed034f28e050166fe8cae16cfb8..1deedd3fc28792fc368580973038c182 } // Leaves end - skip diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java -index 8eb35e945a8c376128a4fa3868e32cc90209403a..01bab5294ae27624d8941d55bbe676cb1ea73966 100644 +index 93eb9e2d4e44881181a07b12249c3812635fec14..846a96de92c74cfd3091c21d692cb8bdac60c4eb 100644 --- a/net/minecraft/server/players/PlayerList.java +++ b/net/minecraft/server/players/PlayerList.java @@ -131,6 +131,7 @@ public abstract class PlayerList { @@ -157,7 +157,7 @@ index 8eb35e945a8c376128a4fa3868e32cc90209403a..01bab5294ae27624d8941d55bbe676cb abstract public void loadAndSaveFiles(); // Paper - fix converting txt to json file; moved from DedicatedPlayerList constructor -+ // Leaves start - replay api ++ // Leaves start - replay mod api + public void placeNewPhotographer(Connection connection, org.leavesmc.leaves.replay.ServerPhotographer player, ServerLevel worldserver) { + player.isRealPlayer = true; // Paper + player.loginTime = System.currentTimeMillis(); // Paper @@ -268,7 +268,7 @@ index 8eb35e945a8c376128a4fa3868e32cc90209403a..01bab5294ae27624d8941d55bbe676cb + ); + } + } -+ // Leaves end - replay api ++ // Leaves end - replay mod api + public void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie cookie) { player.isRealPlayer = true; // Paper @@ -298,7 +298,7 @@ index 8eb35e945a8c376128a4fa3868e32cc90209403a..01bab5294ae27624d8941d55bbe676cb } } -+ // Leaevs start - replay mod api ++ // Leaves start - replay mod api + public void removePhotographer(org.leavesmc.leaves.replay.ServerPhotographer entityplayer) { + ServerLevel worldserver = entityplayer.serverLevel(); + diff --git a/leaves-server/minecraft-patches/features/0114-Xaero-Map-Protocol.patch b/leaves-server/minecraft-patches/features/0114-Xaero-Map-Protocol.patch new file mode 100644 index 00000000..12a417ab --- /dev/null +++ b/leaves-server/minecraft-patches/features/0114-Xaero-Map-Protocol.patch @@ -0,0 +1,18 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: violetc <58360096+s-yh-china@users.noreply.github.com> +Date: Fri, 7 Feb 2025 14:23:43 +0800 +Subject: [PATCH] Xaero Map Protocol + + +diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java +index 9187e876a3e226a9f28af32630122f2ead72b6f3..2aafa4a3e5314b69bbb8deedb5df3a8979efc5d9 100644 +--- a/net/minecraft/server/players/PlayerList.java ++++ b/net/minecraft/server/players/PlayerList.java +@@ -1323,6 +1323,7 @@ public abstract class PlayerList { + player.connection.send(new ClientboundInitializeBorderPacket(worldBorder)); + player.connection.send(new ClientboundSetTimePacket(level.getGameTime(), level.getDayTime(), level.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); + player.connection.send(new ClientboundSetDefaultSpawnPositionPacket(level.getSharedSpawnPos(), level.getSharedSpawnAngle())); ++ org.leavesmc.leaves.protocol.XaeroMapProtocol.onSendWorldInfo(player); // Leaves - xaero map protocol + if (level.isRaining()) { + // CraftBukkit start - handle player weather + // player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0.0F)); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/AlwaysSendDataConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/AlwaysSendDataConfig.java index 31f68872..1ee9a806 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/AlwaysSendDataConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/AlwaysSendDataConfig.java @@ -16,7 +16,7 @@ public class AlwaysSendDataConfig extends BotConfig { private boolean value; public AlwaysSendDataConfig() { - super("always_send_data", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("ture", "false")), AlwaysSendDataConfig::new); + super("always_send_data", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("true", "false")), AlwaysSendDataConfig::new); this.value = LeavesConfig.modify.fakeplayer.canSendDataAlways; } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SkipSleepConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SkipSleepConfig.java index 0d934910..b2b1be24 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SkipSleepConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SkipSleepConfig.java @@ -13,7 +13,7 @@ public class SkipSleepConfig extends BotConfig { public SkipSleepConfig() { - super("skip_sleep", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("ture", "false")), SkipSleepConfig::new); + super("skip_sleep", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("true", "false")), SkipSleepConfig::new); } @Override diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SpawnPhantomConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SpawnPhantomConfig.java index 983b358a..24e3c3cf 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SpawnPhantomConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SpawnPhantomConfig.java @@ -15,7 +15,7 @@ public class SpawnPhantomConfig extends BotConfig { private boolean value; public SpawnPhantomConfig() { - super("spawn_phantom", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("ture", "false")), SpawnPhantomConfig::new); + super("spawn_phantom", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("true", "false")), SpawnPhantomConfig::new); this.value = LeavesConfig.modify.fakeplayer.canSpawnPhantom; } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LMSPasterProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LMSPasterProtocol.java index a933931f..03c45db2 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LMSPasterProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/LMSPasterProtocol.java @@ -125,7 +125,7 @@ public LmsPasterPayload(int id, CompoundTag nbt) { } @New - public LmsPasterPayload(FriendlyByteBuf buf) { + public LmsPasterPayload(ResourceLocation location, FriendlyByteBuf buf) { this(buf.readVarInt(), buf.readNbt()); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/RequestBlockPayload.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/RequestBlockPayload.java index 3cea446e..5e5b4a0c 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/RequestBlockPayload.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/RequestBlockPayload.java @@ -38,14 +38,14 @@ public void write(FriendlyByteBuf buf) { CODEC.encode(ProtocolUtils.decorate(buf), this); } - @New - public static RequestBlockPayload create(ResourceLocation location, FriendlyByteBuf buf) { - return CODEC.decode(ProtocolUtils.decorate(buf)); - } - @Override @NotNull public ResourceLocation id() { return PACKET_REQUEST_BLOCK; } + + @New + public static RequestBlockPayload create(ResourceLocation location, FriendlyByteBuf buf) { + return CODEC.decode(ProtocolUtils.decorate(buf)); + } } \ No newline at end of file diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/RequestEntityPayload.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/RequestEntityPayload.java index 61e47fa9..515dc5d1 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/RequestEntityPayload.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/RequestEntityPayload.java @@ -40,14 +40,14 @@ public void write(FriendlyByteBuf buf) { CODEC.encode(ProtocolUtils.decorate(buf), this); } - @New - public static RequestEntityPayload create(ResourceLocation location, FriendlyByteBuf buf) { - return CODEC.decode(ProtocolUtils.decorate(buf)); - } - @Override @NotNull public ResourceLocation id() { return PACKET_REQUEST_ENTITY; } + + @New + public static RequestEntityPayload create(ResourceLocation location, FriendlyByteBuf buf) { + return CODEC.decode(ProtocolUtils.decorate(buf)); + } } \ No newline at end of file diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/ServerHandshakePayload.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/ServerHandshakePayload.java index b7202127..f6a2ed7c 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/ServerHandshakePayload.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/payload/ServerHandshakePayload.java @@ -10,6 +10,7 @@ import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; +import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.protocol.core.LeavesCustomPayload; import org.leavesmc.leaves.protocol.core.ProtocolUtils; import org.leavesmc.leaves.protocol.jade.JadeProtocol; @@ -42,5 +43,10 @@ public void write(FriendlyByteBuf buf) { public ResourceLocation id() { return PACKET_SERVER_HANDSHAKE; } + + @New + public static ServerHandshakePayload create(ResourceLocation location, FriendlyByteBuf buf) { + return CODEC.decode(ProtocolUtils.decorate(buf)); + } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/REIServerProtocol.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/REIServerProtocol.java index ac636629..75f384bf 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/REIServerProtocol.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/REIServerProtocol.java @@ -2,32 +2,39 @@ import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.Contract; import org.leavesmc.leaves.LeavesConfig; import org.leavesmc.leaves.protocol.core.LeavesProtocol; +import org.leavesmc.leaves.protocol.core.LeavesProtocolManager.EmptyPayload; import org.leavesmc.leaves.protocol.core.ProtocolHandler; import org.leavesmc.leaves.protocol.core.ProtocolUtils; import org.leavesmc.leaves.protocol.rei.payload.CreateItemGrabPayload; import org.leavesmc.leaves.protocol.rei.payload.CreateItemHotbarPayload; import org.leavesmc.leaves.protocol.rei.payload.CreateItemMessagePayload; import org.leavesmc.leaves.protocol.rei.payload.CreateItemPayload; -import org.leavesmc.leaves.protocol.rei.payload.DeleteItemPayload; -@LeavesProtocol(namespace = "rei") +@LeavesProtocol(namespace = "roughlyenoughitems") public class REIServerProtocol { - @ProtocolHandler.PayloadReceiver(payload = DeleteItemPayload.class, payloadId = "delete_item") - public static void handleDeleteItem(ServerPlayer player, DeleteItemPayload payload) { - if (!LeavesConfig.protocol.reiServerProtocol) { - return; - } - if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) { - player.displayClientMessage(Component.translatable("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false); + public static final String PROTOCOL_ID = "roughlyenoughitems"; + + @Contract("_ -> new") + public static ResourceLocation id(String path) { + return ResourceLocation.tryBuild(PROTOCOL_ID, path); + } + + @ProtocolHandler.PayloadReceiver(payload = EmptyPayload.class, payloadId = "delete_item") + public static void handleDeleteItem(ServerPlayer player, EmptyPayload payload) { + if (!check(player, true)) { return; } + AbstractContainerMenu menu = player.containerMenu; if (!menu.getCarried().isEmpty()) { menu.setCarried(ItemStack.EMPTY); @@ -37,14 +44,11 @@ public static void handleDeleteItem(ServerPlayer player, DeleteItemPayload paylo @ProtocolHandler.PayloadReceiver(payload = CreateItemPayload.class, payloadId = "create_item") public static void handleCreateItem(ServerPlayer player, CreateItemPayload payload) { - if (!LeavesConfig.protocol.reiServerProtocol) { - return; - } - if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) { - player.displayClientMessage(Component.translatable("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false); + if (!check(player, true)) { return; } - ItemStack stack = payload.getItem(); + + ItemStack stack = payload.item(); if (player.getInventory().add(stack.copy())) { ProtocolUtils.sendPayloadPacket(player, new CreateItemMessagePayload(stack.copy(), player.getScoreboardName())); } else { @@ -54,15 +58,12 @@ public static void handleCreateItem(ServerPlayer player, CreateItemPayload paylo @ProtocolHandler.PayloadReceiver(payload = CreateItemGrabPayload.class, payloadId = "create_item_grab") public static void handleCreateItemGrab(ServerPlayer player, CreateItemGrabPayload payload) { - if (!LeavesConfig.protocol.reiServerProtocol) { - return; - } - if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) { - player.displayClientMessage(Component.translatable("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false); + if (!check(player, true)) { return; } + AbstractContainerMenu menu = player.containerMenu; - ItemStack itemStack = payload.getItem(); + ItemStack itemStack = payload.item(); ItemStack stack = itemStack.copy(); if (!menu.getCarried().isEmpty() && ItemStack.isSameItemSameComponents(menu.getCarried(), stack)) { stack.setCount(Mth.clamp(stack.getCount() + menu.getCarried().getCount(), 1, stack.getMaxStackSize())); @@ -76,15 +77,12 @@ public static void handleCreateItemGrab(ServerPlayer player, CreateItemGrabPaylo @ProtocolHandler.PayloadReceiver(payload = CreateItemHotbarPayload.class, payloadId = "create_item_hotbar") public static void handleCreateItemHotbar(ServerPlayer player, CreateItemHotbarPayload payload) { - if (!LeavesConfig.protocol.reiServerProtocol) { + if (!check(player, true)) { return; } - if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) { - player.displayClientMessage(Component.translatable("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false); - return; - } - ItemStack stack = payload.getItem(); - int hotbarSlotId = payload.getHotbarSlot(); + + ItemStack stack = payload.item(); + int hotbarSlotId = payload.hotbarSlot(); if (hotbarSlotId >= 0 && hotbarSlotId < 9) { AbstractContainerMenu menu = player.containerMenu; player.getInventory().items.set(hotbarSlotId, stack.copy()); @@ -94,4 +92,16 @@ public static void handleCreateItemHotbar(ServerPlayer player, CreateItemHotbarP player.displayClientMessage(Component.translatable("text.rei.failed_cheat_items"), false); } } + + private static boolean check(ServerPlayer player, boolean needOP) { + if (!LeavesConfig.protocol.reiServerProtocol) { + return false; + } + + if (needOP && MinecraftServer.getServer().getPlayerList().isOp(player.gameProfile)) { // TODO check permission node + player.displayClientMessage(Component.translatable("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false); + return false; + } + return true; + } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemGrabPayload.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemGrabPayload.java index 840b121c..8be991f8 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemGrabPayload.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemGrabPayload.java @@ -3,25 +3,21 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.protocol.core.LeavesCustomPayload; +import org.leavesmc.leaves.protocol.rei.REIServerProtocol; -public class CreateItemGrabPayload implements LeavesCustomPayload { +public record CreateItemGrabPayload(ItemStack item) implements LeavesCustomPayload { - private static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "create_item_grab"); - - private final ItemStack item; - - public CreateItemGrabPayload(final ItemStack item) { - this.item = item; - } + private static final ResourceLocation ID = REIServerProtocol.id("create_item_grab"); @New - public CreateItemGrabPayload(FriendlyByteBuf buf) { + public CreateItemGrabPayload(ResourceLocation location, @NotNull FriendlyByteBuf buf) { this(buf.readJsonWithCodec(ItemStack.OPTIONAL_CODEC)); } @Override - public void write(FriendlyByteBuf buf) { + public void write(@NotNull FriendlyByteBuf buf) { buf.writeJsonWithCodec(ItemStack.OPTIONAL_CODEC, item); } @@ -29,8 +25,4 @@ public void write(FriendlyByteBuf buf) { public ResourceLocation id() { return ID; } - - public ItemStack getItem() { - return item; - } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemHotbarPayload.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemHotbarPayload.java index 34f34185..8728f3e6 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemHotbarPayload.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemHotbarPayload.java @@ -4,21 +4,14 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import org.leavesmc.leaves.protocol.core.LeavesCustomPayload; +import org.leavesmc.leaves.protocol.rei.REIServerProtocol; -public class CreateItemHotbarPayload implements LeavesCustomPayload { +public record CreateItemHotbarPayload(ItemStack item, int hotbarSlot) implements LeavesCustomPayload { - private static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "create_item_hotbar"); - - private final ItemStack item; - private final int hotbarSlot; - - public CreateItemHotbarPayload(final ItemStack item, final int hotbarSlot) { - this.item = item; - this.hotbarSlot = hotbarSlot; - } + private static final ResourceLocation ID = REIServerProtocol.id("create_item_hotbar"); @New - public CreateItemHotbarPayload(FriendlyByteBuf buf) { + public CreateItemHotbarPayload(ResourceLocation location, FriendlyByteBuf buf) { this(buf.readJsonWithCodec(ItemStack.OPTIONAL_CODEC), buf.readVarInt()); } @@ -32,12 +25,4 @@ public void write(FriendlyByteBuf buf) { public ResourceLocation id() { return ID; } - - public ItemStack getItem() { - return item; - } - - public int getHotbarSlot() { - return hotbarSlot; - } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemMessagePayload.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemMessagePayload.java index 91787ecc..ef6c70f8 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemMessagePayload.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemMessagePayload.java @@ -3,22 +3,21 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.protocol.core.LeavesCustomPayload; +import org.leavesmc.leaves.protocol.rei.REIServerProtocol; -public class CreateItemMessagePayload implements LeavesCustomPayload { +public record CreateItemMessagePayload(ItemStack item, String playerName) implements LeavesCustomPayload { - private static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "ci_msg"); + private static final ResourceLocation ID = REIServerProtocol.id("ci_msg"); - private final ItemStack item; - private final String playerName; - - public CreateItemMessagePayload(final ItemStack item, final String playerName) { - this.item = item; - this.playerName = playerName; + @New + public CreateItemMessagePayload(ResourceLocation location, @NotNull FriendlyByteBuf buf) { + this(buf.readJsonWithCodec(ItemStack.OPTIONAL_CODEC), buf.readUtf()); } @Override - public void write(FriendlyByteBuf buf) { + public void write(@NotNull FriendlyByteBuf buf) { buf.writeJsonWithCodec(ItemStack.OPTIONAL_CODEC, item); buf.writeUtf(playerName); } @@ -27,12 +26,4 @@ public void write(FriendlyByteBuf buf) { public ResourceLocation id() { return ID; } - - public ItemStack getItem() { - return item; - } - - public String getPlayerName() { - return playerName; - } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemPayload.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemPayload.java index e2cccdf1..29ea16b2 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemPayload.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/CreateItemPayload.java @@ -3,26 +3,21 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.protocol.core.LeavesCustomPayload; +import org.leavesmc.leaves.protocol.rei.REIServerProtocol; -public class CreateItemPayload implements LeavesCustomPayload { +public record CreateItemPayload(ItemStack item) implements LeavesCustomPayload { - private static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "create_item"); - - private final ItemStack item; - - @New - public CreateItemPayload(ItemStack item) { - this.item = item; - } + private static final ResourceLocation ID = REIServerProtocol.id("create_item"); @New - public CreateItemPayload(FriendlyByteBuf buf) { + public CreateItemPayload(ResourceLocation location, @NotNull FriendlyByteBuf buf) { this(buf.readJsonWithCodec(ItemStack.OPTIONAL_CODEC)); } @Override - public void write(FriendlyByteBuf buf) { + public void write(@NotNull FriendlyByteBuf buf) { buf.writeJsonWithCodec(ItemStack.OPTIONAL_CODEC, item); } @@ -30,8 +25,4 @@ public void write(FriendlyByteBuf buf) { public ResourceLocation id() { return ID; } - - public ItemStack getItem() { - return item; - } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/DeleteItemPayload.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/DeleteItemPayload.java deleted file mode 100644 index 52918e9e..00000000 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/DeleteItemPayload.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.leavesmc.leaves.protocol.rei.payload; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import org.leavesmc.leaves.protocol.core.LeavesCustomPayload; - -public class DeleteItemPayload implements LeavesCustomPayload { - - private static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "delete_item"); - - @Override - public void write(FriendlyByteBuf buf) { - - } - - @Override - public ResourceLocation id() { - return ID; - } -} diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/MoveItemPayload.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/MoveItemPayload.java new file mode 100644 index 00000000..760aae1d --- /dev/null +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/rei/payload/MoveItemPayload.java @@ -0,0 +1,30 @@ +package org.leavesmc.leaves.protocol.rei.payload; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; +import org.leavesmc.leaves.protocol.core.LeavesCustomPayload; +import org.leavesmc.leaves.protocol.rei.REIServerProtocol; + +public record MoveItemPayload(ResourceLocation category, boolean isShift, CompoundTag nbt) implements LeavesCustomPayload { + + private static final ResourceLocation ID = REIServerProtocol.id("move_items_new"); + + @New + public MoveItemPayload(ResourceLocation location, @NotNull FriendlyByteBuf buf) { + this(buf.readResourceLocation(), buf.readBoolean(), buf.readNbt()); + } + + @Override + public void write(@NotNull FriendlyByteBuf buf) { + buf.writeResourceLocation(category); + buf.writeBoolean(isShift); + buf.writeNbt(nbt); + } + + @Override + public ResourceLocation id() { + return ID; + } +}