diff options
| author | anhgelus <anhgelus.morhtuuzh@proton.me> | 2024-09-08 11:40:12 +0000 |
|---|---|---|
| committer | anhgelus <anhgelus.morhtuuzh@proton.me> | 2024-09-08 11:40:12 +0000 |
| commit | 1d3b40a0955e8b5f5418135933d0e6f7c75e795c (patch) | |
| tree | 1f4c108d9a91fb52762e6f8bc419d7b75b1f9062 | |
| parent | a19b4998a33df2f097d19b6ecc7c2c915ad87a8a (diff) | |
feat(game): give food on start
| -rw-r--r-- | src/main/java/world/anhgelus/molehunt/Molehunt.java | 5 | ||||
| -rw-r--r-- | src/main/java/world/anhgelus/molehunt/config/Config.java | 8 | ||||
| -rw-r--r-- | src/main/java/world/anhgelus/molehunt/game/Game.java | 3 |
3 files changed, 16 insertions, 0 deletions
diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index b867337..83309a0 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -100,6 +100,11 @@ public class Molehunt implements ModInitializer { GameRules.Category.MISC, GameRuleFactory.createBooleanRule(CONFIG_FILE.getOrDefault("enable_portals", false)) ); + public static final GameRules.Key<GameRules.BooleanRule> FOOD_ON_START = GameRuleRegistry.register( + MOD_ID +":foodOnStart", + GameRules.Category.MISC, + GameRuleFactory.createBooleanRule(CONFIG_FILE.getOrDefault("food_on_start", true)) + ); 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 9db560b..e448f7d 100644 --- a/src/main/java/world/anhgelus/molehunt/config/Config.java +++ b/src/main/java/world/anhgelus/molehunt/config/Config.java @@ -64,6 +64,10 @@ public class Config { return server.getGameRules().getBoolean(Molehunt.ENABLE_PORTALS); } + public boolean foodOnStart() { + return server.getGameRules().getBoolean(Molehunt.FOOD_ON_START); + } + public static SimpleConfig configFile(String fileName) { return SimpleConfig.of(fileName).provider(Config::defaultConfig).request(); } @@ -90,6 +94,10 @@ public class Config { # Default: -1. mole_count = -1 + # Give food on start + # Default: true + food_on_start = true + # Client-side settings (applies to all players) diff --git a/src/main/java/world/anhgelus/molehunt/game/Game.java b/src/main/java/world/anhgelus/molehunt/game/Game.java index 3ffdf61..bac6c27 100644 --- a/src/main/java/world/anhgelus/molehunt/game/Game.java +++ b/src/main/java/world/anhgelus/molehunt/game/Game.java @@ -1,6 +1,8 @@ package world.anhgelus.molehunt.game;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
+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;
@@ -80,6 +82,7 @@ public class Game { p.networkHandler.sendPacket(timing);
p.networkHandler.sendPacket(title);
p.changeGameMode(GameMode.SURVIVAL);
+ if (Molehunt.CONFIG.foodOnStart()) p.giveItemStack(new ItemStack(Items.COOKED_BEEF, 64));
});
server.setDefaultGameMode(GameMode.SPECTATOR);
|
