Skip to content

Commit

Permalink
feat: track & update furniture itemstacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 22, 2024
1 parent 853d285 commit 6bf7314
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
11 changes: 4 additions & 7 deletions src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import com.mineinabyss.blocky.compatibility.worldedit.WorldEditSupport
import com.mineinabyss.blocky.helpers.FurniturePacketHelpers
import com.mineinabyss.blocky.listeners.*
import com.mineinabyss.blocky.systems.FurnitureOutlineSystem
import com.mineinabyss.blocky.systems.FurnitureTrackerSystem
import com.mineinabyss.geary.addons.GearyPhase
import com.mineinabyss.geary.autoscan.autoscan
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.idofront.config.config
import com.mineinabyss.idofront.di.DI
import com.mineinabyss.idofront.messaging.broadcast
import com.mineinabyss.idofront.messaging.logError
import com.mineinabyss.idofront.plugin.Plugins
import com.mineinabyss.idofront.plugin.listeners
Expand All @@ -34,8 +34,6 @@ import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket
import net.minecraft.resources.ResourceLocation
import net.minecraft.tags.BlockTags
import net.minecraft.world.item.Item
import org.bukkit.Bukkit
import org.bukkit.block.data.BlockData
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.plugin.java.JavaPlugin
Expand All @@ -60,6 +58,9 @@ class BlockyPlugin : JavaPlugin() {

BlockyCommandExecutor()

geary.pipeline.addSystems(FurnitureTrackerSystem(), FurnitureOutlineSystem())
FurniturePacketHelpers.registerPacketListeners()

listeners(
BlockyGenericListener(),
BlockyFurnitureListener(),
Expand Down Expand Up @@ -92,10 +93,6 @@ class BlockyPlugin : JavaPlugin() {
runStartupFunctions()
}
}

FurniturePacketHelpers.registerPacketListeners()
geary.pipeline.addSystem(FurnitureOutlineSystem())

}

fun runStartupFunctions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import com.mineinabyss.blocky.helpers.*
import com.mineinabyss.geary.papermc.tracking.entities.events.GearyEntityAddToWorldEvent
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.idofront.messaging.logError
import com.mineinabyss.idofront.messaging.logSuccess
import com.mineinabyss.idofront.messaging.logVal
import com.mineinabyss.idofront.plugin.Plugins
import com.ticxo.modelengine.api.events.BaseEntityInteractEvent
import io.papermc.paper.event.packet.PlayerChunkLoadEvent
Expand All @@ -30,7 +28,6 @@ import org.bukkit.Location
import org.bukkit.block.BlockFace
import org.bukkit.entity.ArmorStand
import org.bukkit.entity.ItemDisplay
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
import org.bukkit.event.Event
import org.bukkit.event.EventHandler
Expand All @@ -56,8 +53,6 @@ class BlockyFurnitureListener : Listener {
@EventHandler(priority = EventPriority.HIGH)
fun GearyEntityAddToWorldEvent.onAddFurniture() {
val furniture = entity as? ItemDisplay ?: return
if (entity !is LivingEntity) logError("Entity $entity is not a living entity")
else (entity as LivingEntity).equipment.logVal("equipment: ")
val simulationDistance = (Bukkit.getServer().simulationDistance * 16.0).pow(2)
blocky.plugin.server.onlinePlayers.filterNotNull().filter {
it.world == entity.world && it.location.distanceSquared(entity.location) < simulationDistance
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mineinabyss.blocky.systems

import com.mineinabyss.blocky.api.BlockyFurnitures.prefabKey
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<ItemDisplay>()

override fun Pointer.tick() {
val freshItem = furniture.prefabKey?.let { gearyItems.createItem(it, furniture.itemStack) } ?: return
furniture.itemStack = freshItem.toSerializable().toItemStack(furniture.itemStack ?: ItemStack.empty(), EnumSet.of(BaseSerializableItemStack.Properties.COLOR))
}

}

0 comments on commit 6bf7314

Please sign in to comment.