diff options
| author | Léo Kosman <leo.kosman@proton.me> | 2024-08-24 13:25:56 +0200 |
|---|---|---|
| committer | Léo Kosman <leo.kosman@proton.me> | 2024-08-24 13:29:33 +0200 |
| commit | 57c83485e1db1513fa204c3ef5a0d81176995490 (patch) | |
| tree | eb87c72b82c7cf4751c995718237358332b323ae | |
| parent | f59f9bdfadfb804e804cbafc168af82817f334f6 (diff) | |
feat: set and shrink world borders
| -rw-r--r-- | src/main/java/world/anhgelus/molehunt/Game.java | 24 | ||||
| -rw-r--r-- | src/main/java/world/anhgelus/molehunt/config/Config.java | 1 |
2 files changed, 25 insertions, 0 deletions
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<ServerPlayerEntity> 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 """; |
