From 97be59a7b6b990e8a68b69424904ed465a1faabe Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Mon, 16 Mar 2026 22:14:20 +0100 Subject: feat(): support 26.1 --- .../java/world/anhgelus/molehunt/Molehunt.java | 94 ++++++------- .../world/anhgelus/molehunt/config/Config.java | 26 ++-- .../anhgelus/molehunt/config/ConfigPayload.java | 26 ++-- .../java/world/anhgelus/molehunt/game/Game.java | 155 +++++++++++---------- .../world/anhgelus/molehunt/game/GamePayload.java | 22 +-- .../molehunt/mixin/NoJoinLeaveMessage.java | 16 +-- .../anhgelus/molehunt/mixin/NoMsgCommand.java | 8 +- .../world/anhgelus/molehunt/mixin/NoPortals.java | 12 +- 8 files changed, 180 insertions(+), 179 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index d5df320..984f906 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -13,17 +13,17 @@ import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket; +import net.minecraft.resources.Identifier; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; -import net.minecraft.world.GameMode; -import net.minecraft.world.rule.GameRule; -import net.minecraft.world.rule.GameRuleCategory; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.GameType; +import net.minecraft.world.level.gamerules.GameRule; +import net.minecraft.world.level.gamerules.GameRuleCategory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import world.anhgelus.molehunt.config.Config; @@ -35,7 +35,7 @@ import world.anhgelus.molehunt.game.GamePayload; import java.util.HashMap; import java.util.UUID; -import static net.minecraft.server.command.CommandManager.literal; +import static net.minecraft.commands.Commands.literal; public class Molehunt implements ModInitializer { @@ -49,61 +49,61 @@ public class Molehunt implements ModInitializer { public static final GameRule GAME_DURATION = GameRuleBuilder .forInteger(CONFIG_FILE.getOrDefault("game_duration", 90)) .category(GameRuleCategory.MISC) - .buildAndRegister(Identifier.of(MOD_ID, "gameDurationMinutes")); + .buildAndRegister(Identifier.fromNamespaceAndPath(MOD_ID, "gameDurationMinutes")); public static final GameRule MOLE_PERCENTAGE = GameRuleBuilder .forInteger(CONFIG_FILE.getOrDefault("mole_percentage", 25)) .range(0, 100) .category(GameRuleCategory.MISC) - .buildAndRegister(Identifier.of(MOD_ID, "molePercentage")); + .buildAndRegister(Identifier.fromNamespaceAndPath(MOD_ID, "molePercentage")); public static final GameRule MOLE_COUNT = GameRuleBuilder .forInteger(CONFIG_FILE.getOrDefault("mole_count", -1)) .category(GameRuleCategory.MISC) - .buildAndRegister(Identifier.of(MOD_ID, "moleCount")); + .buildAndRegister(Identifier.fromNamespaceAndPath(MOD_ID, "moleCount")); public static final GameRule SHOW_NAMETAGS = GameRuleBuilder .forBoolean(CONFIG_FILE.getOrDefault("show_nametags", false)) .category(GameRuleCategory.MISC) - .buildAndRegister(Identifier.of(MOD_ID, "showNametags")); + .buildAndRegister(Identifier.fromNamespaceAndPath(MOD_ID, "showNametags")); public static final GameRule SHOW_TAB = GameRuleBuilder .forBoolean(CONFIG_FILE.getOrDefault("show_tab", false)) .category(GameRuleCategory.MISC) - .buildAndRegister(Identifier.of(MOD_ID, "showTab")); + .buildAndRegister(Identifier.fromNamespaceAndPath(MOD_ID, "showTab")); public static final GameRule SHOW_SKINS = GameRuleBuilder .forBoolean(CONFIG_FILE.getOrDefault("show_skins", false)) .category(GameRuleCategory.MISC) - .buildAndRegister(Identifier.of(MOD_ID, "showSkins")); + .buildAndRegister(Identifier.fromNamespaceAndPath(MOD_ID, "showSkins")); public static final GameRule INITIAL_WORLD_SIZE = GameRuleBuilder .forInteger(CONFIG_FILE.getOrDefault("initial_world_size", 600)) .minValue(0) .category(GameRuleCategory.MISC) - .buildAndRegister(Identifier.of(MOD_ID, "initialWorldSize")); + .buildAndRegister(Identifier.fromNamespaceAndPath(MOD_ID, "initialWorldSize")); public static final GameRule FINAL_WORLD_SIZE = GameRuleBuilder .forInteger(CONFIG_FILE.getOrDefault("final_world_size", 100)) .minValue(0) .category(GameRuleCategory.MISC) - .buildAndRegister(Identifier.of(MOD_ID, "finalWorldSize")); + .buildAndRegister(Identifier.fromNamespaceAndPath(MOD_ID, "finalWorldSize")); public static final GameRule MOVING_STARTING_TIME_OFFSET = GameRuleBuilder .forInteger(CONFIG_FILE.getOrDefault("border_moving_starting_time_offset", 30)) .minValue(0) .category(GameRuleCategory.MISC) - .buildAndRegister(Identifier.of(MOD_ID, "borderMovingStartingTimeOffsetMinutes")); + .buildAndRegister(Identifier.fromNamespaceAndPath(MOD_ID, "borderMovingStartingTimeOffsetMinutes")); public static final GameRule ENABLE_PORTALS = GameRuleBuilder .forBoolean(CONFIG_FILE.getOrDefault("enable_portals", false)) .category(GameRuleCategory.MISC) - .buildAndRegister(Identifier.of(MOD_ID, "enablePortals")); + .buildAndRegister(Identifier.fromNamespaceAndPath(MOD_ID, "enablePortals")); public static final GameRule FOOD_ON_START = GameRuleBuilder .forBoolean(CONFIG_FILE.getOrDefault("food_on_start", true)) .category(GameRuleCategory.MISC) - .buildAndRegister(Identifier.of(MOD_ID, "foodOnStart")); + .buildAndRegister(Identifier.fromNamespaceAndPath(MOD_ID, "foodOnStart")); public Game game; @@ -126,26 +126,26 @@ public class Molehunt implements ModInitializer { final var command = literal("molehunt"); command.then(literal("start") - .requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK)) + .requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)) .executes(context -> { game = new Game(context.getSource().getServer()); game.start(); return Command.SINGLE_SUCCESS; })); - command.then(literal("timer").requires(ServerCommandSource::isExecutedByPlayer).then( + command.then(literal("timer").requires(CommandSourceStack::isPlayer).then( literal("show").executes(context -> { var player = context.getSource().getPlayer(); assert player != null; - timerVisibility.put(player.getUuid(), true); - context.getSource().sendFeedback(() -> Text.translatable("commands.molehunt.timer.show"), false); + timerVisibility.put(player.getUUID(), true); + context.getSource().sendSuccess(() -> Component.translatable("commands.molehunt.timer.show"), false); if (game == null || !game.started()) { - player.networkHandler.sendPacket(new OverlayMessageS2CPacket( - Text.translatable("commands.molehunt.error.game_not_started").formatted(Formatting.RED) + player.connection.send(new ClientboundSetActionBarTextPacket( + Component.translatable("commands.molehunt.error.game_not_started").withStyle(ChatFormatting.RED) )); } else { - player.networkHandler.sendPacket(new OverlayMessageS2CPacket(Text.of(game.getRemainingText()))); + player.connection.send(new ClientboundSetActionBarTextPacket(Component.translationArg(game.getRemainingText()))); } return Command.SINGLE_SUCCESS; @@ -155,16 +155,16 @@ public class Molehunt implements ModInitializer { var player = context.getSource().getPlayer(); assert player != null; - timerVisibility.put(player.getUuid(), false); - context.getSource().sendFeedback(() -> Text.translatable("commands.molehunt.timer.hide"), false); + timerVisibility.put(player.getUUID(), false); + context.getSource().sendSuccess(() -> Component.translatable("commands.molehunt.timer.hide"), false); return Command.SINGLE_SUCCESS; }) )); command.then(literal("role") - .requires(ServerCommandSource::isExecutedByPlayer) + .requires(CommandSourceStack::isPlayer) .executes(context -> { if (game == null || !game.started()) { - throw (new SimpleCommandExceptionType(Text.translatable("commands.molehunt.error.game_not_started"))).create(); + throw (new SimpleCommandExceptionType(Component.translatable("commands.molehunt.error.game_not_started"))).create(); } final var source = context.getSource(); @@ -172,30 +172,30 @@ public class Molehunt implements ModInitializer { assert player != null; if (game.isMole(player)) { - source.sendFeedback( - () -> Text.translatable("commands.molehunt.role.mole") + source.sendSuccess( + () -> Component.translatable("commands.molehunt.role.mole") .append("\n\n") - .append(Text.translatable("commands.molehunt.role.mole.list", game.getMolesAsString())), + .append(Component.translatable("commands.molehunt.role.mole.list", game.getMolesAsString())), false); } else if (player.isSpectator()) { - source.sendFeedback( - () -> Text.translatable("commands.molehunt.role.survivor.mole_count", game.getMoles().size()), + source.sendSuccess( + () -> Component.translatable("commands.molehunt.role.survivor.mole_count", game.getMoles().size()), false); } else { - source.sendFeedback( - () -> Text.translatable("commands.molehunt.role.survivor") + source.sendSuccess( + () -> Component.translatable("commands.molehunt.role.survivor") .append("\n\n") - .append(Text.translatable("commands.molehunt.role.survivor.mole_count", game.getMoles().size())), + .append(Component.translatable("commands.molehunt.role.survivor.mole_count", game.getMoles().size())), false); } return Command.SINGLE_SUCCESS; })); command.then(literal("stop") - .requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK)) + .requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)) .executes(context -> { if (game == null || !game.started()) { - throw (new SimpleCommandExceptionType(Text.translatable("commands.molehunt.error.game_not_started"))).create(); + throw (new SimpleCommandExceptionType(Component.translatable("commands.molehunt.error.game_not_started"))).create(); } game.stop(); @@ -210,7 +210,7 @@ public class Molehunt implements ModInitializer { ServerMessageEvents.ALLOW_CHAT_MESSAGE.register((message, sender, params) -> false); ServerLivingEntityEvents.AFTER_DEATH.register((entity, damageSource) -> { - if (!(entity instanceof ServerPlayerEntity) || game == null) return; + if (!(entity instanceof ServerPlayer) || game == null) return; if (!game.started()) return; if (game.wonByMoles()) game.end(); }); @@ -218,7 +218,7 @@ public class Molehunt implements ModInitializer { ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> { if (game == null) return; if (!game.started()) return; - newPlayer.changeGameMode(GameMode.SPECTATOR); + newPlayer.setGameMode(GameType.SPECTATOR); }); ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { @@ -232,7 +232,7 @@ public class Molehunt implements ModInitializer { ); }); - PayloadTypeRegistry.playS2C().register(ConfigPayload.ID, ConfigPayload.CODEC); - PayloadTypeRegistry.playS2C().register(GamePayload.ID, GamePayload.CODEC); + PayloadTypeRegistry.clientboundPlay().register(ConfigPayload.ID, ConfigPayload.CODEC); + PayloadTypeRegistry.clientboundPlay().register(GamePayload.ID, GamePayload.CODEC); } } diff --git a/src/main/java/world/anhgelus/molehunt/config/Config.java b/src/main/java/world/anhgelus/molehunt/config/Config.java index 08c3850..c9d04af 100644 --- a/src/main/java/world/anhgelus/molehunt/config/Config.java +++ b/src/main/java/world/anhgelus/molehunt/config/Config.java @@ -16,56 +16,56 @@ public class Config { public void sendConfigPayload() { final var payload = new ConfigPayload(nametagsEnabled(), skinsEnabled(), tabEnabled()); - server.getPlayerManager().getPlayerList().forEach(p -> ServerPlayNetworking.send(p, payload)); + server.getPlayerList().getPlayers().forEach(p -> ServerPlayNetworking.send(p, payload)); } public void sendConfigPayload(boolean showNametags, boolean showSkins, boolean showTab) { final var payload = new ConfigPayload(showNametags, showSkins, showTab); - server.getPlayerManager().getPlayerList().forEach(p -> ServerPlayNetworking.send(p, payload)); + server.getPlayerList().getPlayers().forEach(p -> ServerPlayNetworking.send(p, payload)); } public int getGameDuration() { - return server.getOverworld().getGameRules().getValue(Molehunt.GAME_DURATION); + return server.overworld().getGameRules().get(Molehunt.GAME_DURATION); } public int getMolePercentage() { - return server.getOverworld().getGameRules().getValue(Molehunt.MOLE_PERCENTAGE); + return server.overworld().getGameRules().get(Molehunt.MOLE_PERCENTAGE); } public int getMoleCount() { - return server.getOverworld().getGameRules().getValue(Molehunt.MOLE_COUNT); + return server.overworld().getGameRules().get(Molehunt.MOLE_COUNT); } public boolean nametagsEnabled() { - return server.getOverworld().getGameRules().getValue(Molehunt.SHOW_NAMETAGS); + return server.overworld().getGameRules().get(Molehunt.SHOW_NAMETAGS); } public boolean skinsEnabled() { - return server.getOverworld().getGameRules().getValue(Molehunt.SHOW_SKINS); + return server.overworld().getGameRules().get(Molehunt.SHOW_SKINS); } public boolean tabEnabled() { - return server.getOverworld().getGameRules().getValue(Molehunt.SHOW_TAB); + return server.overworld().getGameRules().get(Molehunt.SHOW_TAB); } public int getInitialWorldSize() { - return server.getOverworld().getGameRules().getValue(Molehunt.INITIAL_WORLD_SIZE); + return server.overworld().getGameRules().get(Molehunt.INITIAL_WORLD_SIZE); } public int getFinalWorldSize() { - return server.getOverworld().getGameRules().getValue(Molehunt.FINAL_WORLD_SIZE); + return server.overworld().getGameRules().get(Molehunt.FINAL_WORLD_SIZE); } public int getBorderShrinkingStartingTimeOffset() { - return server.getOverworld().getGameRules().getValue(Molehunt.MOVING_STARTING_TIME_OFFSET); + return server.overworld().getGameRules().get(Molehunt.MOVING_STARTING_TIME_OFFSET); } public boolean portalsEnabled() { - return server.getOverworld().getGameRules().getValue(Molehunt.ENABLE_PORTALS); + return server.overworld().getGameRules().get(Molehunt.ENABLE_PORTALS); } public boolean foodOnStart() { - return server.getOverworld().getGameRules().getValue(Molehunt.FOOD_ON_START); + return server.overworld().getGameRules().get(Molehunt.FOOD_ON_START); } public static SimpleConfig configFile(String fileName) { diff --git a/src/main/java/world/anhgelus/molehunt/config/ConfigPayload.java b/src/main/java/world/anhgelus/molehunt/config/ConfigPayload.java index b43bd1b..4c8fcdb 100644 --- a/src/main/java/world/anhgelus/molehunt/config/ConfigPayload.java +++ b/src/main/java/world/anhgelus/molehunt/config/ConfigPayload.java @@ -1,25 +1,25 @@ package world.anhgelus.molehunt.config; -import net.minecraft.network.RegistryByteBuf; -import net.minecraft.network.codec.PacketCodec; -import net.minecraft.network.codec.PacketCodecs; -import net.minecraft.network.packet.CustomPayload; -import net.minecraft.util.Identifier; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; import world.anhgelus.molehunt.Molehunt; -public record ConfigPayload(boolean showNametags, boolean showSkins, boolean showTab) implements CustomPayload { - public static final Identifier CONFIG_PACKET_ID = Identifier.of(Molehunt.MOD_ID, "config"); +public record ConfigPayload(boolean showNametags, boolean showSkins, boolean showTab) implements CustomPacketPayload { + public static final Identifier CONFIG_PACKET_ID = Identifier.fromNamespaceAndPath(Molehunt.MOD_ID, "config"); - public static final CustomPayload.Id ID = new CustomPayload.Id<>(CONFIG_PACKET_ID); - public static final PacketCodec CODEC = PacketCodec.tuple( - PacketCodecs.BOOLEAN, ConfigPayload::showNametags, - PacketCodecs.BOOLEAN, ConfigPayload::showSkins, - PacketCodecs.BOOLEAN, ConfigPayload::showTab, + public static final CustomPacketPayload.Type ID = new CustomPacketPayload.Type<>(CONFIG_PACKET_ID); + public static final StreamCodec CODEC = StreamCodec.composite( + ByteBufCodecs.BOOL, ConfigPayload::showNametags, + ByteBufCodecs.BOOL, ConfigPayload::showSkins, + ByteBufCodecs.BOOL, ConfigPayload::showTab, ConfigPayload::new ); @Override - public Id getId() { + public Type type() { return ID; } } diff --git a/src/main/java/world/anhgelus/molehunt/game/Game.java b/src/main/java/world/anhgelus/molehunt/game/Game.java index 98fe2b8..d95d211 100644 --- a/src/main/java/world/anhgelus/molehunt/game/Game.java +++ b/src/main/java/world/anhgelus/molehunt/game/Game.java @@ -1,19 +1,19 @@ package world.anhgelus.molehunt.game; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket; -import net.minecraft.network.packet.s2c.play.SubtitleS2CPacket; -import net.minecraft.network.packet.s2c.play.TitleFadeS2CPacket; -import net.minecraft.network.packet.s2c.play.TitleS2CPacket; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket; +import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket; +import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket; +import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; -import net.minecraft.world.GameMode; -import net.minecraft.world.rule.GameRules; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.GameType; +import net.minecraft.world.level.gamerules.GameRules; import world.anhgelus.molehunt.Molehunt; import world.anhgelus.molehunt.timer.TickTask; import world.anhgelus.molehunt.timer.TimerAccess; @@ -25,12 +25,12 @@ import java.util.stream.Collectors; public class Game { - public final int defaultTime = Molehunt.CONFIG.getGameDuration() * 60; + public final int DEFAULT_TIME = Molehunt.CONFIG.getGameDuration() * 60; private final MinecraftServer server; private final List moles = new ArrayList<>(); - private final TitleFadeS2CPacket timing = new TitleFadeS2CPacket(20, 40, 20); - private int remaining = defaultTime; + private final ClientboundSetTitlesAnimationPacket timing = new ClientboundSetTitlesAnimationPacket(20, 40, 20); private boolean started = false; + private int remaining = DEFAULT_TIME; public Game(MinecraftServer server) { this.server = server; @@ -38,33 +38,32 @@ public class Game { public void start() { final int n = Molehunt.CONFIG.getMoleCount() < 0 - ? Math.floorDiv(server.getCurrentPlayerCount(), Math.floorDiv(100, Molehunt.CONFIG.getMolePercentage())) + ? Math.floorDiv(server.getPlayerCount(), Math.floorDiv(100, Molehunt.CONFIG.getMolePercentage())) : Molehunt.CONFIG.getMoleCount(); - final var playerManager = server.getPlayerManager(); + final var playerManager = server.getPlayerList(); - final var players = new ArrayList<>(playerManager.getPlayerList()); + final var players = new ArrayList<>(playerManager.getPlayers()); for (int i = 0; i < n && !players.isEmpty(); i++) { final var r = ThreadLocalRandom.current().nextInt(0, players.size()); final var mole = players.get(r); - if (mole == null) throw new IllegalStateException("Mole is null!"); - moles.add(mole.getUuid()); + moles.add(mole.getUUID()); players.remove(r); } - final var gamerules = server.getOverworld().getGameRules(); + final var gamerules = server.overworld().getGameRules(); // immutable gamerules - gamerules.setValue(GameRules.SHOW_DEATH_MESSAGES, false, server); - gamerules.setValue(GameRules.ANNOUNCE_ADVANCEMENTS, false, server); + gamerules.set(GameRules.SHOW_DEATH_MESSAGES, false, server); + gamerules.set(GameRules.SHOW_ADVANCEMENT_MESSAGES, false, server); // gamerules for the start - gamerules.setValue(GameRules.DO_IMMEDIATE_RESPAWN, true, server); + gamerules.set(GameRules.IMMEDIATE_RESPAWN, true, server); final var timer = TimerAccess.getTimerFromOverworld(server); - final var worldBorder = server.getOverworld().getWorldBorder(); + final var worldBorder = server.overworld().getWorldBorder(); worldBorder.setSize(Molehunt.CONFIG.getInitialWorldSize()); if (Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset() < Molehunt.CONFIG.getGameDuration()) { - timer.dds_runTask(new TickTask(() -> worldBorder.interpolateSize( + timer.dds_runTask(new TickTask(() -> worldBorder.lerpSizeBetween( Molehunt.CONFIG.getInitialWorldSize(), Molehunt.CONFIG.getFinalWorldSize(), (long) (Molehunt.CONFIG.getGameDuration() - Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset()) * 60 * 1000, @@ -72,54 +71,56 @@ public class Game { ), (long) Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset() * 60 * 1000)); } - final var title = new TitleS2CPacket(Text.translatable("molehunt.game.start.suspense")); - playerManager.getPlayerList().forEach(p -> { - p.getInventory().clear(); - p.kill(p.getEntityWorld()); - p.networkHandler.sendPacket(timing); - p.networkHandler.sendPacket(title); - p.changeGameMode(GameMode.SURVIVAL); - if (Molehunt.CONFIG.foodOnStart()) p.giveItemStack(new ItemStack(Items.COOKED_BEEF, 64)); + final var title = new ClientboundSetTitleTextPacket(Component.translatable("molehunt.game.start.suspense")); + playerManager.getPlayers().forEach(p -> { + p.getInventory().clearContent(); + p.kill(p.level()); + p.connection.send(timing); + p.connection.send(title); + p.setGameMode(GameType.SURVIVAL); + if (Molehunt.CONFIG.foodOnStart()) p.addItem(new ItemStack(Items.COOKED_BEEF, 64)); }); - server.setDefaultGameMode(GameMode.SPECTATOR); + server.setDefaultGameType(GameType.SPECTATOR); timer.dds_runTask(new TickTask(() -> { - playerManager.getPlayerList().forEach(p -> { - p.networkHandler.sendPacket(timing); - if (moles.contains(p.getUuid())) { - p.networkHandler.sendPacket(new TitleS2CPacket(Text.translatable("molehunt.game.start.mole.title"))); - p.networkHandler.sendPacket(new SubtitleS2CPacket(Text.translatable("molehunt.game.start.mole.subtitle"))); + playerManager.getPlayers().forEach(p -> { + p.connection.send(timing); + if (moles.contains(p.getUUID())) { + p.connection.send(new ClientboundSetTitleTextPacket(Component.translatable("molehunt.game.start.mole.title"))); + p.connection.send(new ClientboundSetSubtitleTextPacket(Component.translatable("molehunt.game.start.mole.subtitle"))); } else { - p.networkHandler.sendPacket(new TitleS2CPacket(Text.translatable("molehunt.game.start.survivor.title"))); - p.networkHandler.sendPacket(new SubtitleS2CPacket(Text.translatable("molehunt.game.start.survivor.subtitle"))); + p.connection.send(new ClientboundSetTitleTextPacket(Component.translatable("molehunt.game.start.survivor.title"))); + p.connection.send(new ClientboundSetSubtitleTextPacket(Component.translatable("molehunt.game.start.survivor.subtitle"))); } // reset health and food level p.setHealth(p.getMaxHealth()); - p.getHungerManager().setFoodLevel(20); - p.getHungerManager().setSaturationLevel(5.0f); + p.getFoodData().setFoodLevel(20); + p.getFoodData().setSaturation(5.0f); }); // reset gamerules after the start - gamerules.setValue(GameRules.DO_IMMEDIATE_RESPAWN, false, server); + gamerules.set(GameRules.IMMEDIATE_RESPAWN, false, server); // reset time and weather - server.getOverworld().setTimeOfDay(0); - server.getOverworld().resetWeather(); + final var overworld = server.overworld(); + server.clockManager() + .setTotalTicks(overworld.getLevel().dimensionType().defaultClock().orElseThrow(), 0); + overworld.resetWeatherCycle(); changeState(true); timer.dds_runTask(new TickTask(() -> { remaining--; - playerManager.getPlayerList().forEach(player -> { - if (Molehunt.timerVisibility.getOrDefault(player.getUuid(), true)) { - player.networkHandler.sendPacket(new OverlayMessageS2CPacket(Text.of(getRemainingText()))); + playerManager.getPlayers().forEach(player -> { + if (Molehunt.timerVisibility.getOrDefault(player.getUUID(), true)) { + player.connection.send(new ClientboundSetActionBarTextPacket(Component.translationArg(getRemainingText()))); } }); - playerManager.sendToAll(timing); + playerManager.broadcastAll(timing); if (remaining == 0) end(); }, 5 * 1000, 1000)); }, 4 * 1000)); } public void stop() { - server.getPlayerManager().broadcast(Text.translatable("commands.molehunt.stop.success"), false); + server.getPlayerList().broadcastSystemMessage(Component.translatable("commands.molehunt.stop.success"), false); end(); } @@ -127,39 +128,40 @@ public class Game { final var timer = TimerAccess.getTimerFromOverworld(server); timer.dds_cancel(); - final var worldBorder = server.getOverworld().getWorldBorder(); + final var worldBorder = server.overworld().getWorldBorder(); // Stops the border shrinking. worldBorder.setSize(worldBorder.getSize()); changeState(false); - final var pm = server.getPlayerManager(); - final var winnerSuspense = new TitleS2CPacket(Text.translatable("molehunt.game.end.suspense.title")); - pm.getPlayerList().forEach(p -> { - p.networkHandler.sendPacket(timing); - p.networkHandler.sendPacket(winnerSuspense); - p.changeGameMode(GameMode.CREATIVE); + final var pm = server.getPlayerList(); + final var winnerSuspense = new ClientboundSetTitleTextPacket(Component.translatable("molehunt.game.end.suspense.title")); + pm.getPlayers().forEach(p -> { + p.connection.send(timing); + p.connection.send(winnerSuspense); + p.setGameMode(GameType.CREATIVE); }); + timer.dds_runTask(new TickTask(() -> { - TitleS2CPacket winner; + ClientboundSetTitleTextPacket winner; if (wonByMoles()) { - winner = new TitleS2CPacket(Text.translatable("molehunt.game.end.winners.moles.title")); + winner = new ClientboundSetTitleTextPacket(Component.translatable("molehunt.game.end.winners.moles.title")); } else { - winner = new TitleS2CPacket(Text.translatable("molehunt.game.end.winners.survivors.title")); + winner = new ClientboundSetTitleTextPacket(Component.translatable("molehunt.game.end.winners.survivors.title")); } - pm.sendToAll(new SubtitleS2CPacket(Text.translatable("molehunt.game.end.winners.subtitle", getMolesAsString()))); - pm.sendToAll(winner); - pm.sendToAll(timing); + pm.broadcastAll(new ClientboundSetSubtitleTextPacket(Component.translatable("molehunt.game.end.winners.subtitle", getMolesAsString()))); + pm.broadcastAll(winner); + pm.broadcastAll(timing); moles.clear(); }, 4 * 1000)); } - public Text getRemainingText() { - return Text.of("§c" + TimeUtils.generateShortString(remaining)); + public Component getRemainingText() { + return Component.nullToEmpty("§c" + TimeUtils.generateShortString(remaining)); } - public List getMoles() { + public List getMoles() { return moles.stream() - .map(uuid -> server.getPlayerManager().getPlayer(uuid)) + .map(uuid -> server.getPlayerList().getPlayer(uuid)) .filter(Objects::nonNull) .filter(p -> !p.isSpectator()) .toList(); @@ -167,23 +169,22 @@ public class Game { public String getMolesAsString() { return getMoles().stream() - .map(PlayerEntity::getDisplayName) - .filter(Objects::nonNull) + .map(Player::getDisplayName) .map(Object::toString) .collect(Collectors.joining(", ")); } - public boolean isMole(ServerPlayerEntity player) { - return moles.contains(player.getUuid()); + public boolean isMole(ServerPlayer player) { + return moles.contains(player.getUUID()); } public boolean wonByMoles() { return new HashSet<>(moles).containsAll( - server.getPlayerManager() - .getPlayerList() + server.getPlayerList() + .getPlayers() .stream() .filter(p -> !p.isSpectator() && !p.isCreative()) - .map(Entity::getUuid) + .map(Entity::getUUID) .toList() ); } @@ -195,6 +196,6 @@ public class Game { private void changeState(boolean hasStarted) { started = hasStarted; final var payload = new GamePayload(hasStarted); - server.getPlayerManager().getPlayerList().forEach(p -> ServerPlayNetworking.send(p, payload)); + server.getPlayerList().getPlayers().forEach(p -> ServerPlayNetworking.send(p, payload)); } } diff --git a/src/main/java/world/anhgelus/molehunt/game/GamePayload.java b/src/main/java/world/anhgelus/molehunt/game/GamePayload.java index 66e3209..f611385 100644 --- a/src/main/java/world/anhgelus/molehunt/game/GamePayload.java +++ b/src/main/java/world/anhgelus/molehunt/game/GamePayload.java @@ -1,23 +1,23 @@ package world.anhgelus.molehunt.game; -import net.minecraft.network.RegistryByteBuf; -import net.minecraft.network.codec.PacketCodec; -import net.minecraft.network.codec.PacketCodecs; -import net.minecraft.network.packet.CustomPayload; -import net.minecraft.util.Identifier; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; import world.anhgelus.molehunt.Molehunt; -public record GamePayload(boolean gameLaunched) implements CustomPayload { - public static final Identifier GAME_PACKET_ID = Identifier.of(Molehunt.MOD_ID, "game"); +public record GamePayload(boolean gameLaunched) implements CustomPacketPayload { + public static final Identifier GAME_PACKET_ID = Identifier.fromNamespaceAndPath(Molehunt.MOD_ID, "game"); - public static final CustomPayload.Id ID = new CustomPayload.Id<>(GAME_PACKET_ID); - public static final PacketCodec CODEC = PacketCodec.tuple( - PacketCodecs.BOOLEAN, GamePayload::gameLaunched, + public static final CustomPacketPayload.Type ID = new CustomPacketPayload.Type<>(GAME_PACKET_ID); + public static final StreamCodec CODEC = StreamCodec.composite( + ByteBufCodecs.BOOL, GamePayload::gameLaunched, GamePayload::new ); @Override - public Id getId() { + public Type type() { return ID; } } diff --git a/src/main/java/world/anhgelus/molehunt/mixin/NoJoinLeaveMessage.java b/src/main/java/world/anhgelus/molehunt/mixin/NoJoinLeaveMessage.java index a82a21e..0771981 100644 --- a/src/main/java/world/anhgelus/molehunt/mixin/NoJoinLeaveMessage.java +++ b/src/main/java/world/anhgelus/molehunt/mixin/NoJoinLeaveMessage.java @@ -1,18 +1,18 @@ package world.anhgelus.molehunt.mixin; -import net.minecraft.server.PlayerManager; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.server.players.PlayerList; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(PlayerManager.class) +@Mixin(PlayerList.class) public class NoJoinLeaveMessage { - @Inject(at = @At("HEAD"), method = "broadcast*", cancellable = true) - public void broadcastNoJoinLeaveMessage(Text message, boolean overlay, CallbackInfo ci) { - final var content = message.getContent().toString(); - if (content.startsWith("translation{key='multiplayer.player.joined")) ci.cancel(); - else if (content.startsWith("translation{key='multiplayer.player.left")) ci.cancel(); + @Inject(at = @At("HEAD"), method = "broadcastSystemMessage*", cancellable = true) + public void broadcastNoJoinLeaveMessage(final Component message, final boolean overlay, CallbackInfo ci) { + final var content = message.getContents().toString(); + if (content.startsWith("translation{key='multiplayer.player.joined") || + content.startsWith("translation{key='multiplayer.player.left")) ci.cancel(); } } diff --git a/src/main/java/world/anhgelus/molehunt/mixin/NoMsgCommand.java b/src/main/java/world/anhgelus/molehunt/mixin/NoMsgCommand.java index 2727143..b68773e 100644 --- a/src/main/java/world/anhgelus/molehunt/mixin/NoMsgCommand.java +++ b/src/main/java/world/anhgelus/molehunt/mixin/NoMsgCommand.java @@ -1,17 +1,17 @@ package world.anhgelus.molehunt.mixin; import com.mojang.brigadier.CommandDispatcher; -import net.minecraft.server.command.MessageCommand; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.commands.MsgCommand; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(MessageCommand.class) +@Mixin(MsgCommand.class) public class NoMsgCommand { @Inject(at = @At("HEAD"), method = "register", cancellable = true) - private static void register(CommandDispatcher dispatcher, CallbackInfo ci) { + private static void register(CommandDispatcher dispatcher, CallbackInfo ci) { ci.cancel(); } } diff --git a/src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java b/src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java index a71e6d1..74504fe 100644 --- a/src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java +++ b/src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java @@ -1,18 +1,18 @@ package world.anhgelus.molehunt.mixin; -import net.minecraft.entity.Entity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.world.dimension.PortalManager; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.PortalProcessor; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import world.anhgelus.molehunt.Molehunt; -@Mixin(PortalManager.class) +@Mixin(PortalProcessor.class) public class NoPortals { - @Inject(at = @At("HEAD"), method = "tick", cancellable = true) - public void disableTick(ServerWorld world, Entity entity, boolean canUsePortals, CallbackInfoReturnable cir) { + @Inject(at = @At("HEAD"), method = "processPortalTeleportation", cancellable = true) + public void disableTick(ServerLevel world, Entity entity, boolean canUsePortals, CallbackInfoReturnable cir) { if (Molehunt.CONFIG == null || Molehunt.CONFIG.portalsEnabled()) return; cir.setReturnValue(false); } -- cgit v1.2.3