diff options
| author | Léo Kosman <leo.kosman@proton.me> | 2024-08-25 00:13:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-25 00:13:06 +0200 |
| commit | 5c0617cd3de4e786b3643e67bf610d5349164243 (patch) | |
| tree | 8fe51eefb34ee634be663f43caa4a3525a934104 /src/main/java/world/anhgelus | |
| parent | f9702feda784bfe7fef3cb8b8d0ddb420010ea5b (diff) | |
| parent | a243d9c2d8847ab4b95b56d4496ee2e301c75f48 (diff) | |
Merge pull request #6 from anhgelus/feat/world-borders
[Feat] World borders
Diffstat (limited to 'src/main/java/world/anhgelus')
| -rw-r--r-- | src/main/java/world/anhgelus/molehunt/Molehunt.java | 17 | ||||
| -rw-r--r-- | src/main/java/world/anhgelus/molehunt/config/Config.java | 39 | ||||
| -rw-r--r-- | src/main/java/world/anhgelus/molehunt/game/Game.java | 23 |
3 files changed, 74 insertions, 5 deletions
diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index afd6960..52399dc 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -41,7 +41,7 @@ public class Molehunt implements ModInitializer { public static final SimpleConfig CONFIG_FILE = Config.configFile(MOD_ID); public static final GameRules.Key<GameRules.IntRule> GAME_DURATION = GameRuleRegistry.register( - MOD_ID +":gameDuration", + MOD_ID +":gameDurationMinutes", GameRules.Category.MISC, GameRuleFactory.createIntRule(CONFIG_FILE.getOrDefault("game_duration", 90)) ); @@ -79,6 +79,21 @@ public class Molehunt implements ModInitializer { CONFIG.sendConfigPayload(); }) ); + public static final GameRules.Key<GameRules.IntRule> INITIAL_WORLD_SIZE = GameRuleRegistry.register( + MOD_ID +":initialWorldSize", + GameRules.Category.MISC, + GameRuleFactory.createIntRule(CONFIG_FILE.getOrDefault("initial_world_size", 200), 0) + ); + public static final GameRules.Key<GameRules.IntRule> FINAL_WORLD_SIZE = GameRuleRegistry.register( + MOD_ID +":finalWorldSize", + GameRules.Category.MISC, + GameRuleFactory.createIntRule(CONFIG_FILE.getOrDefault("final_world_size", 50), 0) + ); + public static final GameRules.Key<GameRules.IntRule> MOVING_STARTING_TIME_OFFSET = GameRuleRegistry.register( + MOD_ID +":borderMovingStartingTimeOffsetMinutes", + GameRules.Category.MISC, + GameRuleFactory.createIntRule(CONFIG_FILE.getOrDefault("border_moving_starting_time_offset", 10), 0) + ); public Game game; diff --git a/src/main/java/world/anhgelus/molehunt/config/Config.java b/src/main/java/world/anhgelus/molehunt/config/Config.java index dbaebcf..e1c84a4 100644 --- a/src/main/java/world/anhgelus/molehunt/config/Config.java +++ b/src/main/java/world/anhgelus/molehunt/config/Config.java @@ -16,9 +16,7 @@ public class Config { public void sendConfigPayload() { final var payload = new ConfigPayload(areNametagsEnabled(), areSkinsEnabled(), isTabEnabled()); - server.getPlayerManager().getPlayerList().forEach(p -> { - ServerPlayNetworking.send(p, payload); - }); + server.getPlayerManager().getPlayerList().forEach(p -> ServerPlayNetworking.send(p, payload)); } public void sendConfigPayload(boolean showNametags, boolean showSkins, boolean showTab) { @@ -50,6 +48,18 @@ public class Config { return server.getGameRules().getBoolean(Molehunt.SHOW_TAB); } + public int getInitialWorldSize() { + return server.getGameRules().getInt(Molehunt.INITIAL_WORLD_SIZE); + } + + public int getFinalWorldSize() { + return server.getGameRules().getInt(Molehunt.FINAL_WORLD_SIZE); + } + + public int getBorderShrinkingStartingTimeOffset() { + return server.getGameRules().getInt(Molehunt.MOVING_STARTING_TIME_OFFSET); + } + public static SimpleConfig configFile(String fileName) { return SimpleConfig.of(fileName).provider(Config::defaultConfig).request(); } @@ -57,7 +67,10 @@ public class Config { private static String defaultConfig(String s) { return """ # Molehunt mod configuration file + # To regenerate the default configuration, delete, move or rename this file. + # Game settings + # The duration of a molehunt game, in minutes. # Default: 90 minutes (1 hour 30 minutes). game_duration = 90 @@ -73,6 +86,9 @@ public class Config { # Default: -1. mole_count = -1 + + # Client-side settings (applies to all players) + # Show nametags # Default: false show_nametags = false @@ -84,6 +100,23 @@ public class Config { # Show tab # Default: false show_tab = false + + + # World border settings : + + # Initial world size (in blocks). + # Default: 200 blocks. + initial_world_size = 200 + + # Final world size (in blocks). + # Default: 50 blocks. + final_world_size = 50 + + # Moving starting time offset (in minutes) + # The time before starting to move the world borders. + # If this value is greater than the game duration, borders will never move. + # Default: 10 minutes. + border_moving_starting_time_offset = 10 """; } } diff --git a/src/main/java/world/anhgelus/molehunt/game/Game.java b/src/main/java/world/anhgelus/molehunt/game/Game.java index a98516c..a2fdfbb 100644 --- a/src/main/java/world/anhgelus/molehunt/game/Game.java +++ b/src/main/java/world/anhgelus/molehunt/game/Game.java @@ -59,6 +59,21 @@ 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()) {
+ timer.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ final var worldBorder = server.getOverworld().getWorldBorder();
+ worldBorder.interpolateSize(
+ Molehunt.CONFIG.getInitialWorldSize(),
+ Molehunt.CONFIG.getFinalWorldSize(),
+ (long) (Molehunt.CONFIG.getGameDuration() - Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset()) * 60 * 1000);
+ }
+ }, (long) Molehunt.CONFIG.getBorderShrinkingStartingTimeOffset() * 60 * 1000);
+ }
+
final var title = new TitleS2CPacket(Text.translatable("molehunt.game.start.suspense"));
playerManager.getPlayerList().forEach(p -> {
p.kill();
@@ -78,7 +93,8 @@ public class Game { p.networkHandler.sendPacket(new TitleS2CPacket(Text.translatable("molehunt.game.start.mole.title")));
p.networkHandler.sendPacket(new SubtitleS2CPacket(Text.translatable("molehunt.game.start.mole.subtitle")));
} else {
- p.networkHandler.sendPacket(new TitleS2CPacket(Text.translatable("molehunt.game.start.survivor")));
+ p.networkHandler.sendPacket(new TitleS2CPacket(Text.translatable("molehunt.game.start.survivor.title")));
+ p.networkHandler.sendPacket(new SubtitleS2CPacket(Text.translatable("molehunt.game.start.survivor.subtitle")));
}
// reset health and food level
p.setHealth(p.getMaxHealth());
@@ -118,6 +134,11 @@ public class Game { public void end() {
timer.cancel();
timer = new Timer();
+
+ final var worldBorder = server.getOverworld().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"));
|
