add command button to GUI that runs /seed

This commit is contained in:
Joseph Garcia 2020-12-07 14:27:33 -06:00
parent c2dbe688c1
commit 216a712281
2 changed files with 47 additions and 2 deletions

View File

@ -29,7 +29,7 @@ dependencies {
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them. // You may need to force-disable transitiveness on them.
dependencies { dependencies {
modImplementation "io.github.cottonmc:LibGui:3.2.1+1.16.3" modImplementation "io.github.cottonmc:LibGui:3.2.2+1.16.3"
} }
} }

View File

@ -2,12 +2,22 @@ package com.josyf.macrobuttons;
import io.github.cottonmc.cotton.gui.GuiDescription;
import io.github.cottonmc.cotton.gui.client.CottonClientScreen;
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
import io.github.cottonmc.cotton.gui.widget.WButton;
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
import io.github.cottonmc.cotton.gui.widget.WLabel;
import io.github.cottonmc.cotton.gui.widget.WSprite;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.options.KeyBinding; import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
public class MacroButtons implements ModInitializer { public class MacroButtons implements ModInitializer {
@ -33,11 +43,46 @@ public class MacroButtons implements ModInitializer {
ClientTickEvents.END_CLIENT_TICK.register(client -> { ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (keyBinding.wasPressed()) { while (keyBinding.wasPressed()) {
client.player.sendMessage(new LiteralText("Key 1 was pressed!"), false); // client.player.sendMessage(new LiteralText("Key 1 was pressed!"), false);
MinecraftClient.getInstance().openScreen(new ExampleScreen(new ExampleGui()));
//printMessage();
} }
}); });
} }
public class ExampleScreen extends CottonClientScreen {
public ExampleScreen(GuiDescription description) {
super(description);
}
}
public class ExampleGui extends LightweightGuiDescription {
public ExampleGui() {
WGridPanel root = new WGridPanel();
setRootPanel(root);
root.setSize(256, 240);
// WSprite icon = new WSprite(new Identifier("minecraft:textures/item/redstone.png"));
// root.add(icon, 0, 2, 1, 1);
// example button to play with
WButton button = new WButton(new TranslatableText("gui.examplemod.examplebutton"));
button.setOnClick(() -> {
printMessage();
});
root.add(button, 0, 3, 4, 1);
WLabel label = new WLabel(new LiteralText("Test"), 0xFFFFFF);
root.add(label, 0, 4, 2, 1);
root.validate(this);
}
}
// player can run a command here
private void printMessage() {
MinecraftClient.getInstance().player.sendChatMessage("/seed");
}
} }