Skip to content

Commit

Permalink
refactor: handle hitboxes via entity-tracking events
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Sep 24, 2024
1 parent 78506f8 commit abc4c04
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 36 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group=com.mineinabyss
version=0.10
idofrontVersion=0.25.3
idofrontVersion=0.25.6

6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
gearyPaper = "0.30.14"
guiy="0.12.4-dev.1"
gearyPaper = "0.30.20"
guiy="0.12.4"

[libraries]
geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" }
guiy = { module = "com.mineinabyss:guiy-compose", version.ref = "guiy" }

minecraft-plugin-protectionlib = "io.th0rgal:protectionlib:1.6.0"
minecraft-plugin-protectionlib = "io.th0rgal:protectionlib:1.6.1"
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import com.mineinabyss.idofront.util.to
import com.ticxo.modelengine.api.events.BaseEntityInteractEvent
import io.papermc.paper.event.packet.PlayerChunkLoadEvent
import io.papermc.paper.event.packet.PlayerChunkUnloadEvent
import io.papermc.paper.event.player.PlayerTrackEntityEvent
import io.papermc.paper.event.player.PlayerUntrackEntityEvent
import io.th0rgal.protectionlib.ProtectionLib
import org.bukkit.*
import org.bukkit.block.BlockFace
Expand All @@ -41,41 +43,20 @@ import org.bukkit.util.Vector
class BlockyFurnitureListener : Listener {

@EventHandler(priority = EventPriority.HIGH)
fun PlayerChunkLoadEvent.onLoadChunk() {
chunk.entities.filterIsInstance<ItemDisplay>().forEach {
FurniturePacketHelpers.sendInteractionEntityPacket(it, player)
FurniturePacketHelpers.sendCollisionHitboxPacket(it, player)
FurniturePacketHelpers.sendLightPacket(it, player)
}
fun PlayerTrackEntityEvent.onTrackEntity() {
val baseEntity = entity as? ItemDisplay ?: return
FurniturePacketHelpers.sendInteractionEntityPacket(baseEntity, player)
FurniturePacketHelpers.sendCollisionHitboxPacket(baseEntity, player)
FurniturePacketHelpers.sendLightPacket(baseEntity, player)
}

@EventHandler
fun PlayerChunkUnloadEvent.onUnloadChunk() {
chunk.entities.filterIsInstance<ItemDisplay>().forEach {
FurniturePacketHelpers.removeInteractionHitboxPacket(it, player)
FurniturePacketHelpers.removeHitboxOutlinePacket(it, player)
FurniturePacketHelpers.removeCollisionHitboxPacket(it, player)
FurniturePacketHelpers.removeLightPacket(it, player)
}
}

@EventHandler(priority = EventPriority.LOWEST)
fun EntityRemoveFromWorldEvent.onRemoveFurniture() {
val entity = entity as? ItemDisplay ?: return
FurniturePacketHelpers.removeInteractionHitboxPacket(entity)
FurniturePacketHelpers.removeHitboxOutlinePacket(entity)
FurniturePacketHelpers.removeCollisionHitboxPacket(entity)
FurniturePacketHelpers.removeLightPacket(entity)
}

@EventHandler
fun PlayerChangedWorldEvent.onChangeWorld() {
from.entities.filterIsInstance<ItemDisplay>().forEach {
FurniturePacketHelpers.removeInteractionHitboxPacket(it, player)
FurniturePacketHelpers.removeHitboxOutlinePacket(it, player)
FurniturePacketHelpers.removeCollisionHitboxPacket(it, player)
FurniturePacketHelpers.removeLightPacket(it, player)
}
fun PlayerUntrackEntityEvent.onUntrackEntity() {
val baseEntity = entity as? ItemDisplay ?: return
FurniturePacketHelpers.removeInteractionHitboxPacket(baseEntity, player)
FurniturePacketHelpers.removeHitboxOutlinePacket(baseEntity, player)
FurniturePacketHelpers.removeCollisionHitboxPacket(baseEntity, player)
FurniturePacketHelpers.removeLightPacket(baseEntity, player)
}

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
Expand Down

0 comments on commit abc4c04

Please sign in to comment.