Add scrolling
This commit is contained in:
parent
c5ff6a2c4f
commit
9fa9b616fd
1 changed files with 17 additions and 1 deletions
|
@ -9,6 +9,7 @@ import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.lwjgl.system.MathUtil;
|
||||||
|
|
||||||
public class ComputerScreen extends AbstractContainerScreen<ComputerMenu> {
|
public class ComputerScreen extends AbstractContainerScreen<ComputerMenu> {
|
||||||
public ComputerScreen(ComputerMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
|
public ComputerScreen(ComputerMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
|
||||||
|
@ -16,6 +17,7 @@ public class ComputerScreen extends AbstractContainerScreen<ComputerMenu> {
|
||||||
}
|
}
|
||||||
|
|
||||||
String editingLine = "";
|
String editingLine = "";
|
||||||
|
int scroll = 0;
|
||||||
|
|
||||||
public void reinitDimensions() {
|
public void reinitDimensions() {
|
||||||
init();
|
init();
|
||||||
|
@ -43,6 +45,7 @@ public class ComputerScreen extends AbstractContainerScreen<ComputerMenu> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) {
|
public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) {
|
||||||
|
scroll = 0;
|
||||||
InputConstants.Key mouseKey = InputConstants.getKey(pKeyCode, pScanCode);
|
InputConstants.Key mouseKey = InputConstants.getKey(pKeyCode, pScanCode);
|
||||||
assert this.minecraft != null;
|
assert this.minecraft != null;
|
||||||
if (!this.minecraft.options.keyInventory.isActiveAndMatches(mouseKey) && super.keyPressed(pKeyCode, pScanCode, pModifiers))
|
if (!this.minecraft.options.keyInventory.isActiveAndMatches(mouseKey) && super.keyPressed(pKeyCode, pScanCode, pModifiers))
|
||||||
|
@ -59,12 +62,25 @@ public class ComputerScreen extends AbstractContainerScreen<ComputerMenu> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseScrolled(double pMouseX, double pMouseY, double pScrollX, double pScrollY) {
|
||||||
|
if (pScrollY < 0) {
|
||||||
|
scroll--;
|
||||||
|
return true;
|
||||||
|
} else if (pScrollY > 0) {
|
||||||
|
scroll++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.mouseScrolled(pMouseX, pMouseY, pScrollX, pScrollY);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderLabels(@NotNull GuiGraphics graphics, int pMouseX, int pMouseY) {
|
protected void renderLabels(@NotNull GuiGraphics graphics, int pMouseX, int pMouseY) {
|
||||||
int offsetY = 0;
|
int offsetY = 0;
|
||||||
var lines = menu.getLines();
|
var lines = menu.getLines();
|
||||||
//var renderedlines = lines.subList(lines.size() - menu.getRows(), lines.size());
|
//var renderedlines = lines.subList(lines.size() - menu.getRows(), lines.size());
|
||||||
for (int i = Math.max(0, lines.size() - menu.getRows() + 1); i < lines.size(); i++) {
|
scroll = Math.max(Math.min(scroll, lines.size() - 1), 0);
|
||||||
|
for (int i = Math.max(0, lines.size() - menu.getRows() + 1 - scroll); i < lines.size() - scroll; i++) {
|
||||||
graphics.drawString(font, lines.get(i), 0, offsetY, 0xFFFFFFFF);
|
graphics.drawString(font, lines.get(i), 0, offsetY, 0xFFFFFFFF);
|
||||||
offsetY += 11;
|
offsetY += 11;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue