Skip to content

Commit

Permalink
add modelengine-furniture listener handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Oct 24, 2023
1 parent e7fb553 commit 8179ade
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ dependencyResolutionManagement {
}

versionCatalogs {
create("libs").from("com.mineinabyss:catalog:$idofrontVersion")
create("libs"){
from("com.mineinabyss:catalog:$idofrontVersion")
version("modelengine", "R4.0.3")
}
create("blockyLibs").from(files("gradle/blockyLibs.versions.toml"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mccoroutine.bukkit.minecraftDispatcher
import com.mineinabyss.blocky.api.BlockyFurnitures.getBlockySeat
import com.mineinabyss.blocky.api.BlockyFurnitures.isBlockyFurniture
import com.mineinabyss.blocky.api.BlockyFurnitures.isModelEngineFurniture
import com.mineinabyss.blocky.api.BlockyFurnitures.removeFurniture
import com.mineinabyss.blocky.api.events.furniture.BlockyFurnitureInteractEvent
import com.mineinabyss.blocky.api.events.furniture.BlockyFurniturePlaceEvent
Expand All @@ -18,7 +19,7 @@ import com.mineinabyss.blocky.helpers.*
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.prefabs.helpers.prefabs
import com.mineinabyss.idofront.messaging.broadcast
import com.ticxo.modelengine.api.events.BaseEntityInteractEvent
import io.papermc.paper.event.packet.PlayerChunkLoadEvent
import io.th0rgal.protectionlib.ProtectionLib
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -97,7 +98,6 @@ class BlockyFurnitureListener : Listener {

@EventHandler
fun PlayerUseUnknownEntityEvent.onInteract() {
broadcast(this.entityId)
val baseFurniture = FurniturePacketHelpers.getBaseFurnitureFromInteractionEntity(entityId) ?: return
blocky.plugin.launch(blocky.plugin.minecraftDispatcher) {
when {
Expand All @@ -111,6 +111,20 @@ class BlockyFurnitureListener : Listener {
}
}

@EventHandler // ModelEngine-interaction check
fun BaseEntityInteractEvent.onModelEngineInteract() {
val baseEntity = baseEntity.original as? ItemDisplay ?: return
if (!baseEntity.isBlockyFurniture || !baseEntity.isModelEngineFurniture) return
when {
action == BaseEntityInteractEvent.Action.ATTACK -> removeFurniture(baseEntity, player)
else -> BlockyFurnitureInteractEvent(
baseEntity, player,
slot, player.inventory.itemInMainHand,
null, null
).callEvent()
}
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
fun BlockyFurnitureInteractEvent.onSitting() {
if (!ProtectionLib.canInteract(player, entity.location) || player.isSneaking) return
Expand Down

0 comments on commit 8179ade

Please sign in to comment.