From 967bb7468203f7ab19ac31a57e4debb1cb12eeaf Mon Sep 17 00:00:00 2001 From: Jomar Milan Date: Fri, 2 Aug 2024 14:28:37 -0700 Subject: [PATCH] Make button open data pack selection screen --- .../mixin/EditWorldScreenMixin.java | 20 +++++++++++++++++-- .../assets/datapackinstaller/lang/en_us.json | 3 --- 2 files changed, 18 insertions(+), 5 deletions(-) delete mode 100644 src/main/resources/assets/datapackinstaller/lang/en_us.json diff --git a/src/main/java/ml/unbreakinggold/datapackinstaller/mixin/EditWorldScreenMixin.java b/src/main/java/ml/unbreakinggold/datapackinstaller/mixin/EditWorldScreenMixin.java index a3d9310..b46c41e 100644 --- a/src/main/java/ml/unbreakinggold/datapackinstaller/mixin/EditWorldScreenMixin.java +++ b/src/main/java/ml/unbreakinggold/datapackinstaller/mixin/EditWorldScreenMixin.java @@ -1,10 +1,18 @@ package ml.unbreakinggold.datapackinstaller.mixin; +import it.unimi.dsi.fastutil.booleans.BooleanConsumer; +import ml.unbreakinggold.datapackinstaller.client.DatapackInstallerClient; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.pack.PackScreen; import net.minecraft.client.gui.screen.world.EditWorldScreen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.DirectionalLayoutWidget; +import net.minecraft.resource.ResourcePackManager; +import net.minecraft.resource.VanillaDataPackProvider; import net.minecraft.text.Text; +import net.minecraft.world.level.storage.LevelStorage; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -16,7 +24,8 @@ @Mixin(EditWorldScreen.class) public class EditWorldScreenMixin extends Screen { @Shadow @Final private DirectionalLayoutWidget layout; - @Unique private static final Text SELECT_DATAPACKS_TEXT = Text.translatable("selectWorld.edit.datapacks"); + @Unique private static final Text SELECT_DATAPACKS_TEXT = Text.translatable("dataPack.title"); + @Unique @Nullable private ResourcePackManager packManager; protected EditWorldScreenMixin(Text title) { super(title); @@ -24,7 +33,14 @@ protected EditWorldScreenMixin(Text title) { @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/EmptyWidget;(II)V", ordinal = 1), method = "") private void addButton(CallbackInfo info) { - this.layout.add(ButtonWidget.builder(SELECT_DATAPACKS_TEXT, (button) -> {}).width(200).build()); + this.layout.add(ButtonWidget.builder(SELECT_DATAPACKS_TEXT, (button) -> { + if (this.packManager == null) { + this.packManager = VanillaDataPackProvider.createManager(DatapackInstallerClient.MAIN_PATH, client.getSymlinkFinder()); + this.packManager.scanPacks(); + } + + this.client.setScreen(new PackScreen((ResourcePackManager) this.packManager, (resourcePackManager) -> {}, DatapackInstallerClient.MAIN_PATH, Text.translatable("dataPack.title"))); + }).width(200).build()); // Reduce spacing so vanilla buttons remain on screen. this.layout.spacing(1); diff --git a/src/main/resources/assets/datapackinstaller/lang/en_us.json b/src/main/resources/assets/datapackinstaller/lang/en_us.json deleted file mode 100644 index b754974..0000000 --- a/src/main/resources/assets/datapackinstaller/lang/en_us.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "selectWorld.edit.datapacks": "Select Datapacks" -} \ No newline at end of file