Skip to content

Commit

Permalink
refactor: tweak some queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed May 13, 2024
1 parent 89b68b4 commit 1e43081
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import com.mineinabyss.geary.papermc.features.entities.sounds.Sounds
import com.mineinabyss.geary.papermc.tracking.entities.components.AttemptSpawn
import com.mineinabyss.geary.serialization.setPersisting
import com.mineinabyss.geary.systems.builders.observeWithData
import com.mineinabyss.geary.systems.query.Query
import com.mineinabyss.geary.systems.query.query
import com.mineinabyss.idofront.spawning.spawn
import com.mineinabyss.idofront.typealiases.BukkitEntity
import org.bukkit.entity.ItemDisplay

@OptIn(DangerousComponentOperation::class)
fun GearyModule.createFurnitureSpawner() = observeWithData<AttemptSpawn>()
.exec(query<BlockyFurniture/*, BlockyFurniture.Color*/>()) { (furniture/*, color*/) ->
val spawnLoc = event.location

spawnLoc.spawn<ItemDisplay> {
val props = furniture.properties
.exec(object : Query() {
val furniture by get<BlockyFurniture>()
val color by get<BlockyFurniture.Color>().orNull()
}) {
event.location.spawn<ItemDisplay> {
val props = it.furniture.properties

isPersistent = props.persistent
itemDisplayTransform = props.displayTransform
Expand All @@ -31,7 +33,7 @@ fun GearyModule.createFurnitureSpawner() = observeWithData<AttemptSpawn>()
props.shadowStrength?.let { shadowStrength = it }
transformation = transformation.apply { scale.set(props.scale) }

//color.let { entity.setPersisting(it) }
it.color?.let { entity.setPersisting(it) }
entity.set<BukkitEntity>(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ package com.mineinabyss.blocky.systems.actions

import com.mineinabyss.blocky.components.core.BlockyFurniture
import com.mineinabyss.geary.modules.GearyModule
import com.mineinabyss.geary.observers.events.OnSet
import com.mineinabyss.geary.papermc.tracking.items.components.SetItem
import com.mineinabyss.geary.systems.builders.observeWithData
import com.mineinabyss.geary.systems.builders.observe
import com.mineinabyss.geary.systems.query.Query
import com.mineinabyss.idofront.items.asColorable
import com.mineinabyss.idofront.items.editItemMeta
import com.mineinabyss.idofront.typealiases.BukkitEntity
import net.kyori.adventure.text.Component
import org.bukkit.entity.ItemDisplay

fun GearyModule.createFurnitureItemSetter() = observeWithData<SetItem>()
fun GearyModule.createFurnitureItemSetter() = observe<OnSet>()
.involving<SetItem, ItemDisplay, BlockyFurniture>()
.exec(object : Query() {
val entity by get<BukkitEntity>()
val itemDisplay by get<ItemDisplay>()
val furniture by get<BlockyFurniture>()
val color by get<BlockyFurniture.Color>().orNull()
val setItem by get<SetItem>()
}) {
val itemDisplay = it.entity as? ItemDisplay ?: return@exec
val itemStack = it.furniture.properties.itemStack?.toItemStackOrNull() ?: event.item.toItemStack()
val itemStack = it.furniture.properties.itemStack?.toItemStackOrNull() ?: it.setItem.item.toItemStack()
val furnitureItem = itemStack.clone().editItemMeta {
displayName(Component.empty())
it.color?.color?.let { c -> asColorable()?.color = c }
}
itemDisplay.itemStack = furnitureItem
it.itemDisplay.itemStack = furnitureItem
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import org.bukkit.Bukkit
import org.bukkit.entity.ItemDisplay

fun GearyModule.createFurnitureMEGModelSetter() = observeWithData<OnSet>()
.involving(query<BukkitEntity, BlockyFurniture, BlockyModelEngine>())
.exec { (entity, _, modelengine) ->
.involving(query<ItemDisplay, BlockyFurniture, BlockyModelEngine>())
.exec { (itemDisplay, _, modelengine) ->
// Save for scheduled task
if (!Plugins.isEnabled("ModelEngine")) return@exec
val activeModel = ModelEngineAPI.createActiveModel(modelengine.modelId)
Bukkit.getScheduler().scheduleSyncDelayedTask(blocky.plugin, {
ModelEngineAPI.getOrCreateModeledEntity(entity).apply {
ModelEngineAPI.getOrCreateModeledEntity(itemDisplay).apply {
models.forEach {
removeModel(it.key)
it.value.destroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import org.bukkit.Bukkit
import org.bukkit.entity.ItemDisplay

fun GearyModule.createFurnitureSeatSetter() = observe<OnSet>()
.involving(query<BukkitEntity, BlockyFurniture, BlockySeats>())
.exec { (entity, _, seats) ->
val display = entity as? ItemDisplay ?: return@exec
.involving(query<ItemDisplay, BlockyFurniture, BlockySeats>())
.exec { (itemDisplay, _, seats) ->
val itemDisplay = itemDisplay
val seats = seats

FurnitureHelpers.clearFurnitureSeats(display)
FurnitureHelpers.clearFurnitureSeats(itemDisplay)
Bukkit.getScheduler().scheduleSyncDelayedTask(blocky.plugin, {
FurnitureHelpers.spawnFurnitureSeat(display, seats)
FurnitureHelpers.spawnFurnitureSeat(itemDisplay, seats)
}, 1L)
}

0 comments on commit 1e43081

Please sign in to comment.