MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"create button that prints hello world"
/* Here is an example of a custom button that prints "Hello World" to the console when clicked in Minecraft Forge. This is a simple implementation of a button in a GUI. */ public class HelloWorldButton extends Button { public HelloWorldButton(int widthIn, int heightIn, int width, int height, String msg, Button.IPressable onPress) { super(widthIn, heightIn, width, height, msg, onPress); } @Override public void onPress() { System.out.println("Hello World"); } } /* To use this button, you need to add it to a GUI. Here is an example of how to do this: */ public class ExampleScreen extends Screen { protected ExampleScreen(ITextComponent titleIn) { super(titleIn); } @Override protected void init() { super.init(); this.addButton(new HelloWorldButton(this.width / 2 - 100, this.height / 2, 200, 20, "Press Me", button -> {})); } } /* This will create a button in the middle of the screen that says "Press Me". When you press it, "Hello World" will be printed to the console. */