Skip to content

Commit 1a10a70

Browse files
committed
Merge branch '1.21.8' into 1.21.10
2 parents 0a23b0d + 93d3db8 commit 1a10a70

6 files changed

Lines changed: 110 additions & 19 deletions

File tree

buildSrc/src/main/kotlin/xaeroplus-platform.conventions.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ loom {
1010
jvmArguments.addAll("-Dsodium.checks.issue2561=false", "-Xmx4G")
1111
programArguments.addAll("--username", "rfresh2")
1212
generateRunConfig = true
13-
preferGradleTask = false
13+
preferGradleTask = true
1414
}
1515
}
1616
// mixin {

common/src/main/java/xaeroplus/feature/drawing/DrawingHighlightCacheDimensionHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ public void removeHighlights(final LongCollection toRemove) {
195195
dbExecutor.execute(() -> database.removeHighlights(toRemove, dimension));
196196
}
197197

198+
public void removeAllHighlights() {
199+
if (!mc.isSameThread()) {
200+
throw new RuntimeException("removeAllHighlights must be called on the main thread!");
201+
}
202+
staleChunks.clear();
203+
chunks.clear();
204+
dbExecutor.execute(() -> database.removeAllHighlights(dimension));
205+
}
206+
198207
@Override
199208
public CompletableFuture<Long2LongMap> getHighlightsInCustomWindow(final int windowRegionX, final int windowRegionZ, final int windowRegionSize, final ResourceKey<Level> dimension) {
200209
// stale highlight write is async but our db executor is single threaded so we will always execute after the write task

common/src/main/java/xaeroplus/feature/drawing/DrawingLinesCacheDimensionHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ public void removeLine(Line line) {
6060
}
6161
}
6262

63+
public void removeAllLines() {
64+
if (!mc.isSameThread()) {
65+
throw new RuntimeException("removeAllLines must be called on the main thread!");
66+
}
67+
lines.clear();
68+
staleLines.clear();
69+
dbExecutor.execute(() -> database.removeAllLines(dimension));
70+
}
71+
6372
public Object2IntMap<Line> getLines() {
6473
return lines;
6574
}

common/src/main/java/xaeroplus/feature/drawing/DrawingTextCacheDimensionHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ public void removeText(int x, int z) {
5959
}
6060
}
6161

62+
public void removeAllTexts() {
63+
if (!mc.isSameThread()) {
64+
throw new RuntimeException("removeAllTexts must be called on the main thread!");
65+
}
66+
texts.clear();
67+
staleTexts.clear();
68+
dbExecutor.execute(() -> database.removeAllTexts(dimension));
69+
}
70+
6271
public Long2ObjectMap<Text> getTexts() {
6372
return texts;
6473
}

common/src/main/java/xaeroplus/feature/drawing/db/DrawingDatabase.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,31 @@ private boolean removeLine0(final int x1, final int z1, final int x2, final int
551551
return true;
552552
}
553553

554+
public void removeAllLines(final ResourceKey<Level> dimension) {
555+
int tryCount = 0;
556+
while (tryCount++ < MAX_RETRIES) {
557+
if (removeAllLines0(dimension)) {
558+
return;
559+
}
560+
XaeroPlus.LOGGER.info("Retrying removing all lines from {} database in dimension: {}, (attempt {}/{})", databaseName, dimension.location(), tryCount, MAX_RETRIES);
561+
Wait.waitMs(50);
562+
}
563+
}
564+
565+
private boolean removeAllLines0(final ResourceKey<Level> dimension) {
566+
try (var statement = connection.createStatement()) {
567+
statement.executeUpdate("DELETE FROM \"" + getTableName(dimension, LINES_TABLE) + "\"");
568+
} catch (SQLException e) {
569+
XaeroPlus.LOGGER.error("Error while removing all lines from {} database in dimension: {}", databaseName, dimension.location(), e);
570+
if (e.getErrorCode() == SQLiteErrorCode.SQLITE_CORRUPT.code) {
571+
XaeroPlus.LOGGER.error("Corruption detected in {} database", databaseName, e);
572+
recoverCorruptDatabase();
573+
}
574+
return false;
575+
}
576+
return true;
577+
}
578+
554579
public void removeHighlight(final int x, final int z, final ResourceKey<Level> dimension) {
555580
int tryCount = 0;
556581
while (tryCount++ < MAX_RETRIES) {
@@ -618,6 +643,31 @@ private boolean removeHighlights0(final LongCollection toRemove, final ResourceK
618643
return true;
619644
}
620645

646+
public void removeAllHighlights(final ResourceKey<Level> dimension) {
647+
int tryCount = 0;
648+
while (tryCount++ < 3) {
649+
if (removeAllHighlights0(dimension)) {
650+
return;
651+
}
652+
XaeroPlus.LOGGER.info("Retrying removing all highlights from {} database in dimension: {} (attempt {}/{})", databaseName, dimension.location(), tryCount, 3);
653+
Wait.waitMs(50);
654+
}
655+
}
656+
657+
private boolean removeAllHighlights0(final ResourceKey<Level> dimension) {
658+
try (var statement = connection.createStatement()) {
659+
statement.executeUpdate("DELETE FROM \"" + getTableName(dimension, HIGHLIGHTS_TABLE) + "\"");
660+
} catch (SQLException e) {
661+
XaeroPlus.LOGGER.error("Error while removing all highlights from {} database in dimension: {}", databaseName, dimension.location(), e);
662+
if (e.getErrorCode() == SQLiteErrorCode.SQLITE_CORRUPT.code) {
663+
XaeroPlus.LOGGER.error("Corruption detected in {} database", databaseName, e);
664+
recoverCorruptDatabase();
665+
}
666+
return false;
667+
}
668+
return true;
669+
}
670+
621671
public void removeText(final int x, final int z, final ResourceKey<Level> dimension) {
622672
int tryCount = 0;
623673
while (tryCount++ < MAX_RETRIES) {
@@ -643,6 +693,31 @@ private boolean removeText0(final int x, final int z, final ResourceKey<Level> d
643693
return true;
644694
}
645695

696+
public void removeAllTexts(final ResourceKey<Level> dimension) {
697+
int tryCount = 0;
698+
while (tryCount++ < MAX_RETRIES) {
699+
if (removeAllTexts0(dimension)) {
700+
return;
701+
}
702+
XaeroPlus.LOGGER.info("Retrying removing all texts from {} database in dimension: {}, (attempt {}/{})", databaseName, dimension.location(), tryCount, MAX_RETRIES);
703+
Wait.waitMs(50);
704+
}
705+
}
706+
707+
private boolean removeAllTexts0(final ResourceKey<Level> dimension) {
708+
try (var statement = connection.createStatement()) {
709+
statement.executeUpdate("DELETE FROM \"" + getTableName(dimension, TEXTS_TABLE) + "\"");
710+
} catch (SQLException e) {
711+
XaeroPlus.LOGGER.error("Error while removing all texts from {} database in dimension: {}", databaseName, dimension.location(), e);
712+
if (e.getErrorCode() == SQLiteErrorCode.SQLITE_CORRUPT.code) {
713+
XaeroPlus.LOGGER.error("Corruption detected in {} database", databaseName, e);
714+
recoverCorruptDatabase();
715+
}
716+
return false;
717+
}
718+
return true;
719+
}
720+
646721
@Override
647722
public void close() {
648723
try {

common/src/main/java/xaeroplus/module/impl/Drawing.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package xaeroplus.module.impl;
22

3-
import it.unimi.dsi.fastutil.longs.*;
3+
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
4+
import it.unimi.dsi.fastutil.longs.LongArrayList;
5+
import it.unimi.dsi.fastutil.longs.LongCollection;
6+
import it.unimi.dsi.fastutil.longs.LongList;
47
import it.unimi.dsi.fastutil.objects.Object2IntMap;
58
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
6-
import it.unimi.dsi.fastutil.objects.ObjectArraySet;
79
import net.lenni0451.lambdaevents.EventHandler;
810
import net.minecraft.resources.ResourceKey;
911
import net.minecraft.util.Mth;
@@ -339,26 +341,13 @@ public Line snap(int x1, int z1, int x2, int z2, double scale) {
339341

340342
public void clearAll() {
341343
drawingCache.getAllHighlightCaches().forEach(c -> {
342-
var keySet = new LongArraySet(c.chunks.keySet());
343-
for (var key : keySet) {
344-
var x = ChunkUtils.longToChunkX(key);
345-
var z = ChunkUtils.longToChunkZ(key);
346-
c.removeHighlight(x, z);
347-
}
344+
c.removeAllHighlights();
348345
});
349346
drawingCache.getAllLinesCaches().forEach(c -> {
350-
var lineSet = new ObjectArraySet<>(c.getLines().keySet());
351-
for (var line : lineSet) {
352-
c.removeLine(line);
353-
}
347+
c.removeAllLines();
354348
});
355349
drawingCache.getAllTextsCaches().forEach(c -> {
356-
var keySet = new LongArraySet(c.getTexts().keySet());
357-
for (var key : keySet) {
358-
var x = ChunkUtils.longToChunkX(key);
359-
var z = ChunkUtils.longToChunkZ(key);
360-
c.removeText(x, z);
361-
}
350+
c.removeAllTexts();
362351
});
363352
operationCollector = null;
364353
operationStack.clear();

0 commit comments

Comments
 (0)