Skip to content

Instantly share code, notes, and snippets.

@robere2
Last active March 28, 2019 17:46
Show Gist options
  • Save robere2/fd314599161eff24fdb6eae24a252f83 to your computer and use it in GitHub Desktop.
Save robere2/fd314599161eff24fdb6eae24a252f83 to your computer and use it in GitHub Desktop.
Example of how to set up a very simple scrollable GUI in Minecraft
class ScrollableGui extends GuiScreen {
int scrollDistance = 0;
final int x = 10;
final int y = 10;
@Override
public void handleMouseInput() throws IOException {
super.handleMouseInput();
// Get the distance scrolled since last checking
int d = Mouse.getDWheel();
if(d == 0)
return;
// Add the distance scrolled to our scrollDistance field
scrollDistance += d;
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
int adjustedY = y + scrollDistance;
// Draw the string at the specified y adjusted for scrolling and x
drawString(Minecraft.getMinecraft().fontRendererObj, "Hello, world!", x, adjustedY, 0xFFFFFFFF);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment