mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-25 14:44:28 +00:00
Fix server thread leak in ThreadedBlockData (#2230)
This commit is contained in:
1 parent
5457df5369
commit
ce2462cad3
3 files changed
+30
-11
No files matched your search
@@ -2,30 +2,49 @@ package com.gtnewhorizons.angelica.client.rendering;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Used to store the block bounds fields in a thread-safe manner, as instance fields don't work correctly
|
||||
* on multiple threads.
|
||||
*/
|
||||
public class ThreadedBlockData {
|
||||
public static final Thread MAIN_THREAD = Thread.currentThread();
|
||||
public static Thread serverThread;
|
||||
public final class ThreadedBlockData {
|
||||
|
||||
public static final Thread MAIN_THREAD = Thread.currentThread();
|
||||
private static Thread SERVER_THREAD;
|
||||
private static final AtomicInteger CURRENT_SERVER_THREAD_ID = new AtomicInteger();
|
||||
|
||||
private final int serverThreadId = Thread.currentThread() == SERVER_THREAD ? CURRENT_SERVER_THREAD_ID.get() : -1;
|
||||
public double minX, minY, minZ, maxX, maxY, maxZ;
|
||||
public final Thread owner = Thread.currentThread();
|
||||
|
||||
public ThreadedBlockData() {}
|
||||
|
||||
public ThreadedBlockData(ThreadedBlockData other) {
|
||||
this.minX = other.minX;
|
||||
this.minY = other.minY;
|
||||
this.minY = other.minY;
|
||||
this.minZ = other.minZ;
|
||||
this.maxX = other.maxX;
|
||||
this.maxY = other.maxY;
|
||||
this.maxZ = other.maxZ;
|
||||
}
|
||||
|
||||
public boolean isCurrent() {
|
||||
return this.serverThreadId == CURRENT_SERVER_THREAD_ID.get();
|
||||
}
|
||||
|
||||
public static ThreadedBlockData get(Block block) {
|
||||
return ((Getter)block).angelica$getThreadData();
|
||||
return ((Getter) block).angelica$getThreadData();
|
||||
}
|
||||
|
||||
public static void setServerThread(Thread t) {
|
||||
ThreadedBlockData.SERVER_THREAD = t;
|
||||
if (t != null) {
|
||||
CURRENT_SERVER_THREAD_ID.incrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
public static Thread getServerThread() {
|
||||
return SERVER_THREAD;
|
||||
}
|
||||
|
||||
public interface Getter {
|
||||
|
||||
Reference in new issue
Block a user