@@ -22,11 +22,12 @@ val SectionKey.section get() = WorldManager.getSectionFor(this)
2222val 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 */
3738val 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