Skip to content

Commit

Permalink
fix: furniture spawning
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed May 13, 2024
1 parent 351c0ea commit ef01268
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ object FurnitureHelpers {
val color = item?.itemMeta?.asColorable()?.color
return spawnLoc.spawnFromPrefab(prefabKey) {
if (color != null) set(BlockyFurniture.Color(color))
}.getOrNull() as? ItemDisplay
}.getOrThrow() as? ItemDisplay
}

//TODO Fix seat breaking below 0.0 offset and remove max() check here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import org.bukkit.entity.ItemDisplay

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

spawnLoc.spawn<ItemDisplay> {
Expand All @@ -32,7 +31,7 @@ fun GearyModule.createFurnitureSpawner() = observeWithData<AttemptSpawn>()
props.shadowStrength?.let { shadowStrength = it }
transformation = transformation.apply { scale.set(props.scale) }

color.let { entity.setPersisting(it) }
//color.let { entity.setPersisting(it) }
entity.set<BukkitEntity>(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ 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.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>()
.exec(query<BlockyFurniture/*, BlockyFurniture.Color*/, ItemDisplay>()) { (furniture/*, color*/, entity) ->
val itemStack = furniture.properties.itemStack?.toItemStackOrNull() ?: event.item.toItemStack()
fun GearyModule.createFurnitureItemSetter() = observeWithData<OnSet>()
.exec(query<BukkitEntity, SetItem, BlockyFurniture/*, BlockyFurniture.Color*/>()) { (entity, item, furniture/*, color*/) ->
val itemDisplay = entity as? ItemDisplay ?: return@exec
val itemStack = furniture.properties.itemStack?.toItemStackOrNull() ?: item.item.toItemStack()
val furnitureItem = itemStack.clone().editItemMeta {
displayName(Component.empty())
//color.color?.let { asColorable()?.color = it }
}
entity.itemStack = furnitureItem
itemDisplay.itemStack = furnitureItem
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ import com.mineinabyss.blocky.blocky
import com.mineinabyss.blocky.components.core.BlockyFurniture
import com.mineinabyss.blocky.components.features.furniture.BlockyModelEngine
import com.mineinabyss.geary.modules.GearyModule
import com.mineinabyss.geary.observers.events.OnSet
import com.mineinabyss.geary.systems.builders.observeWithData
import com.mineinabyss.geary.systems.query.query
import com.mineinabyss.idofront.plugin.Plugins
import com.mineinabyss.idofront.typealiases.BukkitEntity
import com.ticxo.modelengine.api.ModelEngineAPI
import org.bukkit.Bukkit
import org.bukkit.entity.ItemDisplay

fun GearyModule.createFurnitureMEGModelSetter() = observeWithData<BlockyModelEngine>()
.exec(query<ItemDisplay> { has<BlockyFurniture>() } ) { (itemDisplay) ->
fun GearyModule.createFurnitureMEGModelSetter() = observeWithData<OnSet>()
.exec(query<BukkitEntity, BlockyFurniture, BlockyModelEngine>()) { (entity, furniture, modelengine) ->
// Save for scheduled task
if (!Plugins.isEnabled("ModelEngine")) return@exec
val activeModel = ModelEngineAPI.createActiveModel(event.modelId)
val activeModel = ModelEngineAPI.createActiveModel(modelengine.modelId)
Bukkit.getScheduler().scheduleSyncDelayedTask(blocky.plugin, {
ModelEngineAPI.getOrCreateModeledEntity(itemDisplay).apply {
ModelEngineAPI.getOrCreateModeledEntity(entity).apply {
models.forEach {
removeModel(it.key)
it.value.destroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import com.mineinabyss.blocky.components.core.BlockyFurniture
import com.mineinabyss.blocky.components.features.furniture.BlockySeat
import com.mineinabyss.blocky.helpers.FurnitureHelpers
import com.mineinabyss.geary.modules.GearyModule
import com.mineinabyss.geary.observers.events.OnSet
import com.mineinabyss.geary.systems.builders.observeWithData
import com.mineinabyss.geary.systems.query.query
import com.mineinabyss.idofront.typealiases.BukkitEntity
import org.bukkit.Bukkit
import org.bukkit.entity.ItemDisplay

fun GearyModule.createFurnitureSeatSetter() = observeWithData<BlockySeat>()
.involving(query<ItemDisplay, BlockyFurniture>())
.exec { (entity, furniture) ->
val display = entity
fun GearyModule.createFurnitureSeatSetter() = observeWithData<OnSet>()
.exec(query<BukkitEntity, BlockyFurniture, BlockySeat>()) { (entity, furniture, seat) ->
val display = entity as? ItemDisplay ?: return@exec
val furniture = furniture
val seat = event
val seat = seat
val yaw = display.location.yaw

FurnitureHelpers.clearFurnitureSeats(display)
Expand Down

0 comments on commit ef01268

Please sign in to comment.