-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the gc free serializer compatible with lithium (maybe)
I can't test this for some reason?
- Loading branch information
Showing
2 changed files
with
88 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...alizer/src/main/java/com/ishland/c2me/opts/chunk_serializer/common/utils/LithiumUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.ishland.c2me.opts.chunk_serializer.common.utils; | ||
|
||
import com.ishland.c2me.opts.chunk_serializer.mixin.ChunkTickSchedulerAccessor; | ||
import it.unimi.dsi.fastutil.longs.Long2ReferenceAVLTreeMap; | ||
import net.minecraft.world.tick.ChunkTickScheduler; | ||
import net.minecraft.world.tick.OrderedTick; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Collection; | ||
|
||
public class LithiumUtil { | ||
static final Field chunkTickScheduler$TickQueuesByTimeAndPriority; | ||
|
||
|
||
static { | ||
Class<?> chunkTickSchedulerClass = ChunkTickScheduler.class; | ||
|
||
Field tickQueuesByTimeAndPriority = null; | ||
try { | ||
tickQueuesByTimeAndPriority = chunkTickSchedulerClass.getDeclaredField("tickQueuesByTimeAndPriority"); | ||
tickQueuesByTimeAndPriority.setAccessible(true); | ||
} catch (NoSuchFieldException e) { | ||
// pass | ||
} | ||
|
||
chunkTickScheduler$TickQueuesByTimeAndPriority = tickQueuesByTimeAndPriority; | ||
} | ||
|
||
public static final boolean IS_LITHIUM_TICK_QUEUE_ACTIVE = chunkTickScheduler$TickQueuesByTimeAndPriority != null; | ||
|
||
public static <T> Collection<Collection<OrderedTick<T>>> getTickQueueCollection(ChunkTickSchedulerAccessor<T> accessor) { | ||
try { | ||
//noinspection unchecked | ||
Long2ReferenceAVLTreeMap<Collection<OrderedTick<T>>> tickQueuesByTimeAndPriority = | ||
(Long2ReferenceAVLTreeMap<Collection<OrderedTick<T>>>) | ||
chunkTickScheduler$TickQueuesByTimeAndPriority.get(accessor); | ||
return tickQueuesByTimeAndPriority.values(); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |