-
Notifications
You must be signed in to change notification settings - Fork 5
Getting Started
ErdbeerbaerLP edited this page Jul 10, 2022
·
8 revisions
- Add the CurseForge maven repository to your build.gradle
repositories {
maven { url "https://repo.erdbeerbaerlp.de/repository/maven-public/" }
}
- Add the library
dependencies {
compileOnly('de.erdbeerbaerlp:guilib:2.0.2')
}
- Refresh Gradle
- Depend on the mod in your mods.toml file
[[dependencies.yourmodid]]
modId="eguilib"
mandatory=true
versionRange="[2.0.2,)"
ordering="NONE"
side="CLIENT"
To create an GUI, your class must extend ExtendedScreen
and implement all methods
public class ExampleGUI extends ExtendedScreen{
@Override
public void buildGui() {
}
@Override
public void updateGui() {
}
@Override
public boolean doesGuiPauseGame() {
return false;
}
@Override
public boolean doesEscCloseGui() {
return false;
}
}
Now you can start adding components to it.
You can do it by creating fields for every component and initialize it in buildGui() (it won´t work in the constructor or in the field!)
public class ExampleGUI extends ExtendedScreen{
private Label lbl;
@Override
public void buildGui() {
lbl = new Label("This is an Example", 10, 50); //Creates an new label at the position x=10;y=50 with the Text "This is an Example"
addComponent(lbl); //This actually adds the component to the GUI
}
@Override
public void updateGui() {
}
@Override
public boolean doesGuiPauseGame() {
return false;
}
@Override
public boolean doesEscCloseGui() {
return false;
}
}
You can also have the gui move the component automatically depending on your screen size. For that simply set the position of the component in updateGui()
public class ExampleGUI extends ExtendedScreen{
private Label lbl;
@Override
public void buildGui() {
lbl = new Label("This is an Example", 0,0);
lbl.setCentered(); //Sets the Label to have its position centered
addComponent(lbl);
}
@Override
public void updateGui() {
lbl.setPosition(width/2, 15); //Keeps the label in the center of the screen
}
@Override
public boolean doesGuiPauseGame() {
return false;
}
@Override
public boolean doesEscCloseGui() {
return false;
}
}
If you need an custom constructor, add it like this (Note: You can´t use the fields in buildGui())
public class ExampleGUI extends ExtendedScreen{
private final String example;
private Label lbl;
public ExampleGUI(String text){
super(); //Required!
this.example = text;
}
@Override
public void buildGui() {
lbl = new Label(0, 0);
lbl.setCentered();
addComponent(lbl);
}
@Override
public void updateGui() {
lbl.setText(this.example); //Set the text from the field
lbl.setPosition(width/2, 15);
}
@Override
public boolean doesGuiPauseGame() {
return false;
}
@Override
public boolean doesEscCloseGui() {
return false;
}
}
Now you can simply open it by using Minecraft.getInstance().setScreen(new ExampleGUI("Example"));
You can see an example with all components here (view it ingame by opening the config menu of this mod)