Skip to content

Commit

Permalink
Removed the "Automated Backup" button from the create world screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
MehradN committed Mar 8, 2023
1 parent 994711d commit 2b2b288
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 83 deletions.
Binary file removed screenshots/AlteredCreateNewWorldScreenPart1.png
Binary file not shown.
Binary file removed screenshots/AlteredCreateNewWorldScreenPart2.png
Binary file not shown.
7 changes: 0 additions & 7 deletions screenshots/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,3 @@ The "Re-create" button can now be accessed from here.

![Altered Edit World Screen](https://raw.githubusercontent.com/MehradN/Rollback/master/screenshots/AlteredEditWorldScreen.png)

## Altered Create New World Screen
You can enable the mod for new worlds from here. <br>
The "Game Rules" button has been moved to the more options screen.

![Altered Create New World Screen Part 1](https://raw.githubusercontent.com/MehradN/Rollback/master/screenshots/AlteredCreateNewWorldScreenPart1.png)

![Altered Create New World Screen Part 2](https://raw.githubusercontent.com/MehradN/Rollback/master/screenshots/AlteredCreateNewWorldScreenPart2.png)
88 changes: 17 additions & 71 deletions src/main/java/ir/mehradn/rollback/mixin/CreateWorldScreenMixin.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package ir.mehradn.rollback.mixin;

import com.mojang.serialization.Lifecycle;
import ir.mehradn.rollback.config.RollbackConfig;
import ir.mehradn.rollback.util.backup.BackupManager;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.CycleButton;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.ConfirmScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
Expand All @@ -20,7 +16,6 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

Expand All @@ -29,81 +24,36 @@
@Environment(EnvType.CLIENT)
@Mixin(CreateWorldScreen.class)
public abstract class CreateWorldScreenMixin extends Screen {
@Shadow private Button gameRulesButton;

private CycleButton<Boolean> automatedButton;
private int[] buttonPos;
private boolean promptEnabled = true;
private boolean enablePrompted = false;
private boolean redirectCreateNewWorld = true;
private boolean promptAnswer = true;

protected CreateWorldScreenMixin(Component component) {
super(component);
}

@Shadow protected abstract void createNewWorld(PrimaryLevelData.SpecialWorldProperty specialWorldProperty, LayeredRegistryAccess<RegistryLayer> layeredRegistryAccess, Lifecycle worldGenSettingsLifecycle);

@ModifyArg(method = "init", index = 0, at = @At(value = "INVOKE", ordinal = 4, target = "Lnet/minecraft/client/gui/screens/worldselection/CreateWorldScreen;addRenderableWidget(Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener;"))
private GuiEventListener changeButton(GuiEventListener widget) {
Button button = (Button)widget;

if (RollbackConfig.replaceGameRulesButton()) {
this.buttonPos = new int[]{button.getX(), button.getY()};
button.setPosition(this.width / 2 + 5, 151);
} else {
this.buttonPos = new int[]{this.width / 2 + 5, 151};
}
return button;
}

@Inject(method = "init", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent;init(Lnet/minecraft/client/gui/screens/worldselection/CreateWorldScreen;Lnet/minecraft/client/Minecraft;Lnet/minecraft/client/gui/Font;)V"))
private void addMyButton(CallbackInfo ci) {
this.automatedButton = addRenderableWidget(CycleButton.onOffBuilder(false).create(
this.buttonPos[0], this.buttonPos[1], 150, 20,
Component.translatable("rollback.screen.automatedOption")
));

if (RollbackConfig.replaceGameRulesButton())
this.gameRulesButton.visible = false;
else
this.automatedButton.visible = false;
}

@Inject(method = "setWorldGenSettingsVisible", at = @At("RETURN"))
private void toggleButtons(boolean moreOptionsOpen, CallbackInfo ci) {
boolean f = RollbackConfig.replaceGameRulesButton() ^ moreOptionsOpen;
this.gameRulesButton.visible = !f;
this.automatedButton.visible = f;
}

@Inject(method = "createNewWorld", cancellable = true, at = @At("HEAD"))
private void promptFeature(PrimaryLevelData.SpecialWorldProperty specialWorldProperty,
LayeredRegistryAccess<RegistryLayer> layeredRegistryAccess,
Lifecycle worldGenSettingsLifecycle,
CallbackInfo ci) {
if (RollbackConfig.promptDisabled()) {
this.enablePrompted = false;
return;
}
if (!this.promptEnabled) {
this.promptEnabled = true;
if (!this.redirectCreateNewWorld) {
this.redirectCreateNewWorld = true;
return;
}
if (!this.automatedButton.getValue()) {
this.minecraft.setScreen(new ConfirmScreen(
(confirmed) -> {
this.automatedButton.setValue(confirmed);
this.promptEnabled = false;
this.enablePrompted = true;
this.createNewWorld(specialWorldProperty, layeredRegistryAccess, worldGenSettingsLifecycle);
},
Component.translatable("rollback.screen.enableAutomatedQuestion"),
Component.empty(),
Component.translatable("gui.yes"),
Component.translatable("gui.no")
));
ci.cancel();
}
this.enablePrompted = false;
this.minecraft.setScreen(new ConfirmScreen(
(confirmed) -> {
this.redirectCreateNewWorld = false;
this.promptAnswer = confirmed;
this.createNewWorld(specialWorldProperty, layeredRegistryAccess, worldGenSettingsLifecycle);
},
Component.translatable("rollback.screen.enableAutomatedQuestion"),
Component.empty(),
Component.translatable("gui.yes"),
Component.translatable("gui.no")
));
ci.cancel();
}

@Inject(method = "createNewWorldDirectory", at = @At("RETURN"))
Expand All @@ -112,10 +62,6 @@ private void saveOption(CallbackInfoReturnable<Optional<LevelStorageSource.Level
return;
String worldName = ci.getReturnValue().get().getLevelId();
BackupManager backupManager = new BackupManager();
backupManager.setAutomated(worldName, this.automatedButton.getValue());
if (this.enablePrompted) {
backupManager.setPrompted(worldName);
this.enablePrompted = false;
}
backupManager.setAutomated(worldName, this.promptAnswer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ public boolean getPrompted(String worldName) {
return (worldObject.get("automated").getAsBoolean() || worldObject.get("prompted").getAsBoolean());
}

public void setPrompted(String worldName) {
getWorldObject(worldName).addProperty("prompted", true);
saveMetadata();
}

public void setPromptAnswer(String worldName, boolean automated) {
JsonObject worldObject = getWorldObject(worldName);
worldObject.addProperty("automated", automated);
Expand Down

0 comments on commit 2b2b288

Please sign in to comment.