Skip to content

Commit

Permalink
Merge branch '1.20.2' into 1.20.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	settings.gradle.kts
  • Loading branch information
rfresh2 committed Dec 5, 2024
2 parents 129d016 + 936d9bb commit 2edeafb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,13 @@ public void setWindow(int regionX, int regionZ, int regionSize) {

private void loadHighlightsInWindow() {
executorService.execute(() -> {
final List<ChunkHighlightData> chunks = database.getHighlightsInWindow(
synchronized (this.chunks) {
database.getHighlightsInWindow(
dimension,
windowRegionX - windowRegionSize, windowRegionX + windowRegionSize,
windowRegionZ - windowRegionSize, windowRegionZ + windowRegionSize
);
synchronized (this.chunks) {
for (int i = 0; i < chunks.size(); i++) {
final ChunkHighlightData chunk = chunks.get(i);
this.chunks.put(chunkPosToLong(chunk.x(), chunk.z()), chunk.foundTime());
}
windowRegionZ - windowRegionSize, windowRegionZ + windowRegionSize,
(x, y, time) -> this.chunks.put(chunkPosToLong(x, y), time)
);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,15 @@ public void insertHighlightList(final List<ChunkHighlightData> chunks, final Res

private void insertHighlightsListInternal(final List<ChunkHighlightData> chunks, final ResourceKey<Level> dimension) {
try {
StringBuilder sb = new StringBuilder("INSERT OR IGNORE INTO \"" + getTableName(dimension) + "\" VALUES ");
for (int i = 0; i < chunks.size(); i++) {
ChunkHighlightData chunk = chunks.get(i);
sb.append("(").append(chunk.x()).append(", ").append(chunk.z()).append(", ").append(chunk.foundTime()).append(")");
if (i < chunks.size() - 1) {
sb.append(", ");
try (var ps = connection.prepareStatement("INSERT OR IGNORE INTO \"" + getTableName(dimension) + "\" VALUES (?, ?, ?)")) {
for (int i = 0; i < chunks.size(); i++) {
final ChunkHighlightData chunk = chunks.get(i);
ps.setInt(1, chunk.x());
ps.setInt(2, chunk.z());
ps.setLong(3, chunk.foundTime());
ps.addBatch();
}
}
try (var stmt = connection.createStatement()) {
stmt.executeUpdate(sb.toString());
ps.executeBatch();
}
} catch (Exception e) {
XaeroPlus.LOGGER.error("Error inserting {} chunks into {} database in dimension: {}", chunks.size(), databaseName, dimension.location(), e);
Expand All @@ -113,7 +112,7 @@ public List<ChunkHighlightData> getHighlightsInWindow(
chunks.add(new ChunkHighlightData(
resultSet.getInt("x"),
resultSet.getInt("z"),
resultSet.getInt("foundTime")));
resultSet.getLong("foundTime")));
}
return chunks;
}
Expand All @@ -124,6 +123,37 @@ public List<ChunkHighlightData> getHighlightsInWindow(
return Collections.emptyList();
}

@FunctionalInterface
public interface HighlightConsumer {
void accept(int x, int z, long foundTime);
}

// avoids instantiating the intermediary list
public void getHighlightsInWindow(
final ResourceKey<Level> dimension,
final int regionXMin, final int regionXMax,
final int regionZMin, final int regionZMax,
HighlightConsumer consumer
) {
try (var statement = connection.createStatement()) {
try (ResultSet resultSet = statement.executeQuery(
"SELECT * FROM \"" + getTableName(dimension) + "\" "
+ "WHERE x >= " + regionCoordToChunkCoord(regionXMin) + " AND x <= " + regionCoordToChunkCoord(regionXMax)
+ " AND z >= " + regionCoordToChunkCoord(regionZMin) + " AND z <= " + regionCoordToChunkCoord(regionZMax))) {
while (resultSet.next()) {
consumer.accept(
resultSet.getInt("x"),
resultSet.getInt("z"),
resultSet.getLong("foundTime")
);
}
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Error getting chunks from {} database in dimension: {}, window: {}-{}, {}-{}", databaseName, dimension.location(), regionXMin, regionXMax, regionZMin, regionZMax, e);
// fall through
}
}

public void removeHighlight(final int x, final int z, final ResourceKey<Level> dimension) {
try (var statement = connection.createStatement()) {
statement.executeUpdate("DELETE FROM \"" + getTableName(dimension) + "\" WHERE x = " + x + " AND z = " + z);
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencyResolutionManagement {
library("balm-neoforge", "maven.modrinth:balm:9.0.9+neoforge-1.20.4")
library("fabric-waystones", "maven.modrinth:fwaystones:3.3.2+mc1.20.4")
library("worldtools", "maven.modrinth:worldtools:1.2.4+1.20.4")
library("sqlite", "org.rfresh.xerial:sqlite-jdbc:3.46.1.0") // relocated xerial sqlite to avoid conflicts with other mods
library("sqlite", "org.rfresh.xerial:sqlite-jdbc:3.47.1.0") // relocated xerial sqlite to avoid conflicts with other mods
library("immediatelyfast", "maven.modrinth:immediatelyfast:1.2.18+1.20.4-fabric")
library("modmenu", "maven.modrinth:modmenu:9.0.0")
library("sodium", "maven.modrinth:sodium:mc1.20.4-0.5.8")
Expand Down

0 comments on commit 2edeafb

Please sign in to comment.