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 | |
| parent | f9702feda784bfe7fef3cb8b8d0ddb420010ea5b (diff) | |
| parent | a243d9c2d8847ab4b95b56d4496ee2e301c75f48 (diff) | |
Merge pull request #6 from anhgelus/feat/world-borders
[Feat] World borders
Diffstat (limited to 'src')
5 files changed, 96 insertions, 19 deletions
diff --git a/src/client/resources/assets/molehunt/lang/en_us.json b/src/client/resources/assets/molehunt/lang/en_us.json index 3a50d81..5896c03 100644 --- a/src/client/resources/assets/molehunt/lang/en_us.json +++ b/src/client/resources/assets/molehunt/lang/en_us.json @@ -12,11 +12,15 @@ "molehunt.game.start.suspense": "§eYou are...", "molehunt.game.start.mole.title": "§cThe Mole!", "molehunt.game.start.mole.subtitle": "§eGet the list of moles with §6/molehunt moles", - "molehunt.game.start.survivor": "§aNot the Mole!", - "gamerule.molehunt:gameDuration": "Duration of a game", - "gamerule.molehunt:molePercentage": "Percentage of Mole", - "gamerule.molehunt:moleCount": "Number of Mole", - "gamerule.molehunt:showNametags": "Show players' nametag", - "gamerule.molehunt:showTab": "Enable the tab", - "gamerule.molehunt:showSkins": "Show players' skin" + "molehunt.game.start.survivor.title": "§aNot the Mole!", + "molehunt.game.start.survivor.subtitle": "§eTry to survive and find out who's the mole!", + "gamerule.molehunt:gameDuration": "Molehunt: Duration of a game", + "gamerule.molehunt:molePercentage": "Molehunt: Percentage of Mole", + "gamerule.molehunt:moleCount": "Molehunt: Number of Mole", + "gamerule.molehunt:showNametags": "Molehunt: Show players' nametag", + "gamerule.molehunt:showTab": "Molehunt: Enable the tab", + "gamerule.molehunt:showSkins": "Molehunt: Show players' skin", + "gamerule.molehunt:initialWorldSize": "Molehunt: Initial world size", + "gamerule.molehunt:finalWorldSize": "Molehunt: Final world size", + "gamerule.molehunt:borderMovingStartingTimeOffsetMinutes": "Molehunt: Time before moving the borders" }
\ No newline at end of file diff --git a/src/client/resources/assets/molehunt/lang/fr_fr.json b/src/client/resources/assets/molehunt/lang/fr_fr.json index bb73ca8..42b4722 100644 --- a/src/client/resources/assets/molehunt/lang/fr_fr.json +++ b/src/client/resources/assets/molehunt/lang/fr_fr.json @@ -12,11 +12,15 @@ "molehunt.game.start.suspense": "§eVous êtes...", "molehunt.game.start.mole.title": "§cLa Taupe !", "molehunt.game.start.mole.subtitle": "§eRécupérer la liste des taupes avec §6/molehunt moles", - "molehunt.game.start.survivor": "§aPas la Taupe!", - "gamerule.molehunt:gameDuration": "Durée d'une partie", - "gamerule.molehunt:molePercentage": "Pourcentage de Taupes", - "gamerule.molehunt:moleCount": "Nombre de Taupes", - "gamerule.molehunt:showNametags": "Affiche les nametags des joueurs", - "gamerule.molehunt:showTab": "Active le tab", - "gamerule.molehunt:showSkins": "Affiche les skins des joueurs" + "molehunt.game.start.survivor.title": "§aPas la taupe!", + "molehunt.game.start.survivor.subtitle": "§eEssaye de survivre et de trouver qui est la taupe !", + "gamerule.molehunt:gameDuration": "Molehunt : Durée d'une partie", + "gamerule.molehunt:molePercentage": "Molehunt : Pourcentage de Taupes", + "gamerule.molehunt:moleCount": "Molehunt : Nombre de Taupes", + "gamerule.molehunt:showNametags": "Molehunt : Affiche les nametags des joueurs", + "gamerule.molehunt:showTab": "Molehunt : Active la liste des joueurs", + "gamerule.molehunt:showSkins": "Molehunt : Affiche les skins des joueurs", + "gamerule.molehunt:initialWorldSize": "Molehunt : Taille initiale du monde", + "gamerule.molehunt:finalWorldSize": "Molehunt : Taille finale du monde", + "gamerule.molehunt:borderMovingStartingTimeOffsetMinutes": "Molehunt : Temps avant de bouger les bordures du monde" }
\ No newline at end of file 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"));
|
