Skip to content

Commit

Permalink
v1.0.1 (#3)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Estecka authored Oct 30, 2023
1 parent 6c443fa commit 6d3c7cb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# 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

Some built-in datapacks are not "just" datapacks, and require special handling. A warning screen will be shown whenever you attempt to enable or disable any of these, and give you the option to back out.

### 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.

Expand Down
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 20 additions & 17 deletions src/main/java/tk/estecka/packrulemenus/mixin/OptionScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,18 +38,23 @@ abstract public class OptionScreenMixin

@Shadow abstract ButtonWidget createButton(Text message, Supplier<Screen> 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)); }
)
));

Expand All @@ -72,19 +78,18 @@ private void RevertScreen(){

@Unique
private void HandleDatapackRefresh(final ResourcePackManager manager, Collection<String> 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);
}
Expand All @@ -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 = "";
Expand All @@ -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;
});
}
Expand Down

0 comments on commit 6d3c7cb

Please sign in to comment.