Skip to content

Commit

Permalink
feat: sync items removed by void to corresponding section
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Oct 18, 2024
1 parent 008e285 commit be6c8b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/main/kotlin/com/mineinabyss/deeperworld/DeeperConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ data class DeeperWorldConfig(
val damageOutsideSections: Double = 1.0,
@YamlComment("Worlds which shouldn't damage players when outside of a section.")
val damageExcludedWorlds: Set<@Serializable(with = WorldSerializer::class) World> = emptySet(),
@YamlComment("Sends an additional remount packet after this delay to prevent client-side mount bugs when moving between sections.\n")
val remountPacketDelay: Duration = 40.ticks,
val fall: FallDamageConfig = FallDamageConfig(),
val time: TimeConfig = TimeConfig(),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ object MovementListener : Listener {
.forEach { MovementHandler.handleMovement(it, from, to) }
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mineinabyss.deeperworld.synchronization

import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent
import com.github.shynixn.mccoroutine.bukkit.launch
import com.mineinabyss.deeperworld.deeperWorld
import com.mineinabyss.deeperworld.event.BlockSyncEvent
Expand All @@ -8,6 +9,7 @@ import com.mineinabyss.deeperworld.world.section.correspondingLocation
import com.mineinabyss.deeperworld.world.section.inSectionOverlap
import com.mineinabyss.idofront.events.call
import com.mineinabyss.idofront.plugin.Plugins
import com.mineinabyss.idofront.spawning.spawn
import com.mineinabyss.idofront.time.ticks
import kotlinx.coroutines.delay
import net.kyori.adventure.text.Component
Expand All @@ -24,6 +26,7 @@ import org.bukkit.block.data.type.Stairs
import org.bukkit.block.data.type.TrapDoor
import org.bukkit.block.sign.Side
import org.bukkit.entity.EntityType
import org.bukkit.entity.Item
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
Expand Down Expand Up @@ -244,4 +247,17 @@ object SectionSyncListener : Listener {

entity.world.getNearbyEntitiesByType(entityType.entityClass, corrLocation, 1.0).firstOrNull()?.remove()
}

/** Sync items removed by void to corresponding section */
@EventHandler
fun EntityRemoveFromWorldEvent.onVoidRemoval() {
val item = (entity as? Item)?.takeIf { it.y < it.world.minHeight } ?: return
val corrLoc = item.location.apply { y = -240.0 }.correspondingLocation ?: return
corrLoc.spawn<Item> {
itemStack = item.itemStack
thrower = item.thrower
owner = item.owner
velocity = velocity
}
}
}

0 comments on commit be6c8b3

Please sign in to comment.