Skip to content

Commit

Permalink
Add for 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dordsor21 committed Dec 24, 2024
1 parent 5689622 commit 162dea8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.fastasyncworldedit.core.queue.implementation.QueueHandler;
import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.MemUtil;
import com.fastasyncworldedit.core.util.NbtUtils;
import com.fastasyncworldedit.core.util.collection.AdaptedMap;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
Expand Down Expand Up @@ -211,7 +212,7 @@ public void setSkyLightingToGet(char[][] light, int minSectionPosition, int maxS
try {
fillLightNibble(light, LightLayer.SKY, minSectionPosition, maxSectionPosition);
} catch (Throwable e) {
LOGGER.error("Error setting lighting to get", e);
LOGGER.error("Error setting sky lighting to get", e);
}
}
}
Expand Down Expand Up @@ -432,7 +433,7 @@ public CompletableFuture<LevelChunk> ensureLoaded(ServerLevel nmsWorld, int chun
}

@Override
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "unchecked"})
public synchronized <T extends Future<T>> T call(IQueueExtent<? extends IChunk> owner, IChunkSet set, Runnable finalizer) {
if (!callLock.isHeldByCurrentThread()) {
throw new IllegalStateException("Attempted to call chunk GET but chunk was not call-locked.");
Expand All @@ -441,18 +442,34 @@ public synchronized <T extends Future<T>> T call(IQueueExtent<? extends IChunk>
final ServerLevel nmsWorld = serverLevel;
CompletableFuture<LevelChunk> nmsChunkFuture = ensureLoaded(nmsWorld, chunkX, chunkZ);
LevelChunk chunk = nmsChunkFuture.getNow(null);
if ((chunk == null && MemUtil.shouldBeginSlow()) || Settings.settings().QUEUE.ASYNC_CHUNK_LOAD_WRITE) {
try {
// "Artificially" slow FAWE down if memory low as performing the operation async can cause large amounts of
// memory usage
chunk = nmsChunkFuture.get();
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("Could not get chunk at {},{} whilst low memory", chunkX, chunkZ, e);
throw new FaweException(
TextComponent.of("Could not get chunk at " + chunkX + "," + chunkZ + " whilst low memory: " + e.getMessage()));
}
}
final int finalCopyKey = copyKey;
// Run immediately if possible
if (chunk != null) {
return tryWrappedInternalCall(set, finalizer, finalCopyKey, chunk, nmsWorld);
}
// Submit via the STQE as that will help handle excessive queuing by waiting for the submission count to fall below the
// target size
nmsChunkFuture.thenApply(nmsChunk -> owner.submitTaskUnchecked(() -> (T) tryWrappedInternalCall(
set,
finalizer,
finalCopyKey,
nmsChunk,
nmsWorld
)));
// If we have re-submitted, return a completed future to prevent potential deadlocks where a future reliant on the
// above submission is halting the BlockingExecutor, and preventing the above task from actually running. The futures
// submitted above will still be added to the STQE submissions.
return (T) (Future) CompletableFuture.completedFuture(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.CraftChunk;

import javax.annotation.Nonnull;
Expand All @@ -79,8 +78,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.IntFunction;

import static java.lang.invoke.MethodType.methodType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.fastasyncworldedit.core.queue.implementation.QueueHandler;
import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks;
import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.MemUtil;
import com.fastasyncworldedit.core.util.NbtUtils;
import com.fastasyncworldedit.core.util.collection.AdaptedMap;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
Expand Down Expand Up @@ -432,7 +433,7 @@ public CompletableFuture<LevelChunk> ensureLoaded(ServerLevel nmsWorld, int chun
}

@Override
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "unchecked"})
public synchronized <T extends Future<T>> T call(IQueueExtent<? extends IChunk> owner, IChunkSet set, Runnable finalizer) {
if (!callLock.isHeldByCurrentThread()) {
throw new IllegalStateException("Attempted to call chunk GET but chunk was not call-locked.");
Expand All @@ -441,18 +442,34 @@ public synchronized <T extends Future<T>> T call(IQueueExtent<? extends IChunk>
final ServerLevel nmsWorld = serverLevel;
CompletableFuture<LevelChunk> nmsChunkFuture = ensureLoaded(nmsWorld, chunkX, chunkZ);
LevelChunk chunk = nmsChunkFuture.getNow(null);
if ((chunk == null && MemUtil.shouldBeginSlow()) || Settings.settings().QUEUE.ASYNC_CHUNK_LOAD_WRITE) {
try {
// "Artificially" slow FAWE down if memory low as performing the operation async can cause large amounts of
// memory usage
chunk = nmsChunkFuture.get();
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("Could not get chunk at {},{} whilst low memory", chunkX, chunkZ, e);
throw new FaweException(
TextComponent.of("Could not get chunk at " + chunkX + "," + chunkZ + " whilst low memory: " + e.getMessage()));
}
}
final int finalCopyKey = copyKey;
// Run immediately if possible
if (chunk != null) {
return tryWrappedInternalCall(set, finalizer, finalCopyKey, chunk, nmsWorld);
}
// Submit via the STQE as that will help handle excessive queuing by waiting for the submission count to fall below the
// target size
nmsChunkFuture.thenApply(nmsChunk -> owner.submitTaskUnchecked(() -> (T) tryWrappedInternalCall(
set,
finalizer,
finalCopyKey,
nmsChunk,
nmsWorld
)));
// If we have re-submitted, return a completed future to prevent potential deadlocks where a future reliant on the
// above submission is halting the BlockingExecutor, and preventing the above task from actually running. The futures
// submitted above will still be added to the STQE submissions.
return (T) (Future) CompletableFuture.completedFuture(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.CraftChunk;

import javax.annotation.Nonnull;
Expand All @@ -78,8 +77,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.IntFunction;

import static java.lang.invoke.MethodType.methodType;
Expand Down

0 comments on commit 162dea8

Please sign in to comment.