-
Notifications
You must be signed in to change notification settings - Fork 0
Initialization and Setup
To get access to any of the Vera classes and functionality, you will need to add is as a dependency in your build.gradle and fabric.mod.json. The artifact is hosted on our own repository.
Dependencies:
repositories {
maven { url = "https://artifacts.snackbag.net/artifactory/libs-release/" }
}
dependencies {
modImplementation "net.snackbag.mcvera:mcvera:VERSION" // replace version with the latest version
}Now reload your gradle build script and you're ready to go!
To start off with setting up a Vera UI, you first need to create a VeraApp environment. Create a new class, in our case 'TutorialApp' and let it extend VeraApp. You will also need to override the init method. This is where you will initialize all your widgets. NEVER initialize widgets in the app's constructor. Here's an example:
import net.snackbag.vera.core.VeraApp;
public class TutorialApp extends VeraApp {
@Override
public void init() {
// Here goes all initialization. NOT in the app's constructor
}
}To open your UI, you will need to initialize it and run the show method. It is recommended to save an instance of the app somewhere so you don't have to re-initialize it all the time. This is optional though, and will vary with each use-case. You can close it by running hide. You can show multiple apps at once, even if the player already has a vanilla screen opened. Vanilla screens are rendered in front of Vera screens.
In this example, we listen to the key press of Y. When pressed, we open the UI.
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;
public class TutorialModClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
// This is a vanilla keybinding. Beware: no vanilla keybinds will
// work when inside the UI. Therefor use Vera's own VShortcut feature.
var openKeybinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.tutorialmod.open",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_Y,
"category.tutorialmod.keys"
));
ClientTickEvents.END_CLIENT_TICK.register((client) -> {
while (openKeybinding.wasPressed()) {
// You can run this anywhere on the client and it will show the app.
// No strings attached!
new TutorialApp().show();
}
});
}
}Great! Now you can show your UI. The only problem is: it's entirely empty.
If you want to add a little hello world text to your UI, click here
Generic
Home
Inner Workings
Starting off
Setup
Hello world!
Basic Events
Widgets
VWidget, the base of everything
VImage
VLabel
VLineInput
VRect