Change ChunkMapMixin#read to asynchronously load data

There's no reason to sync read the data, as the return value
is a CompletableFuture - and Vanilla performs this function
asynchronously as well.
This commit is contained in:
Spottedleaf
2024-08-22 16:01:15 -07:00
parent 1b189fc0c1
commit 0266b87e0f
2 changed files with 26 additions and 22 deletions

View File

@@ -89,10 +89,10 @@ abstract class StateHolderMixin<O, S> implements PropertyAccessStateHolder {
@Overwrite
public <T extends Comparable<T>, V extends T> S setValue(final Property<T> property, final V value) {
final S ret = this.optimisedTable.set(this.tableIndex, property, value);
if (ret == null) {
throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner);
if (ret != null) {
return ret;
}
return ret;
throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner);
}
/**
@@ -101,11 +101,14 @@ abstract class StateHolderMixin<O, S> implements PropertyAccessStateHolder {
*/
@Overwrite
public <T extends Comparable<T>, V extends T> S trySetValue(final Property<T> property, final V value) {
final S ret = property == null ? (S)(StateHolder<O, S>)(Object)this : this.optimisedTable.trySet(this.tableIndex, property, value, (S)(StateHolder<O, S>)(Object)this);
if (ret == null) {
throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner);
if (property == null) {
return (S)(StateHolder<O, S>)(Object)this;
}
return ret;
final S ret = this.optimisedTable.trySet(this.tableIndex, property, value, (S)(StateHolder<O, S>)(Object)this);
if (ret != null) {
return ret;
}
throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner);
}
/**
@@ -124,11 +127,10 @@ abstract class StateHolderMixin<O, S> implements PropertyAccessStateHolder {
@Overwrite
public <T extends Comparable<T>> T getValue(final Property<T> property) {
final T ret = this.optimisedTable.get(this.tableIndex, property);
if (ret == null) {
throw new IllegalArgumentException("Cannot get property " + property + " as it does not exist in " + this.owner);
} else {
if (ret != null) {
return ret;
}
throw new IllegalArgumentException("Cannot get property " + property + " as it does not exist in " + this.owner);
}
/**

View File

@@ -507,18 +507,20 @@ abstract class ChunkMapMixin extends ChunkStorage implements ChunkSystemChunkMap
@Override
public CompletableFuture<Optional<CompoundTag>> read(final ChunkPos pos) {
try {
return CompletableFuture.completedFuture(
Optional.ofNullable(
MoonriseRegionFileIO.loadData(
this.level, pos.x, pos.z, MoonriseRegionFileIO.RegionFileType.CHUNK_DATA,
MoonriseRegionFileIO.getIOBlockingPriorityForCurrentThread()
)
)
);
} catch (final Throwable thr) {
return CompletableFuture.failedFuture(thr);
}
final CompletableFuture<Optional<CompoundTag>> ret = new CompletableFuture<>();
MoonriseRegionFileIO.loadDataAsync(
this.level, pos.x, pos.z, MoonriseRegionFileIO.RegionFileType.CHUNK_DATA,
(final CompoundTag data, final Throwable thr) -> {
if (thr != null) {
ret.completeExceptionally(thr);
} else {
ret.complete(Optional.ofNullable(data));
}
}, false
);
return ret;
}
@Override