From 34999abdd8ef3a340eb4b127e97b4abe5ba62be6 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Mon, 5 Feb 2024 00:06:27 -0500 Subject: [PATCH 1/6] Start converting furniture properties to Geary setter pattern --- .../com/mineinabyss/blocky/BlockyPlugin.kt | 27 +++-- .../blocky/components/core/BlockyFurniture.kt | 5 + .../features/furniture/BlockyModelEngine.kt | 7 +- .../features/furniture/BlockySeat.kt | 7 +- .../blocky/helpers/FurnitureHelpers.kt | 102 ++++++++---------- .../systems/AttemptSpawnFurnitureSystem.kt | 50 +++++++++ .../blocky/systems/FurnitureTrackerSystem.kt | 28 ----- .../actions/SetItemOnFurnitureSystem.kt | 33 ++++++ .../actions/SetMEGModelOnFurnitureSystem.kt | 34 ++++++ .../actions/SetSeatOnFurnitureSystem.kt | 27 +++++ .../cleanup/RemoveSeatsOnUnloadSystem.kt | 17 +++ 11 files changed, 234 insertions(+), 103 deletions(-) create mode 100644 src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt delete mode 100644 src/main/kotlin/com/mineinabyss/blocky/systems/FurnitureTrackerSystem.kt create mode 100644 src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt create mode 100644 src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetMEGModelOnFurnitureSystem.kt create mode 100644 src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetSeatOnFurnitureSystem.kt create mode 100644 src/main/kotlin/com/mineinabyss/blocky/systems/cleanup/RemoveSeatsOnUnloadSystem.kt diff --git a/src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt b/src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt index afc8be69..2de431ae 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt @@ -1,20 +1,17 @@ package com.mineinabyss.blocky -import com.comphenix.protocol.PacketType -import com.comphenix.protocol.ProtocolLibrary -import com.comphenix.protocol.events.ListenerPriority -import com.comphenix.protocol.events.PacketAdapter -import com.comphenix.protocol.events.PacketEvent -import com.mineinabyss.blocky.api.BlockyFurnitures -import com.mineinabyss.blocky.api.events.furniture.BlockyFurnitureInteractEvent import com.mineinabyss.blocky.assets_generation.MoreCreativeTabsGeneration import com.mineinabyss.blocky.assets_generation.ResourcepackGeneration import com.mineinabyss.blocky.compatibility.worldedit.WorldEditListener import com.mineinabyss.blocky.compatibility.worldedit.WorldEditSupport import com.mineinabyss.blocky.helpers.FurniturePacketHelpers import com.mineinabyss.blocky.listeners.* +import com.mineinabyss.blocky.systems.AttemptSpawnFurnitureSystem import com.mineinabyss.blocky.systems.FurnitureOutlineSystem -import com.mineinabyss.blocky.systems.FurnitureTrackerSystem +import com.mineinabyss.blocky.systems.actions.SetItemOnFurnitureSystem +import com.mineinabyss.blocky.systems.actions.SetMEGModelOnFurnitureSystem +import com.mineinabyss.blocky.systems.actions.SetSeatOnFurnitureSystem +import com.mineinabyss.blocky.systems.cleanup.RemoveSeatsOnUnloadSystem import com.mineinabyss.geary.addons.GearyPhase import com.mineinabyss.geary.autoscan.autoscan import com.mineinabyss.geary.modules.geary @@ -24,18 +21,13 @@ import com.mineinabyss.idofront.di.DI import com.mineinabyss.idofront.messaging.logError import com.mineinabyss.idofront.plugin.Plugins import com.mineinabyss.idofront.plugin.listeners -import com.mineinabyss.protocolburrito.dsl.protocolManager -import com.mineinabyss.protocolburrito.packets.ServerboundPlayerActionPacketWrap -import com.mineinabyss.protocolburrito.packets.ServerboundUseItemOnPacketWrap import com.sk89q.worldedit.WorldEdit import io.papermc.paper.configuration.GlobalConfiguration import it.unimi.dsi.fastutil.ints.IntArrayList import net.minecraft.core.registries.BuiltInRegistries -import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket import net.minecraft.resources.ResourceLocation import net.minecraft.tags.BlockTags import org.bukkit.block.data.BlockData -import org.bukkit.inventory.EquipmentSlot import org.bukkit.plugin.java.JavaPlugin var prefabMap = mapOf() @@ -58,7 +50,13 @@ class BlockyPlugin : JavaPlugin() { BlockyCommandExecutor() - geary.pipeline.addSystems(FurnitureTrackerSystem(), FurnitureOutlineSystem()) + geary.pipeline.addSystems( + AttemptSpawnFurnitureSystem(), + SetItemOnFurnitureSystem(), + SetSeatOnFurnitureSystem(), + SetMEGModelOnFurnitureSystem(), + FurnitureOutlineSystem() + ) FurniturePacketHelpers.registerPacketListeners() listeners( @@ -66,6 +64,7 @@ class BlockyPlugin : JavaPlugin() { BlockyFurnitureListener(), BlockyMiddleClickListener(), BlockyNMSListener(), + RemoveSeatsOnUnloadSystem(), ) blocky.config.run { diff --git a/src/main/kotlin/com/mineinabyss/blocky/components/core/BlockyFurniture.kt b/src/main/kotlin/com/mineinabyss/blocky/components/core/BlockyFurniture.kt index ca357333..85699547 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/components/core/BlockyFurniture.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/components/core/BlockyFurniture.kt @@ -1,6 +1,7 @@ package com.mineinabyss.blocky.components.core import com.mineinabyss.blocky.serializers.BrightnessSerializer +import com.mineinabyss.idofront.serialization.ColorSerializer import com.mineinabyss.idofront.serialization.SerializableItemStack import com.mineinabyss.idofront.serialization.Vector3fSerializer import com.mineinabyss.idofront.serialization.toSerializable @@ -85,4 +86,8 @@ data class BlockyFurniture( data class PreventItemStackUpdate( val forceWhenDifferentMaterial: Boolean = true, ) + + @Serializable + @SerialName("blocky:furniture_color") + data class Color(val color: @Serializable(with = ColorSerializer::class) org.bukkit.Color) } diff --git a/src/main/kotlin/com/mineinabyss/blocky/components/features/furniture/BlockyModelEngine.kt b/src/main/kotlin/com/mineinabyss/blocky/components/features/furniture/BlockyModelEngine.kt index fc2e552b..51e3c338 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/components/features/furniture/BlockyModelEngine.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/components/features/furniture/BlockyModelEngine.kt @@ -1,8 +1,13 @@ package com.mineinabyss.blocky.components.features.furniture +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable @SerialName("blocky:modelengine") -data class BlockyModelEngine(val modelId: String) +data class BlockyModelEngine(val modelId: String) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} diff --git a/src/main/kotlin/com/mineinabyss/blocky/components/features/furniture/BlockySeat.kt b/src/main/kotlin/com/mineinabyss/blocky/components/features/furniture/BlockySeat.kt index de872909..000a9522 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/components/features/furniture/BlockySeat.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/components/features/furniture/BlockySeat.kt @@ -1,8 +1,13 @@ package com.mineinabyss.blocky.components.features.furniture +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable @SerialName("blocky:seat") -data class BlockySeat (val heightOffset: Double = 0.0) +data class BlockySeat(val heightOffset: Double = 0.0) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} diff --git a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt index 2963d3b7..f7b08fb8 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt @@ -1,29 +1,19 @@ package com.mineinabyss.blocky.helpers -import com.github.shynixn.mccoroutine.bukkit.launch -import com.mineinabyss.blocky.blocky import com.mineinabyss.blocky.components.core.BlockyFurniture import com.mineinabyss.blocky.components.features.BlockyDrops import com.mineinabyss.blocky.components.features.furniture.BlockyAssociatedSeats -import com.mineinabyss.blocky.components.features.furniture.BlockyModelEngine -import com.mineinabyss.blocky.components.features.furniture.BlockySeat import com.mineinabyss.blocky.helpers.GenericHelpers.toBlockCenterLocation +import com.mineinabyss.geary.papermc.tracking.entities.helpers.spawnFromPrefab import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull -import com.mineinabyss.geary.papermc.tracking.items.components.SetItem import com.mineinabyss.geary.prefabs.PrefabKey -import com.mineinabyss.idofront.items.editItemMeta -import com.mineinabyss.idofront.messaging.broadcastVal -import com.mineinabyss.idofront.plugin.Plugins import com.mineinabyss.idofront.spawning.spawn -import com.ticxo.modelengine.api.ModelEngineAPI import io.papermc.paper.math.Position import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay -import net.kyori.adventure.text.Component import org.bukkit.Location -import org.bukkit.Material import org.bukkit.Rotation import org.bukkit.block.Block import org.bukkit.block.BlockFace @@ -44,13 +34,25 @@ object FurnitureHelpers { else placedAgainst.getRelative(blockFace).takeUnless { !it.type.isAir && it.isReplaceable } } - fun collisionHitboxLocations(rotation: Float, center: Location, hitbox: Set): List = + fun collisionHitboxLocations( + rotation: Float, + center: Location, + hitbox: Set + ): List = hitbox.map { c -> c.location.groundRotate(rotation).add(center) } - fun collisionHitboxPositions(rotation: Float, center: Location, hitbox: Set): List = + fun collisionHitboxPositions( + rotation: Float, + center: Location, + hitbox: Set + ): List = collisionHitboxLocations(rotation, center, hitbox).map { Position.block(it) } - fun interactionHitboxLocations(rotation: Float, center: Location, hitbox: Set): List = + fun interactionHitboxLocations( + rotation: Float, + center: Location, + hitbox: Set + ): List = hitbox.map { c -> c.originOffset.groundRotate(rotation).add(center) } fun rotation(yaw: Float, nullFurniture: BlockyFurniture?): Rotation { @@ -66,8 +68,16 @@ object FurnitureHelpers { fun hasEnoughSpace(blockyFurniture: BlockyFurniture, loc: Location, yaw: Float): Boolean { return if (blockyFurniture.collisionHitbox.isEmpty() && blockyFurniture.interactionHitbox.isEmpty()) true - else collisionHitboxLocations(yaw, loc, blockyFurniture.collisionHitbox).all { adjacent -> adjacent.block.isReplaceable } && - interactionHitboxLocations(yaw, loc, blockyFurniture.interactionHitbox).all { adjacent -> adjacent.block.isReplaceable } + else collisionHitboxLocations( + yaw, + loc, + blockyFurniture.collisionHitbox + ).all { adjacent -> adjacent.block.isReplaceable } && + interactionHitboxLocations( + yaw, + loc, + blockyFurniture.interactionHitbox + ).all { adjacent -> adjacent.block.isReplaceable } } @@ -79,13 +89,6 @@ object FurnitureHelpers { ): ItemDisplay? { val gearyEntity = prefabKey.toEntityOrNull() ?: return null val furniture = gearyEntity.get() ?: return null - val itemStack = furniture.properties.itemStack?.toItemStackOrNull() ?: item ?: gearyEntity.get()?.item?.toItemStack() ?: return null - val furnitureItem = itemStack.clone().editItemMeta { - displayName(Component.empty()) - (this as? LeatherArmorMeta)?.setColor((itemStack.itemMeta as? LeatherArmorMeta)?.color) - ?: (this as? PotionMeta)?.setColor((itemStack.itemMeta as? PotionMeta)?.color) - ?: (this as? MapMeta)?.setColor((itemStack.itemMeta as? MapMeta)?.color) ?: return@editItemMeta - } val spawnLoc = loc.clone().toBlockCenterLocation().apply { if (furniture.properties.displayTransform == NONE) this.y += 0.5 * furniture.properties.scale.y @@ -93,47 +96,21 @@ object FurnitureHelpers { this.pitch = if (furniture.properties.displayTransform == FIXED) 90f else 0f } - val newFurniture = spawnLoc.spawn { - isPersistent = furniture.properties.persistent - - furniture.properties.let { properties -> - itemDisplayTransform = properties.displayTransform - displayWidth = properties.displayWidth - displayHeight = properties.displayHeight - brightness = properties.brightness - billboard = properties.trackingRotation - properties.viewRange?.let { viewRange = it } - properties.shadowRadius?.let { shadowRadius = it } - properties.shadowStrength?.let { shadowStrength = it } - transformation = transformation.apply { scale.set(properties.scale) } - } - this.itemStack = furnitureItem - } ?: return null - - blocky.plugin.launch { newFurniture.delayUntilTracked().extend(gearyEntity) } - gearyEntity.get()?.let { meg -> - if (!Plugins.isEnabled("ModelEngine")) return@let - val activeModel = ModelEngineAPI.createActiveModel(meg.modelId) ?: return@let - ModelEngineAPI.getOrCreateModeledEntity(newFurniture).apply { - addModel(activeModel, false) - isBaseEntityVisible = false - isModelRotationLocked = false - } - } - - gearyEntity.get()?.let { seat -> - if (furniture.collisionHitbox.isNotEmpty()) { - collisionHitboxLocations(yaw, newFurniture.location, furniture.collisionHitbox) - .forEach { _ -> spawnFurnitureSeat(newFurniture, yaw - 180, seat.heightOffset) } - } else spawnFurnitureSeat(newFurniture, yaw, seat.heightOffset) + // Try to get held item's color, used to dye furniture + val color = item?.itemMeta.run { + (this as? LeatherArmorMeta)?.color + ?: (this as? PotionMeta)?.color + ?: (this as? MapMeta)?.color } - return newFurniture + return spawnLoc.spawnFromPrefab(prefabKey, initEvent = { + if (color != null) set(BlockyFurniture.Color(color)) + }).getOrThrow() as ItemDisplay } //TODO Fix seat breaking below 0.0 offset and remove max() check here - fun spawnFurnitureSeat(furniture: ItemDisplay, yaw: Float, height: Double = 0.0) = - furniture.location.toBlockCenterLocation().apply { y += max(0.0, height) }.spawn { + fun spawnFurnitureSeat(furniture: ItemDisplay, yaw: Float, height: Double = 0.0, location: Location) = + location.toBlockCenterLocation().apply { y += max(0.0, height) }.spawn { isVisible = false isMarker = true isSilent = true @@ -141,10 +118,17 @@ object FurnitureHelpers { setGravity(false) setRotation(yaw, 0F) }?.let { seat -> + seat.isPersistent = false furniture.toGeary().getOrSetPersisting { BlockyAssociatedSeats() }._seats.add(seat.uniqueId) seat } + fun clearFurnitureSeats(furniture: ItemDisplay) { + val gearyFurniture = furniture.toGearyOrNull() ?: return + gearyFurniture.get()?.seats?.forEach { it.remove() } + gearyFurniture.remove() + } + internal fun ItemDisplay.handleFurnitureDrops(player: Player) { this.toGearyOrNull()?.get()?.let { GenericHelpers.handleBlockDrop(it, player, location) } } diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt new file mode 100644 index 00000000..3e51073f --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt @@ -0,0 +1,50 @@ +package com.mineinabyss.blocky.systems + +import com.mineinabyss.blocky.components.core.BlockyFurniture +import com.mineinabyss.geary.annotations.optin.UnsafeAccessors +import com.mineinabyss.geary.datatypes.family.family +import com.mineinabyss.geary.papermc.tracking.entities.components.AttemptSpawn +import com.mineinabyss.geary.systems.GearyListener +import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.idofront.spawning.spawn +import com.mineinabyss.idofront.typealiases.BukkitEntity +import org.bukkit.entity.ItemDisplay + +class AttemptSpawnFurnitureSystem : GearyListener() { + private val Pointers.furniture by get().on(target) + + // private val Pointers.color by get().orNull().on(event) + private val Pointers.attemptSpawn by get().on(event) + + val Pointers.family by family { + not { has() } + }.on(target) + + + @OptIn(UnsafeAccessors::class) + override fun Pointers.handle() { + val color = event.entity.get() + val spawnLoc = attemptSpawn.location + + spawnLoc.spawn { + isPersistent = furniture.properties.persistent + + furniture.properties.let { properties -> + itemDisplayTransform = properties.displayTransform + displayWidth = properties.displayWidth + displayHeight = properties.displayHeight + brightness = properties.brightness + billboard = properties.trackingRotation + properties.viewRange?.let { viewRange = it } + properties.shadowRadius?.let { shadowRadius = it } + properties.shadowStrength?.let { shadowStrength = it } + transformation = transformation.apply { scale.set(properties.scale) } + } + if (color != null) { + target.entity.setPersisting(color) + } + target.entity.set(this) +// this.itemStack = furnitureItem + } ?: return + } +} diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/FurnitureTrackerSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/FurnitureTrackerSystem.kt deleted file mode 100644 index a419f454..00000000 --- a/src/main/kotlin/com/mineinabyss/blocky/systems/FurnitureTrackerSystem.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.mineinabyss.blocky.systems - -import com.mineinabyss.blocky.api.BlockyFurnitures.prefabKey -import com.mineinabyss.blocky.components.core.BlockyFurniture -import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull -import com.mineinabyss.geary.papermc.tracking.items.gearyItems -import com.mineinabyss.geary.systems.RepeatingSystem -import com.mineinabyss.geary.systems.accessors.Pointer -import com.mineinabyss.idofront.serialization.BaseSerializableItemStack -import com.mineinabyss.idofront.serialization.toSerializable -import com.mineinabyss.idofront.time.ticks -import org.bukkit.entity.ItemDisplay -import org.bukkit.inventory.ItemStack -import java.util.* - -class FurnitureTrackerSystem : RepeatingSystem(interval = 1.ticks) { - private val Pointer.furniture by get() - - override fun Pointer.tick() { - val preventUpdate = furniture.toGearyOrNull()?.get() - if (preventUpdate != null && !preventUpdate.forceWhenDifferentMaterial) return - val freshItem = furniture.prefabKey?.let { gearyItems.createItem(it, furniture.itemStack) } ?: return - // Skip updating if preventUpdate is present and forceWhenDifferentMaterial is true - if (preventUpdate != null && freshItem.type == furniture.itemStack?.type) return - furniture.itemStack = freshItem.toSerializable().toItemStack(furniture.itemStack ?: ItemStack.empty(), EnumSet.of(BaseSerializableItemStack.Properties.COLOR)) - } - -} \ No newline at end of file diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt new file mode 100644 index 00000000..bcc16b0a --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt @@ -0,0 +1,33 @@ +package com.mineinabyss.blocky.systems.actions + +import com.mineinabyss.blocky.components.core.BlockyFurniture +import com.mineinabyss.geary.papermc.tracking.items.components.SetItem +import com.mineinabyss.geary.systems.GearyListener +import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.idofront.items.editItemMeta +import net.kyori.adventure.text.Component +import org.bukkit.entity.ItemDisplay +import org.bukkit.inventory.meta.LeatherArmorMeta +import org.bukkit.inventory.meta.MapMeta +import org.bukkit.inventory.meta.PotionMeta + +class SetItemOnFurnitureSystem : GearyListener() { + private val Pointers.display by get().on(target) + private val Pointers.color by get().orNull().on(target) + private val Pointers.furniture by get().on(target) + private val Pointers.setItem by get().on(source) + + override fun Pointers.handle() { + val color = color?.color + val itemStack = furniture.properties.itemStack?.toItemStackOrNull() ?: setItem.item.toItemStack() + val furnitureItem = itemStack.clone().editItemMeta { + displayName(Component.empty()) + if (color != null) { + (this as? LeatherArmorMeta)?.setColor(color) + ?: (this as? PotionMeta)?.setColor(color) + ?: (this as? MapMeta)?.setColor(color) ?: return@editItemMeta + } + } + display.itemStack = furnitureItem + } +} diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetMEGModelOnFurnitureSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetMEGModelOnFurnitureSystem.kt new file mode 100644 index 00000000..3ad20fd3 --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetMEGModelOnFurnitureSystem.kt @@ -0,0 +1,34 @@ +package com.mineinabyss.blocky.systems.actions + +import com.mineinabyss.blocky.blocky +import com.mineinabyss.blocky.components.core.BlockyFurniture +import com.mineinabyss.blocky.components.features.furniture.BlockyModelEngine +import com.mineinabyss.geary.systems.GearyListener +import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.idofront.plugin.Plugins +import com.ticxo.modelengine.api.ModelEngineAPI +import org.bukkit.Bukkit +import org.bukkit.entity.ItemDisplay + +class SetMEGModelOnFurnitureSystem : GearyListener() { + private val Pointers.display by get().on(target) + private val Pointers.furniture by get().on(target) + private val Pointers.meg by get().on(source) + + override fun Pointers.handle() { + if (!Plugins.isEnabled("ModelEngine")) return + val activeModel = ModelEngineAPI.createActiveModel(meg.modelId) + Bukkit.getScheduler().scheduleSyncDelayedTask(blocky.plugin, { + ModelEngineAPI.getOrCreateModeledEntity(display).apply { + models.forEach { + removeModel(it.key) + it.value.destroy() + } +// setSaved(false) + addModel(activeModel, false) + isBaseEntityVisible = false + isModelRotationLocked = false + } + }, 2L) + } +} diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetSeatOnFurnitureSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetSeatOnFurnitureSystem.kt new file mode 100644 index 00000000..7de54a23 --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetSeatOnFurnitureSystem.kt @@ -0,0 +1,27 @@ +package com.mineinabyss.blocky.systems.actions + +import com.mineinabyss.blocky.blocky +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.systems.GearyListener +import com.mineinabyss.geary.systems.accessors.Pointers +import org.bukkit.Bukkit +import org.bukkit.entity.ItemDisplay + +class SetSeatOnFurnitureSystem : GearyListener() { + private val Pointers.display by get().on(target) + private val Pointers.furniture by get().on(target) + private val Pointers.seat by get().on(source) + + override fun Pointers.handle() { + val yaw = display.location.yaw + FurnitureHelpers.clearFurnitureSeats(display) + Bukkit.getScheduler().scheduleSyncDelayedTask(blocky.plugin, { + if (furniture.collisionHitbox.isNotEmpty()) { + FurnitureHelpers.collisionHitboxLocations(yaw, display.location, furniture.collisionHitbox) + .forEach { loc -> FurnitureHelpers.spawnFurnitureSeat(display, yaw - 180, seat.heightOffset, loc) } + } else FurnitureHelpers.spawnFurnitureSeat(display, yaw, seat.heightOffset, display.location) + }, 1L) + } +} diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/cleanup/RemoveSeatsOnUnloadSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/cleanup/RemoveSeatsOnUnloadSystem.kt new file mode 100644 index 00000000..d32d4ab0 --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/blocky/systems/cleanup/RemoveSeatsOnUnloadSystem.kt @@ -0,0 +1,17 @@ +package com.mineinabyss.blocky.systems.cleanup + +import com.mineinabyss.blocky.components.features.furniture.BlockySeat +import com.mineinabyss.geary.papermc.tracking.entities.events.GearyEntityRemoveFromWorldEvent +import org.bukkit.entity.ItemDisplay +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener + +class RemoveSeatsOnUnloadSystem : Listener { + @EventHandler + fun GearyEntityRemoveFromWorldEvent.onRemoveSeats() { + val display = entity as? ItemDisplay ?: return + if (gearyEntity.has()) { +// FurnitureHelpers.clearFurnitureSeats(display) + } + } +} From 8d36d247743bd7a056708afbb02f9b405175ebfe Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Mon, 5 Feb 2024 00:31:44 -0500 Subject: [PATCH 2/6] Delete cleanup seats system --- .../com/mineinabyss/blocky/BlockyPlugin.kt | 2 -- .../cleanup/RemoveSeatsOnUnloadSystem.kt | 17 ----------------- 2 files changed, 19 deletions(-) delete mode 100644 src/main/kotlin/com/mineinabyss/blocky/systems/cleanup/RemoveSeatsOnUnloadSystem.kt diff --git a/src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt b/src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt index 2de431ae..15a61ee7 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt @@ -11,7 +11,6 @@ import com.mineinabyss.blocky.systems.FurnitureOutlineSystem import com.mineinabyss.blocky.systems.actions.SetItemOnFurnitureSystem import com.mineinabyss.blocky.systems.actions.SetMEGModelOnFurnitureSystem import com.mineinabyss.blocky.systems.actions.SetSeatOnFurnitureSystem -import com.mineinabyss.blocky.systems.cleanup.RemoveSeatsOnUnloadSystem import com.mineinabyss.geary.addons.GearyPhase import com.mineinabyss.geary.autoscan.autoscan import com.mineinabyss.geary.modules.geary @@ -64,7 +63,6 @@ class BlockyPlugin : JavaPlugin() { BlockyFurnitureListener(), BlockyMiddleClickListener(), BlockyNMSListener(), - RemoveSeatsOnUnloadSystem(), ) blocky.config.run { diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/cleanup/RemoveSeatsOnUnloadSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/cleanup/RemoveSeatsOnUnloadSystem.kt deleted file mode 100644 index d32d4ab0..00000000 --- a/src/main/kotlin/com/mineinabyss/blocky/systems/cleanup/RemoveSeatsOnUnloadSystem.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.mineinabyss.blocky.systems.cleanup - -import com.mineinabyss.blocky.components.features.furniture.BlockySeat -import com.mineinabyss.geary.papermc.tracking.entities.events.GearyEntityRemoveFromWorldEvent -import org.bukkit.entity.ItemDisplay -import org.bukkit.event.EventHandler -import org.bukkit.event.Listener - -class RemoveSeatsOnUnloadSystem : Listener { - @EventHandler - fun GearyEntityRemoveFromWorldEvent.onRemoveSeats() { - val display = entity as? ItemDisplay ?: return - if (gearyEntity.has()) { -// FurnitureHelpers.clearFurnitureSeats(display) - } - } -} From 298af933fc1ca3a447d3f56d37e382e720c7cbb7 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Mon, 5 Feb 2024 22:48:54 -0500 Subject: [PATCH 3/6] Cleanup and address change requests --- .../blocky/BlockyCommandExecutor.kt | 11 +++-- .../blocky/helpers/FurnitureHelpers.kt | 26 +++-------- .../blocky/helpers/ItemMetaHelpers.kt | 44 +++++++++++++++++++ .../systems/AttemptSpawnFurnitureSystem.kt | 34 +++++++------- .../actions/SetItemOnFurnitureSystem.kt | 13 ++---- 5 files changed, 74 insertions(+), 54 deletions(-) create mode 100644 src/main/kotlin/com/mineinabyss/blocky/helpers/ItemMetaHelpers.kt diff --git a/src/main/kotlin/com/mineinabyss/blocky/BlockyCommandExecutor.kt b/src/main/kotlin/com/mineinabyss/blocky/BlockyCommandExecutor.kt index e4ce3849..8c7c106d 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/BlockyCommandExecutor.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/BlockyCommandExecutor.kt @@ -3,6 +3,7 @@ package com.mineinabyss.blocky import com.github.shynixn.mccoroutine.bukkit.launch import com.mineinabyss.blocky.components.core.BlockyFurniture import com.mineinabyss.blocky.components.features.blocks.BlockyDirectional +import com.mineinabyss.blocky.helpers.asRGBColorable import com.mineinabyss.blocky.helpers.gearyInventory import com.mineinabyss.blocky.menus.BlockyMainMenu import com.mineinabyss.blocky.systems.BlockyBlockQuery.prefabKey @@ -26,9 +27,6 @@ import org.bukkit.command.CommandSender import org.bukkit.command.TabCompleter import org.bukkit.entity.Player import org.bukkit.inventory.EquipmentSlot -import org.bukkit.inventory.meta.LeatherArmorMeta -import org.bukkit.inventory.meta.MapMeta -import org.bukkit.inventory.meta.PotionMeta @OptIn(UnsafeAccessors::class) class BlockyCommandExecutor : IdofrontCommandExecutor(), TabCompleter { @@ -78,9 +76,10 @@ class BlockyCommandExecutor : IdofrontCommandExecutor(), TabCompleter { } item.editItemMeta { - (this as? LeatherArmorMeta)?.setColor(color.toColor) - ?: (this as? PotionMeta)?.setColor(color.toColor) - ?: (this as? MapMeta)?.setColor(color.toColor) ?: return@playerAction + (asRGBColorable() ?: run { + player.error("This item cannot be dyed.") + return@playerAction + }).color = color.toColor } player.success("Dyed item to <$color>$color") } diff --git a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt index f7b08fb8..a482c3ef 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt @@ -23,9 +23,6 @@ import org.bukkit.entity.ItemDisplay.ItemDisplayTransform.FIXED import org.bukkit.entity.ItemDisplay.ItemDisplayTransform.NONE import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack -import org.bukkit.inventory.meta.LeatherArmorMeta -import org.bukkit.inventory.meta.MapMeta -import org.bukkit.inventory.meta.PotionMeta import kotlin.math.max object FurnitureHelpers { @@ -67,17 +64,11 @@ object FurnitureHelpers { fun yaw(rotation: Rotation) = Rotation.entries.indexOf(rotation) * 360f / 8f fun hasEnoughSpace(blockyFurniture: BlockyFurniture, loc: Location, yaw: Float): Boolean { - return if (blockyFurniture.collisionHitbox.isEmpty() && blockyFurniture.interactionHitbox.isEmpty()) true - else collisionHitboxLocations( - yaw, - loc, - blockyFurniture.collisionHitbox - ).all { adjacent -> adjacent.block.isReplaceable } && - interactionHitboxLocations( - yaw, - loc, - blockyFurniture.interactionHitbox - ).all { adjacent -> adjacent.block.isReplaceable } + if (blockyFurniture.collisionHitbox.isEmpty() && blockyFurniture.interactionHitbox.isEmpty()) return true + + return collisionHitboxLocations(yaw, loc, blockyFurniture.collisionHitbox) + .plus(interactionHitboxLocations(yaw, loc, blockyFurniture.interactionHitbox)) + .all { adjacent -> adjacent.block.isReplaceable } } @@ -97,11 +88,8 @@ object FurnitureHelpers { } // Try to get held item's color, used to dye furniture - val color = item?.itemMeta.run { - (this as? LeatherArmorMeta)?.color - ?: (this as? PotionMeta)?.color - ?: (this as? MapMeta)?.color - } + + val color = item?.itemMeta?.asRGBColorable()?.color return spawnLoc.spawnFromPrefab(prefabKey, initEvent = { if (color != null) set(BlockyFurniture.Color(color)) diff --git a/src/main/kotlin/com/mineinabyss/blocky/helpers/ItemMetaHelpers.kt b/src/main/kotlin/com/mineinabyss/blocky/helpers/ItemMetaHelpers.kt new file mode 100644 index 00000000..90efde00 --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/blocky/helpers/ItemMetaHelpers.kt @@ -0,0 +1,44 @@ +package com.mineinabyss.blocky.helpers + +import org.bukkit.Color +import org.bukkit.inventory.meta.ItemMeta +import org.bukkit.inventory.meta.LeatherArmorMeta +import org.bukkit.inventory.meta.MapMeta +import org.bukkit.inventory.meta.PotionMeta + +interface RGBColorable { + var color: Color? +} + +/** + * These different ItemMeta classes don't share a common color property so we use this :( + */ +fun ItemMeta.asRGBColorable(): RGBColorable? { + return when (val meta = this) { + is LeatherArmorMeta -> object : RGBColorable { + override var color: Color? + get() = meta.color + set(value) { + meta.setColor(value) + } + } + + is PotionMeta -> object : RGBColorable { + override var color: Color? + get() = meta.color + set(value) { + meta.color = value + } + } + + is MapMeta -> object : RGBColorable { + override var color: Color? + get() = meta.color + set(value) { + meta.color = value + } + } + + else -> null + } +} diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt index 3e51073f..8d4e8c16 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt @@ -13,8 +13,8 @@ import org.bukkit.entity.ItemDisplay class AttemptSpawnFurnitureSystem : GearyListener() { private val Pointers.furniture by get().on(target) - // private val Pointers.color by get().orNull().on(event) private val Pointers.attemptSpawn by get().on(event) + private val Pointers.color by get().orNull().on(event) val Pointers.family by family { not { has() } @@ -23,28 +23,24 @@ class AttemptSpawnFurnitureSystem : GearyListener() { @OptIn(UnsafeAccessors::class) override fun Pointers.handle() { - val color = event.entity.get() val spawnLoc = attemptSpawn.location spawnLoc.spawn { - isPersistent = furniture.properties.persistent - - furniture.properties.let { properties -> - itemDisplayTransform = properties.displayTransform - displayWidth = properties.displayWidth - displayHeight = properties.displayHeight - brightness = properties.brightness - billboard = properties.trackingRotation - properties.viewRange?.let { viewRange = it } - properties.shadowRadius?.let { shadowRadius = it } - properties.shadowStrength?.let { shadowStrength = it } - transformation = transformation.apply { scale.set(properties.scale) } - } - if (color != null) { - target.entity.setPersisting(color) - } + val props = furniture.properties + + isPersistent = props.persistent + itemDisplayTransform = props.displayTransform + displayWidth = props.displayWidth + displayHeight = props.displayHeight + brightness = props.brightness + billboard = props.trackingRotation + props.viewRange?.let { viewRange = it } + props.shadowRadius?.let { shadowRadius = it } + props.shadowStrength?.let { shadowStrength = it } + transformation = transformation.apply { scale.set(props.scale) } + + color?.let { target.entity.setPersisting(it) } target.entity.set(this) -// this.itemStack = furnitureItem } ?: return } } diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt index bcc16b0a..1395b399 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt @@ -1,32 +1,25 @@ package com.mineinabyss.blocky.systems.actions import com.mineinabyss.blocky.components.core.BlockyFurniture +import com.mineinabyss.blocky.helpers.asRGBColorable import com.mineinabyss.geary.papermc.tracking.items.components.SetItem import com.mineinabyss.geary.systems.GearyListener import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.items.editItemMeta import net.kyori.adventure.text.Component import org.bukkit.entity.ItemDisplay -import org.bukkit.inventory.meta.LeatherArmorMeta -import org.bukkit.inventory.meta.MapMeta -import org.bukkit.inventory.meta.PotionMeta class SetItemOnFurnitureSystem : GearyListener() { private val Pointers.display by get().on(target) - private val Pointers.color by get().orNull().on(target) private val Pointers.furniture by get().on(target) + private val Pointers.furnitureColor by get().orNull().on(target) private val Pointers.setItem by get().on(source) override fun Pointers.handle() { - val color = color?.color val itemStack = furniture.properties.itemStack?.toItemStackOrNull() ?: setItem.item.toItemStack() val furnitureItem = itemStack.clone().editItemMeta { displayName(Component.empty()) - if (color != null) { - (this as? LeatherArmorMeta)?.setColor(color) - ?: (this as? PotionMeta)?.setColor(color) - ?: (this as? MapMeta)?.setColor(color) ?: return@editItemMeta - } + furnitureColor?.color?.let { asRGBColorable()?.color = it } } display.itemStack = furnitureItem } From 9c95fd73c01783bf2d1aaf8d0551a2f3e9125a31 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Wed, 7 Feb 2024 00:12:59 -0500 Subject: [PATCH 4/6] Bump: Ido, geary --- gradle.properties | 3 +- gradle/blockyLibs.versions.toml | 2 +- settings.gradle.kts | 5 --- .../blocky/BlockyCommandExecutor.kt | 8 ++-- .../blocky/helpers/FurnitureHelpers.kt | 3 +- .../blocky/helpers/ItemMetaHelpers.kt | 44 ------------------- .../actions/SetItemOnFurnitureSystem.kt | 4 +- 7 files changed, 9 insertions(+), 60 deletions(-) delete mode 100644 src/main/kotlin/com/mineinabyss/blocky/helpers/ItemMetaHelpers.kt diff --git a/gradle.properties b/gradle.properties index 884a66e2..aba61621 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,3 @@ group=com.mineinabyss version=0.9 -idofrontVersion=0.21.5 -composeVersion=1.2.1 +idofrontVersion=0.21.11 diff --git a/gradle/blockyLibs.versions.toml b/gradle/blockyLibs.versions.toml index aa5758ea..c3436377 100644 --- a/gradle/blockyLibs.versions.toml +++ b/gradle/blockyLibs.versions.toml @@ -1,5 +1,5 @@ [versions] -gearyPaper = "0.29.10" +gearyPaper = "0.29.11" guiy="0.9.3" protocolburrito="0.9.0" diff --git a/settings.gradle.kts b/settings.gradle.kts index b1bd4e52..db2a93bb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,11 +9,6 @@ pluginManagement { maven("https://repo.papermc.io/repository/maven-public/") //Paper mavenLocal() } - - val composeVersion: String by settings - plugins { - id("org.jetbrains.compose") version composeVersion - } } dependencyResolutionManagement { diff --git a/src/main/kotlin/com/mineinabyss/blocky/BlockyCommandExecutor.kt b/src/main/kotlin/com/mineinabyss/blocky/BlockyCommandExecutor.kt index 8c7c106d..9aeb4e82 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/BlockyCommandExecutor.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/BlockyCommandExecutor.kt @@ -3,7 +3,6 @@ package com.mineinabyss.blocky import com.github.shynixn.mccoroutine.bukkit.launch import com.mineinabyss.blocky.components.core.BlockyFurniture import com.mineinabyss.blocky.components.features.blocks.BlockyDirectional -import com.mineinabyss.blocky.helpers.asRGBColorable import com.mineinabyss.blocky.helpers.gearyInventory import com.mineinabyss.blocky.menus.BlockyMainMenu import com.mineinabyss.blocky.systems.BlockyBlockQuery.prefabKey @@ -18,6 +17,7 @@ import com.mineinabyss.idofront.commands.arguments.optionArg import com.mineinabyss.idofront.commands.arguments.stringArg import com.mineinabyss.idofront.commands.execution.IdofrontCommandExecutor import com.mineinabyss.idofront.commands.extensions.actions.playerAction +import com.mineinabyss.idofront.items.asColorable import com.mineinabyss.idofront.items.editItemMeta import com.mineinabyss.idofront.messaging.error import com.mineinabyss.idofront.messaging.success @@ -76,10 +76,8 @@ class BlockyCommandExecutor : IdofrontCommandExecutor(), TabCompleter { } item.editItemMeta { - (asRGBColorable() ?: run { - player.error("This item cannot be dyed.") - return@playerAction - }).color = color.toColor + (asColorable() ?: return@playerAction player.error("This item cannot be dyed.")) + .color = color.toColor } player.success("Dyed item to <$color>$color") } diff --git a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt index a482c3ef..8ec03ae4 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt @@ -8,6 +8,7 @@ import com.mineinabyss.geary.papermc.tracking.entities.helpers.spawnFromPrefab import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull import com.mineinabyss.geary.prefabs.PrefabKey +import com.mineinabyss.idofront.items.asColorable import com.mineinabyss.idofront.spawning.spawn import io.papermc.paper.math.Position import kotlinx.coroutines.async @@ -89,7 +90,7 @@ object FurnitureHelpers { // Try to get held item's color, used to dye furniture - val color = item?.itemMeta?.asRGBColorable()?.color + val color = item?.itemMeta?.asColorable()?.color return spawnLoc.spawnFromPrefab(prefabKey, initEvent = { if (color != null) set(BlockyFurniture.Color(color)) diff --git a/src/main/kotlin/com/mineinabyss/blocky/helpers/ItemMetaHelpers.kt b/src/main/kotlin/com/mineinabyss/blocky/helpers/ItemMetaHelpers.kt deleted file mode 100644 index 90efde00..00000000 --- a/src/main/kotlin/com/mineinabyss/blocky/helpers/ItemMetaHelpers.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.mineinabyss.blocky.helpers - -import org.bukkit.Color -import org.bukkit.inventory.meta.ItemMeta -import org.bukkit.inventory.meta.LeatherArmorMeta -import org.bukkit.inventory.meta.MapMeta -import org.bukkit.inventory.meta.PotionMeta - -interface RGBColorable { - var color: Color? -} - -/** - * These different ItemMeta classes don't share a common color property so we use this :( - */ -fun ItemMeta.asRGBColorable(): RGBColorable? { - return when (val meta = this) { - is LeatherArmorMeta -> object : RGBColorable { - override var color: Color? - get() = meta.color - set(value) { - meta.setColor(value) - } - } - - is PotionMeta -> object : RGBColorable { - override var color: Color? - get() = meta.color - set(value) { - meta.color = value - } - } - - is MapMeta -> object : RGBColorable { - override var color: Color? - get() = meta.color - set(value) { - meta.color = value - } - } - - else -> null - } -} diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt index 1395b399..7bf52fff 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetItemOnFurnitureSystem.kt @@ -1,10 +1,10 @@ package com.mineinabyss.blocky.systems.actions import com.mineinabyss.blocky.components.core.BlockyFurniture -import com.mineinabyss.blocky.helpers.asRGBColorable import com.mineinabyss.geary.papermc.tracking.items.components.SetItem import com.mineinabyss.geary.systems.GearyListener import com.mineinabyss.geary.systems.accessors.Pointers +import com.mineinabyss.idofront.items.asColorable import com.mineinabyss.idofront.items.editItemMeta import net.kyori.adventure.text.Component import org.bukkit.entity.ItemDisplay @@ -19,7 +19,7 @@ class SetItemOnFurnitureSystem : GearyListener() { val itemStack = furniture.properties.itemStack?.toItemStackOrNull() ?: setItem.item.toItemStack() val furnitureItem = itemStack.clone().editItemMeta { displayName(Component.empty()) - furnitureColor?.color?.let { asRGBColorable()?.color = it } + furnitureColor?.color?.let { asColorable()?.color = it } } display.itemStack = furnitureItem } From 035c5a70b906406ee2462755ad64fa64b672b178 Mon Sep 17 00:00:00 2001 From: Boy Date: Wed, 7 Feb 2024 15:47:13 +0100 Subject: [PATCH 5/6] refactor: minor tweak and set furniture customName to prevent geary removal --- gradle.properties | 2 +- .../kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt | 2 +- .../mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt | 2 ++ .../blocky/systems/actions/SetSeatOnFurnitureSystem.kt | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index aba61621..89710743 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=com.mineinabyss version=0.9 -idofrontVersion=0.21.11 +idofrontVersion=0.21.12 diff --git a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt index 8ec03ae4..229908e4 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/helpers/FurnitureHelpers.kt @@ -98,7 +98,7 @@ object FurnitureHelpers { } //TODO Fix seat breaking below 0.0 offset and remove max() check here - fun spawnFurnitureSeat(furniture: ItemDisplay, yaw: Float, height: Double = 0.0, location: Location) = + fun spawnFurnitureSeat(furniture: ItemDisplay, location: Location, yaw: Float, height: Double = 0.0) = location.toBlockCenterLocation().apply { y += max(0.0, height) }.spawn { isVisible = false isMarker = true diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt index 8d4e8c16..d6bcabf9 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt @@ -8,6 +8,7 @@ import com.mineinabyss.geary.systems.GearyListener import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.spawning.spawn import com.mineinabyss.idofront.typealiases.BukkitEntity +import net.kyori.adventure.text.Component import org.bukkit.entity.ItemDisplay class AttemptSpawnFurnitureSystem : GearyListener() { @@ -41,6 +42,7 @@ class AttemptSpawnFurnitureSystem : GearyListener() { color?.let { target.entity.setPersisting(it) } target.entity.set(this) + customName(Component.empty()) } ?: return } } diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetSeatOnFurnitureSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetSeatOnFurnitureSystem.kt index 7de54a23..1bedd590 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetSeatOnFurnitureSystem.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/systems/actions/SetSeatOnFurnitureSystem.kt @@ -20,8 +20,8 @@ class SetSeatOnFurnitureSystem : GearyListener() { Bukkit.getScheduler().scheduleSyncDelayedTask(blocky.plugin, { if (furniture.collisionHitbox.isNotEmpty()) { FurnitureHelpers.collisionHitboxLocations(yaw, display.location, furniture.collisionHitbox) - .forEach { loc -> FurnitureHelpers.spawnFurnitureSeat(display, yaw - 180, seat.heightOffset, loc) } - } else FurnitureHelpers.spawnFurnitureSeat(display, yaw, seat.heightOffset, display.location) + .forEach { loc -> FurnitureHelpers.spawnFurnitureSeat(display, loc, yaw - 180, seat.heightOffset) } + } else FurnitureHelpers.spawnFurnitureSeat(display, display.location, yaw, seat.heightOffset) }, 1L) } } From 672563efeeb46fa73eb194349721fd5dc7235a21 Mon Sep 17 00:00:00 2001 From: Boy Date: Thu, 8 Feb 2024 10:52:56 +0100 Subject: [PATCH 6/6] refactor: remove customName set due to geary fixed --- .../mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt b/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt index d6bcabf9..6b518473 100644 --- a/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt +++ b/src/main/kotlin/com/mineinabyss/blocky/systems/AttemptSpawnFurnitureSystem.kt @@ -42,7 +42,6 @@ class AttemptSpawnFurnitureSystem : GearyListener() { color?.let { target.entity.setPersisting(it) } target.entity.set(this) - customName(Component.empty()) } ?: return } }