Skip to content

Commit e03eba9

Browse files
committed
fix: force load enclosure
1 parent 7cce461 commit e03eba9

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

src/main/kotlin/com/github/zly2006/enclosure/EnclosureArea.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.zly2006.enclosure
22

33
import com.github.zly2006.enclosure.command.CONSOLE
4+
import com.github.zly2006.enclosure.command.MAX_CHUNK_LEVEL
45
import com.github.zly2006.enclosure.command.Session
56
import com.github.zly2006.enclosure.gui.EnclosureScreenHandler
67
import com.github.zly2006.enclosure.network.play.SyncPermissionS2CPacket
@@ -425,10 +426,7 @@ open class EnclosureArea : PersistentState, EnclosureView {
425426
ServerMain.getAllEnclosures(world).markDirty()
426427
if (ticket != null) {
427428
toBlockBox().streamChunkPos().forEach {
428-
val level = world.chunkManager.ticketManager.simulationDistanceTracker.getLevel(it.toLong())
429-
if (level > ticket!!.level) {
430-
world.chunkManager.addTicket(ChunkTicketType.FORCED, it, ticket!!.level, it)
431-
}
429+
world.chunkManager.addTicket(ChunkTicketType.FORCED, it, MAX_CHUNK_LEVEL - ticket!!.level, it)
432430
}
433431
}
434432
super.markDirty()

src/main/kotlin/com/github/zly2006/enclosure/EnclosureList.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package com.github.zly2006.enclosure
33
import com.github.zly2006.enclosure.ServerMain.enclosures
44
import com.github.zly2006.enclosure.ServerMain.getAllEnclosures
55
import com.github.zly2006.enclosure.access.ChunkAccess
6-
import com.github.zly2006.enclosure.utils.Serializable2Text
6+
import com.github.zly2006.enclosure.command.MAX_CHUNK_LEVEL
77
import com.github.zly2006.enclosure.utils.Serializable2Text.SerializationSettings.NameHover
88
import net.minecraft.nbt.NbtCompound
99
import net.minecraft.nbt.NbtList
1010
import net.minecraft.nbt.NbtString
1111
import net.minecraft.registry.RegistryWrapper
12+
import net.minecraft.server.world.ChunkLevelType
13+
import net.minecraft.server.world.ChunkLevels
1214
import net.minecraft.server.world.ChunkTicketType
1315
import net.minecraft.server.world.ServerWorld
1416
import net.minecraft.text.Text
@@ -114,8 +116,8 @@ class EnclosureList(world: ServerWorld, private val isRoot: Boolean) : Persisten
114116
if (area.ticket != null) {
115117
area.ticket!!.remainingTicks--
116118
if (area.ticket!!.remainingTicks <= 0) {
117-
area.ticket = null
118119
removeTicket(area, world)
120+
area.ticket = null
119121
world.server.playerManager.broadcast(
120122
Text.literal("Force loading for ").append(area.serialize(NameHover, null)).append(" expired."), false
121123
)
@@ -130,13 +132,15 @@ class EnclosureList(world: ServerWorld, private val isRoot: Boolean) : Persisten
130132
area.toBlockBox().streamChunkPos().forEach {
131133
val chunk = world.getChunkAsView(it.x, it.z)
132134
if (chunk is ChunkAccess) {
133-
val targetLevel = chunk.cache.mapNotNull { it.ticket }.minOfOrNull { it.level }
134-
world.chunkManager.ticketManager.ticketsByPosition.remove(it.toLong())
135-
if (targetLevel != null) {
136-
world.chunkManager.addTicket(ChunkTicketType.FORCED, it, targetLevel, it)
135+
val targetLevel = chunk.cache
136+
.filter { it.ticket != null && it != area }
137+
.minOfOrNull { it.ticket!!.level }
138+
?: ChunkLevels.getLevelFromType(ChunkLevelType.FULL) // chunk border level
139+
if (targetLevel > area.ticket!!.level) {
140+
world.chunkManager.removeTicket(ChunkTicketType.FORCED, it, MAX_CHUNK_LEVEL - area.ticket!!.level, it)
137141
}
138142
} else {
139-
world.chunkManager.removeTicket(ChunkTicketType.FORCED, it, area.ticket!!.level, it)
143+
world.chunkManager.removeTicket(ChunkTicketType.FORCED, it, MAX_CHUNK_LEVEL - area.ticket!!.level, it)
140144
}
141145
}
142146
}
@@ -146,7 +150,7 @@ class EnclosureList(world: ServerWorld, private val isRoot: Boolean) : Persisten
146150
if (area.ticket != null) {
147151
if (area.ticket!!.remainingTicks > 0) {
148152
area.toBlockBox().streamChunkPos().forEach {
149-
world.chunkManager.addTicket(ChunkTicketType.FORCED, it, area.ticket!!.level, it)
153+
world.chunkManager.addTicket(ChunkTicketType.FORCED, it, MAX_CHUNK_LEVEL - area.ticket!!.level, it)
150154
}
151155
// todo: message
152156
}

src/main/kotlin/com/github/zly2006/enclosure/command/ForceLoadSubcommand.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import net.minecraft.server.world.ChunkLevelType
1111
import net.minecraft.server.world.ChunkLevels
1212
import net.minecraft.text.Text
1313

14+
const val MAX_CHUNK_LEVEL = 33 // ChunkLevels.getLevelFromType(ChunkLevelType.FULL)
15+
1416
fun BuilderScope<*>.registerForceLoad() {
1517
fun forceLoad(source: ServerCommandSource, area: Enclosure, ticks: Int, level: Int) {
1618
val ticket = EnclosureArea.ForceLoadTicket(

src/main/resources/assets/enclosure/lang/en_us.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"enclosure.about.author": "Mod author: zly2006",
33
"enclosure.about.click_to_open": "Click to open URL",
4-
"enclosure.about.copyright": "Copyright (c) 2022-2023, zly2006 & contributors",
4+
"enclosure.about.copyright": "Copyright (c) 2022-2024, zly2006 & contributors",
55
"enclosure.about.source": "Source: https://github.com/zly2006/Enclosure",
66
"enclosure.about.team_page": "Team homepage: https://www.starlight.cool/",
77
"enclosure.about.version.client": "Client version: ",

src/main/resources/assets/enclosure/lang/zh_cn.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"enclosure.about.author": "Mod作者: zly2006, 贡献者: Disy920",
2+
"enclosure.about.author": "Mod作者: zly2006",
33
"enclosure.about.click_to_open": "点击打开URL",
4-
"enclosure.about.copyright": "版权所有 (c) 2022-2023, zly2006 和贡献者们",
4+
"enclosure.about.copyright": "版权所有 (c) 2022-2024, zly2006 和贡献者们",
55
"enclosure.about.source": "源码: https://github.com/zly2006/Enclosure",
66
"enclosure.about.team_page": "团队官网: https://www.starlight.cool/",
77
"enclosure.about.version.client": "客户端版本: ",

src/main/resources/enclosure.accesswidener

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ accessible field net/minecraft/server/world/ChunkTicketManager simulationDistanc
2020
accessible field net/minecraft/server/world/ServerChunkManager ticketManager Lnet/minecraft/server/world/ChunkTicketManager;
2121
accessible method net/minecraft/world/SimulationDistanceLevelPropagator getLevel (J)I
2222
accessible field net/minecraft/server/world/ChunkTicketManager ticketsByPosition Lit/unimi/dsi/fastutil/longs/Long2ObjectOpenHashMap;
23+
accessible method net/minecraft/server/world/ChunkTicketManager getTicketSet (J)Lnet/minecraft/util/collection/SortedArraySet;
24+
accessible method net/minecraft/server/world/ChunkTicketManager removeTicket (JLnet/minecraft/server/world/ChunkTicket;)V

0 commit comments

Comments
 (0)