From 9bb3bc44b5201124879836739c976a772cab7403 Mon Sep 17 00:00:00 2001 From: anhgelus Date: Sun, 25 Aug 2024 14:19:09 +0000 Subject: feat(game): disable portals close #7 --- .../java/world/anhgelus/molehunt/mixin/NoPortals.java | 17 +++++++++++++++++ src/main/resources/molehunt.mixins.json | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java diff --git a/src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java b/src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java new file mode 100644 index 0000000..8ab8f14 --- /dev/null +++ b/src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java @@ -0,0 +1,17 @@ +package world.anhgelus.molehunt.mixin; + +import net.minecraft.entity.Entity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.dimension.PortalManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(PortalManager.class) +public class NoPortals { + @Inject(at = @At("HEAD"), method = "tick", cancellable = true) + public void disableTick(ServerWorld world, Entity entity, boolean canUsePortals, CallbackInfoReturnable cir) { + cir.setReturnValue(false); + } +} diff --git a/src/main/resources/molehunt.mixins.json b/src/main/resources/molehunt.mixins.json index 7ee051d..287cfc4 100644 --- a/src/main/resources/molehunt.mixins.json +++ b/src/main/resources/molehunt.mixins.json @@ -4,7 +4,8 @@ "package": "world.anhgelus.molehunt.mixin", "compatibilityLevel": "JAVA_21", "mixins": [ - "NoMsgCommand" + "NoMsgCommand", + "NoPortals" ], "injectors": { "defaultRequire": 1 -- cgit v1.2.3 From d618e7682186c6396d5cb2ee6fbb3028d2b0e8f3 Mon Sep 17 00:00:00 2001 From: anhgelus Date: Sun, 25 Aug 2024 14:25:33 +0000 Subject: docs(info): add feature about disabled nether and end --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e5338a9..475b263 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ The mod stops the game when every innocent is dead or when the timer ended. The moles can see the name of other moles with `/molehunt moles`. +Disable the nether, the end and every other portal. + _Almost_ everything in the mod can configured. ## Configuration -- cgit v1.2.3 From f7784aa574dd3ca05bae3ef0ff00cbdcdac4b457 Mon Sep 17 00:00:00 2001 From: anhgelus Date: Sun, 25 Aug 2024 14:36:00 +0000 Subject: feat(config): gamerule to enable/disable portals --- Writerside/topics/configuration.md | 7 +++++++ src/main/java/world/anhgelus/molehunt/Molehunt.java | 5 +++++ src/main/java/world/anhgelus/molehunt/config/Config.java | 12 +++++++++++- src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java | 2 ++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Writerside/topics/configuration.md b/Writerside/topics/configuration.md index 41c4ff4..3f10fa1 100644 --- a/Writerside/topics/configuration.md +++ b/Writerside/topics/configuration.md @@ -28,6 +28,9 @@ Tab can be used (default: false). - Target border size on the end of the game : `final_world_size` (or `finalWorldSize`). - Time before moving the borders : `border_moving_starting_time_offset` (or `borderMovingStartingTimeOffsetMinutes`). +### Misc +- Enable portals (for the nether, the end and the end gateway) : `enable_portals` (or `enablePortals`). + Every clientside rules (nametag, skin and tab) are only used by the client during a game. Before and after the game, they are not used. @@ -99,4 +102,8 @@ final_world_size = 50 # If this value is greater than the game duration, borders will never shrink. # Default: 10 minutes. border_shrinking_starting_time_offset = 10 + +# Enable portals (nether, end, end gateway) +# Default: false +enable_portals = false ``` diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index 52399dc..58c43f2 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -94,6 +94,11 @@ public class Molehunt implements ModInitializer { GameRules.Category.MISC, GameRuleFactory.createIntRule(CONFIG_FILE.getOrDefault("border_moving_starting_time_offset", 10), 0) ); + public static final GameRules.Key ENABLE_PORTALS = GameRuleRegistry.register( + MOD_ID +":enablePortals", + GameRules.Category.MISC, + GameRuleFactory.createBooleanRule(CONFIG_FILE.getOrDefault("enable_portals", false)) + ); 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 e1c84a4..b2e45ab 100644 --- a/src/main/java/world/anhgelus/molehunt/config/Config.java +++ b/src/main/java/world/anhgelus/molehunt/config/Config.java @@ -60,6 +60,10 @@ public class Config { return server.getGameRules().getInt(Molehunt.MOVING_STARTING_TIME_OFFSET); } + public boolean arePortalsEnabled() { + return server.getGameRules().getBoolean(Molehunt.ENABLE_PORTALS); + } + public static SimpleConfig configFile(String fileName) { return SimpleConfig.of(fileName).provider(Config::defaultConfig).request(); } @@ -102,7 +106,7 @@ public class Config { show_tab = false - # World border settings : + # World border settings # Initial world size (in blocks). # Default: 200 blocks. @@ -117,6 +121,12 @@ public class Config { # If this value is greater than the game duration, borders will never move. # Default: 10 minutes. border_moving_starting_time_offset = 10 + + # Other + + # Enable portals (nether, end, end gateway) + # Default: false + enable_portals = false """; } } diff --git a/src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java b/src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java index 8ab8f14..96c63aa 100644 --- a/src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java +++ b/src/main/java/world/anhgelus/molehunt/mixin/NoPortals.java @@ -7,11 +7,13 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import world.anhgelus.molehunt.Molehunt; @Mixin(PortalManager.class) public class NoPortals { @Inject(at = @At("HEAD"), method = "tick", cancellable = true) public void disableTick(ServerWorld world, Entity entity, boolean canUsePortals, CallbackInfoReturnable cir) { + if (Molehunt.CONFIG == null || Molehunt.CONFIG.arePortalsEnabled()) return; cir.setReturnValue(false); } } -- cgit v1.2.3