minor format updating
This commit is contained in:
+10
-15
@@ -44,31 +44,26 @@ import java.util.function.Supplier;
|
||||
public abstract class ImmersivePortalsAccessorCommon extends ImmersivePortalsAbstractAccessor
|
||||
{
|
||||
@Override
|
||||
protected Object getClientLevel()
|
||||
{
|
||||
return Minecraft.getInstance().level;
|
||||
}
|
||||
protected Object getClientLevel() { return Minecraft.getInstance().level; }
|
||||
@Override
|
||||
protected Class<?> getLevelClass()
|
||||
{
|
||||
return Level.class;
|
||||
}
|
||||
protected Class<?> getLevelClass() { return Level.class; }
|
||||
@Override
|
||||
protected Iterable<?> getEntitiesForRendering()
|
||||
{
|
||||
return Minecraft.getInstance().level.entitiesForRendering();
|
||||
}
|
||||
protected Iterable<?> getEntitiesForRendering() { return Minecraft.getInstance().level.entitiesForRendering(); }
|
||||
|
||||
#if MC_VER < MC_1_21_6
|
||||
private static Matrix4f getProjectionMatrix() {
|
||||
private static Matrix4f getProjectionMatrix()
|
||||
{
|
||||
#if MC_VER > MC_1_16_5
|
||||
return RenderSystem.getProjectionMatrix();
|
||||
#else
|
||||
try {
|
||||
try
|
||||
{
|
||||
Class<?> renderStates = Class.forName("com.qouteall.immersive_portals.render.context_management.RenderStates");
|
||||
Field projectionMatrix = renderStates.getField("projectionMatrix");
|
||||
return (Matrix4f) projectionMatrix.get(null);
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
#endif
|
||||
|
||||
+21
-18
@@ -78,6 +78,7 @@ public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
private volatile long lastAccessTime = System.currentTimeMillis();
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
@@ -95,45 +96,46 @@ public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
//region
|
||||
|
||||
@Override
|
||||
public synchronized void markAccessed() {
|
||||
this.lastAccessTime = System.currentTimeMillis();
|
||||
}
|
||||
public synchronized void markAccessed() { this.lastAccessTime = System.currentTimeMillis(); }
|
||||
public synchronized long getLastAccessTime() { return this.lastAccessTime; }
|
||||
|
||||
private static final Timer CLIENT_CLEANUP_TIMER = TimerUtil.CreateTimer("ClientLevelTickCleanup");
|
||||
|
||||
private static final TimerTask CLIENT_CLEANUP_TASK = TimerUtil.createTimerTask(ClientLevelWrapper::tickCleanup);
|
||||
|
||||
static
|
||||
{
|
||||
// 20 ticks per second (50ms interval)
|
||||
CLIENT_CLEANUP_TIMER.scheduleAtFixedRate(CLIENT_CLEANUP_TASK, 0, 1000 / 20);
|
||||
}
|
||||
|
||||
private void unload() {
|
||||
private void unload()
|
||||
{
|
||||
AbstractDhWorld world = SharedApi.getAbstractDhWorld();
|
||||
if (world != null) {
|
||||
if (world != null)
|
||||
{
|
||||
world.unloadLevel(this);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
this.onUnload();
|
||||
}
|
||||
}
|
||||
|
||||
public static void tickCleanup()
|
||||
{
|
||||
if (MINECRAFT.level == null) { return; }
|
||||
|
||||
if (MINECRAFT.level == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long timeout = 30 * 1000;
|
||||
|
||||
List<ClientLevelWrapper> toUnload = new ArrayList<>();
|
||||
|
||||
ArrayList<ClientLevelWrapper> toUnload = new ArrayList<>();
|
||||
synchronized(LEVEL_WRAPPER_REF_BY_CLIENT_LEVEL)
|
||||
{
|
||||
for (WeakReference<ClientLevelWrapper> ref : LEVEL_WRAPPER_REF_BY_CLIENT_LEVEL.values())
|
||||
{
|
||||
ClientLevelWrapper wrapper = ref.get();
|
||||
if (wrapper != null && wrapper.level != MINECRAFT.level)
|
||||
if (wrapper != null
|
||||
&& wrapper.level != MINECRAFT.level)
|
||||
{
|
||||
// We use the synchronized getter to prevent race conditions with markAccessed()
|
||||
if (currentTime - wrapper.getLastAccessTime() > timeout)
|
||||
@@ -143,16 +145,17 @@ public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (ClientLevelWrapper wrapper : toUnload)
|
||||
{
|
||||
// Re-verify all conditions inside a synchronized block on the wrapper
|
||||
// to ensure atomicity with respect to markAccessed()
|
||||
synchronized(wrapper)
|
||||
{
|
||||
if (wrapper.level != MINECRAFT.level && currentTime - wrapper.getLastAccessTime() > timeout)
|
||||
if (wrapper.level != MINECRAFT.level
|
||||
&& currentTime - wrapper.getLastAccessTime() > timeout)
|
||||
{
|
||||
LOGGER.debug("Unloading level " + wrapper.getDhIdentifier() + " due to inactivity");
|
||||
LOGGER.debug("Unloading level [" + wrapper.getDhIdentifier() + "] due to inactivity");
|
||||
wrapper.unload();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
Submodule coreSubProjects updated: 25ac1de59b...4e647395e8
Reference in New Issue
Block a user