Skip to content

Commit

Permalink
Merge pull request #77 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Nov 13, 2023
2 parents 20fb2fc + bb5281c commit 4a9e9c3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
13 changes: 13 additions & 0 deletions common/src/main/java/dev/ftb/mods/ftblibrary/snbt/SNBT.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.nbt.*;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -20,6 +21,18 @@ public static SNBTCompoundTag readLines(List<String> lines) {
return SNBTParser.read(lines);
}

public static SNBTCompoundTag tryRead(Path path) throws IOException {
return readLines(Files.readAllLines(path, StandardCharsets.UTF_8));
}

public static void tryWrite(Path path, CompoundTag tag) throws IOException {
if (Files.notExists(path.getParent())) {
Files.createDirectories(path.getParent());
}

Files.write(path, writeLines(tag));
}

@Nullable
public static SNBTCompoundTag read(Path path) {
if (Files.notExists(path) || Files.isDirectory(path) || !Files.isReadable(path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ public int cursorPos() {
return textField.cursor();
}

public void selectCurrentLine() {
MultilineTextField.StringView view = textField.getLineView(textField.getLineAtCursor());
textField.setSelecting(false);
textField.seekCursor(Whence.ABSOLUTE, view.beginIndex());
textField.setSelecting(true);
textField.seekCursor(Whence.ABSOLUTE, view.endIndex());
}

public StringExtents getLineView() {
return StringExtents.of(textField.getLineView(textField.getLineAtCursor()));
}

public StringExtents getLineView(int line) {
return StringExtents.of(textField.getLineView(line));
}

public StringExtents getSelected() {
return StringExtents.of(textField.getSelected());
}

@Override
public void tick() {
++frame;
Expand Down Expand Up @@ -301,4 +321,10 @@ private void scrollToCursor() {
private int innerPadding() {
return 4;
}

public record StringExtents(int start, int end) {
public static StringExtents of (MultilineTextField.StringView view) {
return new StringExtents(view.beginIndex(), view.endIndex());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package dev.ftb.mods.ftblibrary.util;

import dev.ftb.mods.ftblibrary.config.NameMap;

public enum PanelPositioning {
BOTTOM_LEFT(0, 2),
LEFT(0, 1),
TOP_LEFT(0, 0),
TOP_CENTER(1, 0),
TOP_RIGHT(1, 0),
RIGHT(1, 1),
BOTTOM_RIGHT(1, 2),
BOTTOM_CENTER(1, 2);

public static final NameMap<PanelPositioning> NAME_MAP = NameMap.of(TOP_RIGHT, values()).baseNameKey("ftbquests.panel.position").create();

private final int posX;
private final int posY;

PanelPositioning(int x, int y) {
posX = x;
posY = y;
}

public PanelPos getPanelPos(int screenW, int screenH, int panelW, int panelH, int insetX, int insetY) {
int px = switch (posX) {
case 0 -> insetX;
case 1 -> (screenW - panelW) / 2;
default -> screenW - panelW - insetX;
};
int py = switch (posY) {
case 0 -> insetY;
case 1 -> (screenH - panelH) / 2;
default -> screenH - panelH - insetY;
};
return new PanelPos(px, py);
}

public PanelPos getPanelPos(int screenW, int screenH, int panelW, int panelH, float insetX, float insetY) {
return getPanelPos(screenW, screenH, panelW, panelH, (int)(screenW * insetX / 2), (int)(screenH * insetY / 2));
}

public record PanelPos(int x, int y) {
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false
mod_id=ftblibrary
archives_base_name=ftb-library
maven_group=dev.ftb.mods
mod_version=2001.1.3
mod_version=2001.1.4
mod_author=FTB Team
minecraft_version=1.20.1
architectury_version=9.0.8
Expand Down

0 comments on commit 4a9e9c3

Please sign in to comment.