From 1d3b40a0955e8b5f5418135933d0e6f7c75e795c Mon Sep 17 00:00:00 2001 From: anhgelus Date: Sun, 8 Sep 2024 11:40:12 +0000 Subject: feat(game): give food on start --- src/main/java/world/anhgelus/molehunt/Molehunt.java | 5 +++++ src/main/java/world/anhgelus/molehunt/config/Config.java | 8 ++++++++ src/main/java/world/anhgelus/molehunt/game/Game.java | 3 +++ 3 files changed, 16 insertions(+) (limited to 'src/main') 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 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); -- cgit v1.2.3