Skip to content

Commit

Permalink
Make button open data pack selection screen
Browse files Browse the repository at this point in the history
  • Loading branch information
MacaylaMarvelous81 committed Aug 2, 2024
1 parent 6bce5b5 commit 967bb74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,15 +24,23 @@
@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);
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/EmptyWidget;<init>(II)V", ordinal = 1), method = "<init>")
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);
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/assets/datapackinstaller/lang/en_us.json

This file was deleted.

0 comments on commit 967bb74

Please sign in to comment.