From 6d3c7cb388520e8ba51713e25791ed1a6abd06ec Mon Sep 17 00:00:00 2001 From: Estecka Date: Mon, 30 Oct 2023 09:56:43 +0100 Subject: [PATCH] v1.0.1 (#3) - Menus are no longer available when cheats are disabled, mirroring the availability of the corresponding commands. - Gamerules changes are now discarded when using the cancel button, or when hitting ESC. - Fix gamerule callbacks not being called. --- README.md | 4 +- changelog.md | 7 +++- gradle.properties | 2 +- .../mixin/OptionScreenMixin.java | 37 ++++++++++--------- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b34ff7f..c940618 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Data-Pack / Game-Rule Menus -Makes the eponymous menus accessible from already from singleplayer worlds. +Makes the eponymous menus accessible from the pause menu in singleplayer worlds. ## Word of caution: Datapacks @@ -8,7 +8,7 @@ Some built-in datapacks are not "just" datapacks, and require special handling. ### Feature Packs -When packs that include experimental features (such as bundles) are toggled, and the approriate feature flag will be toggled on the world. +When packs that include experimental features (such as bundles) are toggled, the approriate feature flag will be toggled on the world. However, **unlike regular datapacks those will not take effect until you restart the world.** If you had to go through a warning screen in order to toggle something, you'll probably want to restart the world immediately. diff --git a/changelog.md b/changelog.md index 4a5711f..b12d9f4 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,8 @@ # v1 -# 1.0 +## 1.0 +### 1.0.0 - Initial Release +### 1.0.1 +- Menus are no longer available when cheats are disabled, mirroring the availability of the corresponding commands. +- Gamerules changes are now discarded when using the cancel button, or when hitting ESC. +- Fix gamerule callbacks not being called. diff --git a/gradle.properties b/gradle.properties index c602b7f..71418d4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.19.4+build.2 loader_version=0.14.24 # Mod Properties -mod_version=1.0.0 +mod_version=1.0.1 maven_group=tk.estecka.packrulemenus archives_base_name=packrule-menus diff --git a/src/main/java/tk/estecka/packrulemenus/mixin/OptionScreenMixin.java b/src/main/java/tk/estecka/packrulemenus/mixin/OptionScreenMixin.java index 7207507..34bdf60 100644 --- a/src/main/java/tk/estecka/packrulemenus/mixin/OptionScreenMixin.java +++ b/src/main/java/tk/estecka/packrulemenus/mixin/OptionScreenMixin.java @@ -21,11 +21,12 @@ import net.minecraft.resource.ResourcePackManager; import net.minecraft.resource.featuretoggle.FeatureFlags; import net.minecraft.resource.featuretoggle.FeatureSet; -import net.minecraft.server.MinecraftServer; +import net.minecraft.server.integrated.IntegratedServer; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.WorldSavePath; -import net.minecraft.world.World; +import net.minecraft.world.GameRules; import tk.estecka.packrulemenus.GenericWarningScreen; import tk.estecka.packrulemenus.PackRuleMenus; @@ -37,18 +38,23 @@ abstract public class OptionScreenMixin @Shadow abstract ButtonWidget createButton(Text message, Supplier screenSupplier); + @Unique + private IntegratedServer server; + @Inject( method="init", at=@At(value="INVOKE", ordinal=1, shift=Shift.AFTER, target="net/minecraft/client/gui/widget/GridWidget$Adder.add (Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget;") ) private void gameruleMenu$Init(CallbackInfo info, @Local GridWidget.Adder adder){ - final MinecraftServer server = this.client.getServer(); - final World world; + this.server = this.client.getServer(); - if (client.isIntegratedServerRunning() && null != (world=client.getServer().getOverworld())) + if (client.isIntegratedServerRunning() + && server.getSaveProperties().areCommandsAllowed() + && server.getOverworld() != null) { + final GameRules worldRules = server.getOverworld().getGameRules(); adder.add(createButton( Text.translatable("selectWorld.gameRules"), () -> new EditGameRulesScreen( - world.getGameRules(), - optRules -> RevertScreen() + worldRules.copy(), + optRules -> { RevertScreen(); optRules.ifPresent(r -> worldRules.setAllValues(r, server)); } ) )); @@ -72,19 +78,18 @@ private void RevertScreen(){ @Unique private void HandleDatapackRefresh(final ResourcePackManager manager, Collection rollback){ - final MinecraftServer server = this.client.getServer(); FeatureSet neoFeatures = manager.getRequestedFeatures(); FeatureSet oldFeatures = server.getSaveProperties().getEnabledFeatures(); if (neoFeatures.equals(oldFeatures)) - ReloadPacks(manager, server); + ReloadPacks(manager); else { boolean isExperimental = FeatureFlags.isNotVanilla(neoFeatures); boolean wasVanillaRemoved = oldFeatures.contains(FeatureFlags.VANILLA) && !neoFeatures.contains(FeatureFlags.VANILLA); BooleanConsumer onConfirm = confirmed -> { if (confirmed){ - this.ApplyFlags(manager, server); - this.ReloadPacks(manager, server); + this.ApplyFlags(manager); + this.ReloadPacks(manager); } else { manager.setEnabledProfiles(rollback); } @@ -101,7 +106,7 @@ private void HandleDatapackRefresh(final ResourcePackManager manager, Collection } @Unique - private void ApplyFlags(final ResourcePackManager manager, final MinecraftServer server){ + private void ApplyFlags(final ResourcePackManager manager){ FeatureSet features = manager.getRequestedFeatures(); String featureNames = ""; @@ -114,14 +119,12 @@ private void ApplyFlags(final ResourcePackManager manager, final MinecraftServer @Unique - private void ReloadPacks(final ResourcePackManager manager, final MinecraftServer server){ - if (client.player != null) - client.inGameHud.getChatHud().addMessage(Text.translatable("commands.reload.success")); + private void ReloadPacks(final ResourcePackManager manager){ + client.inGameHud.getChatHud().addMessage(Text.translatable("commands.reload.success")); server.reloadResources(manager.getEnabledNames()).exceptionally(e -> { PackRuleMenus.LOGGER.error("{}", e); - if (client.player != null) - client.player.getCommandSource().sendError(Text.translatable("commands.reload.failure")); + client.inGameHud.getChatHud().addMessage(Text.translatable("commands.reload.failure").formatted(Formatting.RED)); return null; }); }