diff --git a/src/main/java/qouteall/dimlib/mixin/client/MixinBackupConfirmScreen.java b/src/main/java/qouteall/dimlib/mixin/client/MixinBackupConfirmScreen.java new file mode 100644 index 0000000..9fabe35 --- /dev/null +++ b/src/main/java/qouteall/dimlib/mixin/client/MixinBackupConfirmScreen.java @@ -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 = "", 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() + ); + + } + } +} diff --git a/src/main/resources/assets/dimlib/lang/en_us.json b/src/main/resources/assets/dimlib/lang/en_us.json index fa681b9..0c54bb9 100644 --- a/src/main/resources/assets/dimlib/lang/en_us.json +++ b/src/main/resources/assets/dimlib/lang/en_us.json @@ -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." } \ No newline at end of file diff --git a/src/main/resources/dimlib.mixins.json b/src/main/resources/dimlib.mixins.json index 176bbd1..a91963a 100644 --- a/src/main/resources/dimlib.mixins.json +++ b/src/main/resources/dimlib.mixins.json @@ -12,6 +12,7 @@ ], "client": [ "client.IClientPacketListener", + "client.MixinBackupConfirmScreen", "client.MixinMinecraft" ], "injectors": { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8d823c2..3038a99 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -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", @@ -36,5 +37,10 @@ }, "suggests": { + }, + "custom": { + "modmenu": { + "badges": ["library"] + } } } \ No newline at end of file