-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e8f4f7
commit cfa01d2
Showing
6 changed files
with
218 additions
and
140 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
37 changes: 0 additions & 37 deletions
37
nova/src/main/kotlin/xyz/xenondevs/nova/transformer/patch/chunk/ChunkLoadSchedulingPatch.kt
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
nova/src/main/kotlin/xyz/xenondevs/nova/transformer/patch/chunk/ChunkSchedulingPatch.kt
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,71 @@ | ||
package xyz.xenondevs.nova.transformer.patch.chunk | ||
|
||
import ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor | ||
import io.papermc.paper.chunk.system.ChunkSystem | ||
import io.papermc.paper.chunk.system.scheduling.ChunkTaskScheduler | ||
import net.minecraft.world.level.chunk.ChunkStatus | ||
import net.minecraft.world.level.chunk.LevelChunk | ||
import xyz.xenondevs.bytebase.asm.buildInsnList | ||
import xyz.xenondevs.bytebase.jvm.VirtualClassPath | ||
import xyz.xenondevs.nova.transformer.MultiTransformer | ||
import xyz.xenondevs.nova.util.reflection.ReflectionUtils | ||
import xyz.xenondevs.nova.world.ChunkPos | ||
import xyz.xenondevs.nova.world.format.WorldDataManager | ||
import java.util.function.Consumer | ||
import kotlin.reflect.KFunction | ||
|
||
private val CHUNK_TASK_SCHEDULER_SCHEDULE_CHUNK_LOAD_METHOD = ReflectionUtils.getMethod( | ||
ChunkTaskScheduler::class, | ||
false, | ||
"scheduleChunkLoad", | ||
Int::class, Int::class, ChunkStatus::class, Boolean::class, PrioritisedExecutor.Priority::class, Consumer::class | ||
) | ||
|
||
internal object ChunkSchedulingPatch : MultiTransformer(ChunkTaskScheduler::class, ChunkSystem::class) { | ||
|
||
override fun transform() { | ||
VirtualClassPath[CHUNK_TASK_SCHEDULER_SCHEDULE_CHUNK_LOAD_METHOD] | ||
.instructions.insert(buildInsnList { | ||
addLabel() | ||
aLoad(0) | ||
iLoad(1) | ||
iLoad(2) | ||
invokeStatic(::handleScheduleChunkLoad) | ||
}) | ||
|
||
fun insertEnableTicking(fn: KFunction<*>) = | ||
VirtualClassPath[fn].instructions.insert(buildInsnList { | ||
addLabel() | ||
aLoad(0) | ||
invokeStatic(::enableChunkTicking) | ||
}) | ||
|
||
fun insertDisableTicking(fn: KFunction<*>) = | ||
VirtualClassPath[fn].instructions.insert(buildInsnList { | ||
addLabel() | ||
aLoad(0) | ||
invokeStatic(::disableChunkTicking) | ||
}) | ||
|
||
insertEnableTicking(ChunkSystem::onChunkEntityTicking) | ||
insertEnableTicking(ChunkSystem::onChunkTicking) | ||
insertDisableTicking(ChunkSystem::onChunkNotTicking) | ||
insertDisableTicking(ChunkSystem::onChunkNotEntityTicking) | ||
} | ||
|
||
@JvmStatic | ||
fun handleScheduleChunkLoad(scheduler: ChunkTaskScheduler, x: Int, z: Int) { | ||
WorldDataManager.loadAsync(ChunkPos(scheduler.world.uuid, x, z)) | ||
} | ||
|
||
@JvmStatic | ||
fun enableChunkTicking(chunk: LevelChunk) { | ||
WorldDataManager.startTicking(ChunkPos(chunk.level.uuid, chunk.locX, chunk.locZ)) | ||
} | ||
|
||
@JvmStatic | ||
fun disableChunkTicking(chunk: LevelChunk) { | ||
WorldDataManager.stopTicking(ChunkPos(chunk.level.uuid, chunk.locX, chunk.locZ)) | ||
} | ||
|
||
} |
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
Oops, something went wrong.