Skip to content

Commit e95e0bc

Browse files
committed
fix: hardcode fix for archive server worldheight
1 parent f9897a3 commit e95e0bc

5 files changed

Lines changed: 28 additions & 27 deletions

File tree

src/main/kotlin/com/mineinabyss/deeperworld/DeeperCommands.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ object DeeperCommands {
110110
val loc = player.location
111111
val linkedSection = loc.correspondingSection ?: error("Corresponding Section not found")
112112

113-
val linkedBlock = loc.getCorrespondingLocation(section, linkedSection)?.block
113+
val linkedBlock = loc.correspondingLocation(section, linkedSection)?.block
114114
?: error("Corresponding Location not found")
115115

116116
val offset = pos2.y().coerceAtLeast(0)

src/main/kotlin/com/mineinabyss/deeperworld/synchronization/ContainerSyncListener.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import com.github.shynixn.mccoroutine.bukkit.launch
44
import com.mineinabyss.deeperworld.deeperWorld
55
import com.mineinabyss.deeperworld.world.section.*
66
import com.mineinabyss.idofront.messaging.info
7-
import com.mineinabyss.idofront.plugin.Plugins
87
import com.mineinabyss.idofront.time.ticks
98
import kotlinx.coroutines.delay
109
import nl.rutgerkok.blocklocker.BlockLockerAPIv2
11-
import nl.rutgerkok.blocklocker.SearchMode
1210
import org.bukkit.Chunk
13-
import org.bukkit.block.Block
1411
import org.bukkit.block.Container
1512
import org.bukkit.block.DecoratedPot
1613
import org.bukkit.block.Lidded
@@ -38,7 +35,7 @@ object ContainerSyncListener : Listener {
3835

3936
val section = block.location.section ?: return
4037
val linkedSection = block.location.correspondingSection ?: return
41-
val linkedBlock = block.location.getCorrespondingLocation(section, linkedSection)?.block ?: return
38+
val linkedBlock = block.location.correspondingLocation(section, linkedSection)?.block ?: return
4239

4340
blockLocker?.apply {
4441
updateProtection(linkedBlock)
@@ -53,7 +50,7 @@ object ContainerSyncListener : Listener {
5350

5451
if (container is Lidded) {
5552
(linkedBlock.state as Lidded).open()
56-
if (!section.isOnTopOf(linkedSection)) (container as Lidded).open()
53+
if (!section.isOnTopOf(linkedSection)) container.open()
5754
}
5855

5956
if (section.isOnTopOf(linkedSection)) return
@@ -91,7 +88,7 @@ object ContainerSyncListener : Listener {
9188
val section = block.location.section ?: return
9289
val linkedSection = block.location.correspondingSection ?: return
9390
val linkedBlock =
94-
block.location.getCorrespondingLocation(section, linkedSection)?.block?.state as? DecoratedPot ?: return
91+
block.location.correspondingLocation(section, linkedSection)?.block?.state as? DecoratedPot ?: return
9592

9693
deeperWorld.plugin.launch {
9794
delay(1.ticks)

src/main/kotlin/com/mineinabyss/deeperworld/synchronization/Updaters.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal inline fun Location.sync(
2828
if (!inSectionOverlap) return //ensure blocks don't get altered when we are outside of the corresponding region
2929
val section = section ?: return
3030
val correspondingSection = correspondingSection ?: return
31-
val corresponding = getCorrespondingLocation(section, correspondingSection) ?: return
31+
val corresponding = correspondingLocation(section, correspondingSection) ?: return
3232
updater(block, corresponding.block, section, correspondingSection)
3333
}
3434

src/main/kotlin/com/mineinabyss/deeperworld/world/section/Section.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ data class Section(
2929
val name: String? = null,
3030
val region: Region = Region(0,0,0,1,1,1),
3131
val world: @Serializable(WorldSerializer::class) World = Bukkit.getWorlds().first(),
32-
@SerialName("refTop") private val _refTop: String,
32+
@SerialName("refTop") private val refTop: String,
3333
@YamlComment("refBottom should connect to the refTop of the next section.")
34-
@SerialName("refBottom") private val _refBottom: String
34+
@SerialName("refBottom") private val refBottom: String
3535
) {
3636
@Serializable(LocationSerializer::class)
3737
@EncodeDefault(EncodeDefault.Mode.NEVER)
38-
val referenceTop = _refTop.toLocation(world)
38+
val referenceTop = refTop.toLocation(world)
3939

4040
@Serializable(LocationSerializer::class)
4141
@EncodeDefault(EncodeDefault.Mode.NEVER)
42-
val referenceBottom = _refBottom.toLocation(world)
42+
val referenceBottom = refBottom.toLocation(world)
4343

4444
fun String.toLocation(world: World): Location {
4545
val (x,y,z) = this.getCoordinates().map { it.toDouble() }

src/main/kotlin/com/mineinabyss/deeperworld/world/section/SectionUtils.kt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ val SectionKey.section get() = WorldManager.getSectionFor(this)
2222
val Location.correspondingSection: Section?
2323
get() {
2424
val section = this.section ?: return null
25-
val above: Section? = section.aboveKey.section
26-
val below: Section? = section.belowKey.section
25+
val aboveSection = section.aboveKey.section
26+
val belowSection = section.belowKey.section
27+
2728
return when {
28-
above != null && sharedBetween(section, above) -> above
29-
below != null && sharedBetween(section, below) -> below
29+
sharedBetween(section, aboveSection) -> aboveSection
30+
sharedBetween(section, belowSection) -> belowSection
3031
else -> null
3132
}
3233
}
@@ -36,7 +37,7 @@ val Location.correspondingSection: Section?
3637
*/
3738
val Location.correspondingLocation: Location?
3839
get() {
39-
return getCorrespondingLocation(section ?: return null, correspondingSection ?: return null)
40+
return correspondingLocation(section ?: return null, correspondingSection ?: return null)
4041
}
4142

4243
/**
@@ -47,7 +48,7 @@ val Location.correspondingLocation: Location?
4748
* @param sectionB the section we are translating the point to
4849
* @return A new location that corresponds to the original location
4950
*/
50-
fun Location.getCorrespondingLocation(sectionA: Section, sectionB: Section): Location? {
51+
fun Location.correspondingLocation(sectionA: Section, sectionB: Section): Location? {
5152
if (!sectionA.isAdjacentTo(sectionB)) return null
5253

5354
// We decide which two points we are translating between.
@@ -73,13 +74,17 @@ val Location.inSectionTransition: Boolean
7374
get() {
7475
// Get overlap of this section and corresponding section
7576
val shared = section?.overlapWith(correspondingSection ?: return false) ?: return false
76-
return blockY >= world.maxHeight - .3 * shared || blockY <= world.minHeight + .3 * shared
77+
// Archive Server hardcoding for now
78+
val minHeight = if ("2021" in world.name) 0 else world.minHeight
79+
return blockY >= world.maxHeight - .3 * shared || blockY <= minHeight + .3 * shared
7780
}
7881

79-
fun Location.sharedBetween(section: Section, otherSection: Section): Boolean {
80-
val overlap = section.overlapWith(otherSection) ?: return false
82+
fun Location.sharedBetween(section: Section, otherSection: Section?): Boolean {
83+
val overlap = section.overlapWith(otherSection ?: return false) ?: return false
84+
// Archive Server hardcoding for now
85+
val minHeight = if ("2021" in world.name) 0 else world.minHeight
8186
return when {
82-
section.isOnTopOf(otherSection) -> blockY <= world.minHeight + overlap
87+
section.isOnTopOf(otherSection) -> blockY <= minHeight + overlap
8388
otherSection.isOnTopOf(section) -> blockY >= world.maxHeight - overlap
8489
else -> false
8590
}
@@ -89,12 +94,11 @@ fun Section.overlapWith(other: Section): Int? {
8994
if (!isAdjacentTo(other)) return null
9095
if (min(this.region.max.y, other.region.max.y) <= max(this.region.min.y, other.region.min.y)) return null
9196
// We decide which two points we are translating between.
92-
val (locA, locB) = when (isOnTopOf(other)) {
93-
true -> referenceBottom to other.referenceTop
94-
false -> referenceTop to other.referenceBottom
97+
val (yA, yB) = when {
98+
isOnTopOf(other) -> referenceBottom.blockY to other.referenceTop.blockY
99+
else -> referenceTop.blockY to other.referenceBottom.blockY
95100
}
96-
val yA = locA.blockY
97-
val yB = locB.blockY
101+
98102
return max(this.region.max.y, other.region.max.y) - max(yA, yB) +
99103
(min(yA, yB) - min(this.region.min.y, other.region.min.y))
100104
}

0 commit comments

Comments
 (0)