Skip to content

Commit

Permalink
allow disable warning from gui
Browse files Browse the repository at this point in the history
  • Loading branch information
qouteall committed Dec 30, 2023
1 parent 302a060 commit ea48eec
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package qouteall.dimlib.mixin.client;

import eu.midnightdust.lib.config.MidnightConfig;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Checkbox;
import net.minecraft.client.gui.components.MultiLineLabel;
import net.minecraft.client.gui.screens.BackupConfirmScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.worldselection.WorldOpenFlows;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import qouteall.dimlib.DimLibEntry;
import qouteall.dimlib.config.DimLibConfig;

import java.util.Objects;

@Mixin(BackupConfirmScreen.class)
public class MixinBackupConfirmScreen extends Screen {

@Shadow
@Final
protected BackupConfirmScreen.Listener onProceed;
@Shadow
private Checkbox eraseCache;
@Shadow
private MultiLineLabel message;
@Unique
private boolean dimlib_isExperimentalWarning = false;

protected MixinBackupConfirmScreen(Component title) {
super(title);
throw new RuntimeException();
}

/**
* {@link WorldOpenFlows#askForBackup}
*/
@SuppressWarnings("JavadocReference")
@Inject(method = "<init>", at = @At("RETURN"))
private void onInitEnd(
Runnable runnable, BackupConfirmScreen.Listener listener,
Component component, Component component2, boolean bl, CallbackInfo ci
) {
dimlib_isExperimentalWarning = Objects.equals(
component,
Component.translatable("selectWorld.backupQuestion.experimental")
);
}

@Inject(method = "init", at = @At("RETURN"))
private void onInitEnd(CallbackInfo ci) {
if (dimlib_isExperimentalWarning) {
int i = (this.message.getLineCount() + 1) * 9;
addRenderableWidget(Button
.builder(
Component.translatable(
"dimlib.i_know_what_i_am_doing_and_disable_warning"
),
button -> {
DimLibConfig.suppressExperimentalWarning = true;
MidnightConfig.write(DimLibEntry.MODID);

this.onProceed.proceed(false, this.eraseCache.selected());
}
)
.bounds(
this.width / 2 - 200, 124 + i + 40,
400, 20
)
.build()
);

}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/dimlib/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dimlib.midnightconfig.title": "DimLib Config",
"dimlib.midnightconfig.suppressExperimentalWarning": "Suppress Experimental Warning",
"dimlib.midnightconfig.suppressExperimentalWarning.tooltip": "If enabled, it will not show \"Worlds using Experimental Settings are not supported\" warning screen when entering world."
"dimlib.midnightconfig.suppressExperimentalWarning.tooltip": "If enabled, it will not show \"Worlds using Experimental Settings are not supported\" warning screen when entering world.",
"dimlib.i_know_what_i_am_doing_and_disable_warning": "[DimLib] I know what I am doing and don't show this warning again."
}
1 change: 1 addition & 0 deletions src/main/resources/dimlib.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"client": [
"client.IClientPacketListener",
"client.MixinBackupConfirmScreen",
"client.MixinMinecraft"
],
"injectors": {
Expand Down
10 changes: 8 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"id": "dimlib",
"version": "${version}",
"name": "DimLib",
"description": "Adds the functionality of dynamically adding and removing dimensions.",
"description": "Adds the functionality of dynamically adding and removing dimensions.\nAlso allow disabling 'Experimental Settings not supported' warning screen.",
"authors": [
"qouteall"
],
"contact": {
"homepage": "https://github.com/iPortalTeam/DimLib",
"sources": "https://github.com/iPortalTeam/DimLib"
"sources": "https://github.com/iPortalTeam/DimLib",
"issues": "https://github.com/iPortalTeam/DimLib/issues"
},
"license": "CC0-1.0",
"icon": "assets/dimlib/icon.png",
Expand All @@ -36,5 +37,10 @@
},
"suggests": {

},
"custom": {
"modmenu": {
"badges": ["library"]
}
}
}

0 comments on commit ea48eec

Please sign in to comment.