Skip to content

Commit

Permalink
fix: custom chunk ticket type
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed Jul 16, 2024
1 parent e03eba9 commit 450bfd9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.zly2006.enclosure

import com.github.zly2006.enclosure.command.CONSOLE
import com.github.zly2006.enclosure.command.FORCED
import com.github.zly2006.enclosure.command.MAX_CHUNK_LEVEL
import com.github.zly2006.enclosure.command.Session
import com.github.zly2006.enclosure.gui.EnclosureScreenHandler
Expand Down Expand Up @@ -426,7 +427,7 @@ open class EnclosureArea : PersistentState, EnclosureView {
ServerMain.getAllEnclosures(world).markDirty()
if (ticket != null) {
toBlockBox().streamChunkPos().forEach {
world.chunkManager.addTicket(ChunkTicketType.FORCED, it, MAX_CHUNK_LEVEL - ticket!!.level, it)
world.chunkManager.addTicket(FORCED, it, MAX_CHUNK_LEVEL - ticket!!.level, it)
}
}
super.markDirty()
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/com/github/zly2006/enclosure/EnclosureList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.zly2006.enclosure
import com.github.zly2006.enclosure.ServerMain.enclosures
import com.github.zly2006.enclosure.ServerMain.getAllEnclosures
import com.github.zly2006.enclosure.access.ChunkAccess
import com.github.zly2006.enclosure.command.FORCED
import com.github.zly2006.enclosure.command.MAX_CHUNK_LEVEL
import com.github.zly2006.enclosure.utils.Serializable2Text.SerializationSettings.NameHover
import net.minecraft.nbt.NbtCompound
Expand All @@ -11,7 +12,6 @@ import net.minecraft.nbt.NbtString
import net.minecraft.registry.RegistryWrapper
import net.minecraft.server.world.ChunkLevelType
import net.minecraft.server.world.ChunkLevels
import net.minecraft.server.world.ChunkTicketType
import net.minecraft.server.world.ServerWorld
import net.minecraft.text.Text
import net.minecraft.util.math.BlockPos
Expand Down Expand Up @@ -137,10 +137,10 @@ class EnclosureList(world: ServerWorld, private val isRoot: Boolean) : Persisten
.minOfOrNull { it.ticket!!.level }
?: ChunkLevels.getLevelFromType(ChunkLevelType.FULL) // chunk border level
if (targetLevel > area.ticket!!.level) {
world.chunkManager.removeTicket(ChunkTicketType.FORCED, it, MAX_CHUNK_LEVEL - area.ticket!!.level, it)
world.chunkManager.removeTicket(FORCED, it, MAX_CHUNK_LEVEL - area.ticket!!.level, it)
}
} else {
world.chunkManager.removeTicket(ChunkTicketType.FORCED, it, MAX_CHUNK_LEVEL - area.ticket!!.level, it)
world.chunkManager.removeTicket(FORCED, it, MAX_CHUNK_LEVEL - area.ticket!!.level, it)
}
}
}
Expand All @@ -150,7 +150,7 @@ class EnclosureList(world: ServerWorld, private val isRoot: Boolean) : Persisten
if (area.ticket != null) {
if (area.ticket!!.remainingTicks > 0) {
area.toBlockBox().streamChunkPos().forEach {
world.chunkManager.addTicket(ChunkTicketType.FORCED, it, MAX_CHUNK_LEVEL - area.ticket!!.level, it)
world.chunkManager.addTicket(FORCED, it, MAX_CHUNK_LEVEL - area.ticket!!.level, it)
}
// todo: message
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import me.lucko.fabric.api.permissions.v0.Options
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.server.world.ChunkLevelType
import net.minecraft.server.world.ChunkLevels
import net.minecraft.server.world.ChunkTicketType
import net.minecraft.text.Text
import net.minecraft.util.math.ChunkPos

const val MAX_CHUNK_LEVEL = 33 // ChunkLevels.getLevelFromType(ChunkLevelType.FULL)
val FORCED = ChunkTicketType.create<ChunkPos>("enclosure.forced", Comparator.comparingLong { it.toLong() })

fun BuilderScope<*>.registerForceLoad() {
fun forceLoad(source: ServerCommandSource, area: Enclosure, ticks: Int, level: Int) {
Expand Down

0 comments on commit 450bfd9

Please sign in to comment.