Skip to content

Commit

Permalink
Data pack configuration while loaded in world
Browse files Browse the repository at this point in the history
  • Loading branch information
MacaylaMarvelous81 committed Aug 3, 2024
1 parent 6670a9d commit 2801ad0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 91 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ml.unbreakinggold.datapackinstaller.mixin;

import ml.unbreakinggold.datapackinstaller.client.DatapackInstallerClient;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.pack.PackScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.GridWidget;
import net.minecraft.resource.ResourcePackManager;
import net.minecraft.text.Text;
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 org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.function.Supplier;

@Mixin(GameMenuScreen.class)
public abstract class GameMenuScreenMixin extends Screen {
@Shadow private ButtonWidget createButton(Text text, Supplier<Screen> screenSupplier) { return null; };
@Unique private static final Text DATA_PACK_TEXT = Text.translatable("dataPack.title");

private GameMenuScreenMixin(Text title) {
super(title);
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;isInSingleplayer()Z"), method = "initWidgets", locals = LocalCapture.CAPTURE_FAILHARD)
private void onInitWidgets(CallbackInfo ci, GridWidget gridWidget, GridWidget.Adder adder) {
if (!this.client.isIntegratedServerRunning() || this.client.getServer().isRemote()) return;

adder.add(this.createButton(DATA_PACK_TEXT, () -> {
ResourcePackManager dataPackManager = this.client.getServer().getDataPackManager();

return new PackScreen(dataPackManager, (manager) -> {}, DatapackInstallerClient.MAIN_PATH, DATA_PACK_TEXT);
}));
}
}
2 changes: 1 addition & 1 deletion src/main/resources/DatapackInstaller.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"client": [
"CreateWorldScreenMixin",
"EditWorldScreenMixin"
"GameMenuScreenMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 2801ad0

Please sign in to comment.