From 57c83485e1db1513fa204c3ef5a0d81176995490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Kosman?= Date: Sat, 24 Aug 2024 13:25:56 +0200 Subject: feat: set and shrink world borders --- src/main/java/world/anhgelus/molehunt/Game.java | 24 ++++++++++++++++++++++ .../world/anhgelus/molehunt/config/Config.java | 1 + 2 files changed, 25 insertions(+) (limited to 'src/main/java/world/anhgelus') diff --git a/src/main/java/world/anhgelus/molehunt/Game.java b/src/main/java/world/anhgelus/molehunt/Game.java index dbe7ebd..b6c0338 100644 --- a/src/main/java/world/anhgelus/molehunt/Game.java +++ b/src/main/java/world/anhgelus/molehunt/Game.java @@ -21,6 +21,8 @@ public class Game { public final int defaultTime = Molehunt.CONFIG.getGameDuration()*60; private int remaining = defaultTime; + private Timer borderTimeOffsetTime = new Timer(); + private final MinecraftServer server; private final List moles = new ArrayList<>(); @@ -57,6 +59,20 @@ public class Game { gamerules.get(GameRules.DO_IMMEDIATE_RESPAWN).set(true, server); gamerules.get(GameRules.DO_ENTITY_DROPS).set(false, server); + final var worldBorder = server.getOverworld().getWorldBorder(); + worldBorder.setSize(Molehunt.CONFIG.getInitialWorldSize()); + if (Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset() < Molehunt.CONFIG.getGameDuration()) { + borderTimeOffsetTime.schedule(new TimerTask() { + @Override + public void run() { + worldBorder.interpolateSize( + Molehunt.CONFIG.getInitialWorldSize(), + Molehunt.CONFIG.getFinalWorldSize(), + (long) (Molehunt.CONFIG.getGameDuration() - Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset()) * 60 * 60); + } + }, (long) Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset() * 60 * 60); + } + final var title = new TitleS2CPacket(Text.translatable("molehunt.game.start.suspense")); playerManager.getPlayerList().forEach(p -> { p.kill(); @@ -116,6 +132,14 @@ public class Game { public void end() { timer.cancel(); timer = new Timer(); + + borderTimeOffsetTime.cancel(); + borderTimeOffsetTime = new Timer(); + + final var worldBorder = server.getOverworld().getWorldBorder(); + // Stops the border shrinking. + worldBorder.setSize(worldBorder.getSize()); + started = false; final var pm = server.getPlayerManager(); final var winnerSuspense = new TitleS2CPacket(Text.translatable("molehunt.game.end.suspense.title")); diff --git a/src/main/java/world/anhgelus/molehunt/config/Config.java b/src/main/java/world/anhgelus/molehunt/config/Config.java index b42a469..3f22df3 100644 --- a/src/main/java/world/anhgelus/molehunt/config/Config.java +++ b/src/main/java/world/anhgelus/molehunt/config/Config.java @@ -114,6 +114,7 @@ public class Config { # Shrinking starting offset (in minutes) # The time before starting to shrink the world borders. + # If this value is greater than the game duration, borders will never shrink. # Default: 10 minutes. border_shrinking_starting_time_offset = 10 """; -- cgit v1.2.3