Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Update relations syntax (#104)
Browse files Browse the repository at this point in the history
* Work on relations cleanup

* Update to new Geary syntax

* Fix mobzy spawn throwing errors

* Bump geary version

* Bump version
  • Loading branch information
0ffz authored Jun 24, 2022
1 parent f3992f5 commit 53c34f5
Show file tree
Hide file tree
Showing 19 changed files with 23 additions and 38 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=com.mineinabyss
version=0.16
version=0.17
useNMS=true
idofrontVersion=0.11.95
kotlinVersion=1.6.10
Expand Down
2 changes: 1 addition & 1 deletion gradle/mobzylibs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
geary = "0.16.100"
geary = "0.17.102"

[libraries]
protocolburrito = "com.mineinabyss:protocolburrito:0.4.33"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package com.mineinabyss.mobzy.injection

import com.mineinabyss.geary.annotations.AutoScan
import com.mineinabyss.geary.annotations.Handler
import com.mineinabyss.geary.components.Processed
import com.mineinabyss.geary.datatypes.family.MutableFamilyOperations.Companion.has
import com.mineinabyss.geary.components.relations.Processed
import com.mineinabyss.geary.datatypes.family.family
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.prefabs.configuration.components.Prefab
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.TargetScope
import com.mineinabyss.geary.systems.accessors.get
import com.mineinabyss.geary.systems.query.GearyQuery
import com.mineinabyss.mobzy.ecs.components.initialization.MobzyType
import com.mineinabyss.mobzy.ecs.components.toMobzyCategory
Expand All @@ -23,14 +21,14 @@ object MobzyTypesQuery : GearyQuery() {
has<Prefab>()
}

fun getKeys() = map { it.key }
fun getKeys() = MobzyTypesQuery.run { map { it.key } }
}

fun PrefabKey.toResourceKey(): ResourceLocation = ResourceLocation(namespace, key)

@AutoScan
class MobzyNMSTypeInjector : GearyListener() {
private val TargetScope.info by added<MobzyType>()
private val TargetScope.info by onSet<MobzyType>()
private val TargetScope.prefab by family { has<Prefab>() }

@Handler
Expand All @@ -40,6 +38,6 @@ class MobzyNMSTypeInjector : GearyListener() {
}
entity.set(nmsEntityType)
entity.set(info.mobCategory ?: info.creatureType.toMobzyCategory())
entity.setRelation(MobzyType::class, Processed)
entity.addRelation<Processed, MobzyType>()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import org.bukkit.entity.Mob

@AutoScan
class PathfinderAttachSystem : GearyListener() {
val TargetScope.bukkit by added<BukkitEntity>()
val TargetScope.pathfinders by added<Pathfinders>()
val TargetScope.bukkit by onSet<BukkitEntity>()
val TargetScope.pathfinders by onSet<Pathfinders>()

@Handler
fun TargetScope.attachPathfinders() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ object MobCountManager : Listener, GearyMCContext by GearyMCContextKoin() {

@AutoScan
class CountMobsSystem : GearyListener() {
val TargetScope.bukkitEntity by added<MobCategory>()
val TargetScope.category by added<MobCategory>()
val TargetScope.bukkitEntity by onSet<MobCategory>()
val TargetScope.category by onSet<MobCategory>()

@Handler
fun TargetScope.count() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.mineinabyss.geary.prefabs.PrefabManager
import com.mineinabyss.geary.prefabs.PrefabManagerContext
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.TargetScope
import com.mineinabyss.geary.systems.accessors.get
import com.mineinabyss.geary.systems.query.GearyQuery
import com.mineinabyss.mobzy.spawning.SpawnRegistry.regionSpawns
import com.sk89q.worldguard.WorldGuard
Expand All @@ -23,8 +22,8 @@ import org.koin.core.component.inject
object SpawnRegistry : GearyListener(), PrefabManagerContext {
override val prefabManager: PrefabManager by inject()

private val TargetScope.parentRegions by added<WGRegions>()
private val TargetScope.spawn by added<SpawnType>()
private val TargetScope.parentRegions by onSet<WGRegions>()
private val TargetScope.spawn by onSet<SpawnType>()

private val regionContainer = WorldGuard.getInstance().platform.regionContainer
private val regionSpawns: MutableMap<String, MutableSet<GearyEntity>> = HashMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.mineinabyss.geary.annotations.Handler
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.EventScope
import com.mineinabyss.geary.systems.accessors.TargetScope
import com.mineinabyss.geary.systems.accessors.get
import com.mineinabyss.idofront.serialization.DoubleRangeSerializer
import com.mineinabyss.idofront.util.DoubleRange
import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.EventScope
import com.mineinabyss.geary.systems.accessors.TargetScope
import com.mineinabyss.geary.systems.accessors.get
import com.mineinabyss.mobzy.spawning.SpawnType
import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo
import kotlinx.serialization.SerialName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ package com.mineinabyss.mobzy.spawning.conditions.components
import com.mineinabyss.geary.annotations.AutoScan
import com.mineinabyss.geary.annotations.Handler
import com.mineinabyss.geary.datatypes.family.family
import com.mineinabyss.geary.datatypes.family.MutableFamilyOperations.Companion.has
import com.mineinabyss.geary.datatypes.family.MutableFamilyOperations.Companion.not
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.EventScope
import com.mineinabyss.geary.systems.accessors.TargetScope
import com.mineinabyss.geary.systems.accessors.get
import com.mineinabyss.mobzy.ecs.components.MobCategory
import com.mineinabyss.mobzy.spawning.MobCountManager
import com.mineinabyss.mobzy.spawning.SpawnType
Expand All @@ -18,7 +15,7 @@ import kotlinx.serialization.Serializable

@Serializable
@SerialName("mobzy:ignore.spawn.category_cap")
class IgnoreSpawnCategoryCap()
class IgnoreSpawnCategoryCap

@AutoScan
class SpawnCategoryCapCondition : GearyListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.mineinabyss.geary.annotations.AutoScan
import com.mineinabyss.geary.annotations.Handler
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.TargetScope
import com.mineinabyss.geary.systems.accessors.get
import com.mineinabyss.idofront.serialization.DurationSerializer
import com.mineinabyss.mobzy.mobzyConfig
import com.mineinabyss.mobzy.spawning.GlobalSpawnInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.mineinabyss.geary.annotations.Handler
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.EventScope
import com.mineinabyss.geary.systems.accessors.TargetScope
import com.mineinabyss.geary.systems.accessors.get
import com.mineinabyss.idofront.serialization.IntRangeSerializer
import com.mineinabyss.mobzy.spawning.vertical.SpawnInfo
import kotlinx.serialization.SerialName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.mineinabyss.mobzy.spawning.vertical

import com.mineinabyss.geary.systems.accessors.TargetScope
import com.mineinabyss.geary.systems.accessors.get
import com.mineinabyss.geary.systems.query.GearyQuery
import com.mineinabyss.geary.systems.query.invoke
import com.mineinabyss.idofront.location.down
import com.mineinabyss.idofront.location.up
import com.mineinabyss.idofront.typealiases.BukkitEntity
Expand Down Expand Up @@ -42,7 +40,7 @@ class SpawnInfo(

//TODO more efficiently finding all ECS entities nearby
val localMobs: List<BukkitEntity> by lazy {
NearbyQuery {
NearbyQuery.run {
map { it.bukkit }.filter {
it.location.world == bottom.world && it.location.distanceSquared(bottom) < searchRadiusSquared
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import org.bukkit.entity.Snowball

@AutoScan
class ApplyItemModelListener : GearyListener() {
val TargetScope.model by added<ItemModel>()
val TargetScope.bukkit by added<Snowball>()
val TargetScope.model by onSet<ItemModel>()
val TargetScope.bukkit by onSet<Snowball>()

@Handler
fun TargetScope.applyModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import org.bukkit.entity.LivingEntity
//TODO Make sure this is the first thing to run when priority support comes
@AutoScan
class AddPrefabFromNMSTypeSystem : GearyListener() {
private val TargetScope.bukkitEntity by added<BukkitEntity>()
private val TargetScope.attributes by added<MobAttributes>()
private val TargetScope.bukkitEntity by onSet<BukkitEntity>()
private val TargetScope.attributes by onSet<MobAttributes>()

@Handler
fun TargetScope.addPrefab() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ object GearySpawningListener : Listener {

spawned.toGeary().apply {
addPrefab(prefab)
set(spawned.toBukkit())
GearyMinecraftSpawnEvent(this).call()
}
if (spawned is Mob) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import com.mineinabyss.mobzy.ecs.components.CopyNBT
*/
@AutoScan
class CopyNBTSystem : GearyListener() {
private val TargetScope.nbt by added<CopyNBT>()
private val TargetScope.bukkitEntity by added<BukkitEntity>()
private val TargetScope.nbt by onSet<CopyNBT>()
private val TargetScope.bukkitEntity by onSet<BukkitEntity>()

@Handler
fun TargetScope.copyNBT() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ object ModelEngineSystem : GearySystem, Listener, AnimationController, GearyCont
?.forEach { it.removeState(state, ignoreLerp) }

class ModelEngineTracker : GearyListener() {
val TargetScope.bukkit by added<BukkitEntity>()
val TargetScope.model by added<ModelEngineComponent>()
val TargetScope.bukkit by onSet<BukkitEntity>()
val TargetScope.model by onSet<ModelEngineComponent>()

@Handler
fun TargetScope.registerModelEngine() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.mineinabyss.mobzy.systems.systems
import com.mineinabyss.geary.annotations.AutoScan
import com.mineinabyss.geary.systems.TickingSystem
import com.mineinabyss.geary.systems.accessors.TargetScope
import com.mineinabyss.geary.systems.accessors.get
import com.mineinabyss.idofront.nms.aliases.toNMS
import com.mineinabyss.idofront.typealiases.BukkitEntity
import com.mineinabyss.mobzy.ecs.components.initialization.Model
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/com/mineinabyss/mobzy/MobzyCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.mineinabyss.geary.papermc.GearyMCContextKoin
import com.mineinabyss.geary.papermc.access.toGeary
import com.mineinabyss.geary.papermc.helpers.spawnFromPrefab
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.systems.query.invoke
import com.mineinabyss.idofront.commands.arguments.booleanArg
import com.mineinabyss.idofront.commands.arguments.intArg
import com.mineinabyss.idofront.commands.arguments.optionArg
Expand Down Expand Up @@ -195,7 +194,7 @@ class MobzyCommands : IdofrontCommandExecutor(), TabCompleter, GearyContext by G

if (subCommand == "spawn" || subCommand == "s")
if (args.size == 2) {
return MobzyTypesQuery {
return MobzyTypesQuery.run {
filter {
val arg = args[1].lowercase()
it.key.key.startsWith(arg) || it.key.full.startsWith(arg)
Expand Down

0 comments on commit 53c34f5

Please sign in to comment.