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

Commit

Permalink
Update to geary 0.26
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Mar 13, 2024
1 parent 321582c commit b9cd23d
Show file tree
Hide file tree
Showing 44 changed files with 549 additions and 530 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ jobs:
- uses: MineInAbyss/publish-action@master
with:
maven-metadata-url: https://repo.mineinabyss.com/releases/com/mineinabyss/mobzy/maven-metadata.xml
pages-path: build/dokka/htmlMultiModule/
dokka: dokkaHtmlMultiModule
maven-snapshot-metadata-url: https://repo.mineinabyss.com/snapshots/com/mineinabyss/mobzy/maven-metadata.xml
# pages-path: build/dokka/htmlMultiModule/
# dokka: dokkaHtmlMultiModule
maven-username: ${{ secrets.MAVEN_PUBLISH_USERNAME }}
maven-password: ${{ secrets.MAVEN_PUBLISH_PASSWORD }}
release-files: |
Expand Down
44 changes: 22 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
alias(libs.plugins.mia.kotlin.jvm)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.mia.papermc)
alias(libs.plugins.mia.nms)
alias(libs.plugins.mia.copyjar)
alias(libs.plugins.mia.publication)
alias(libs.plugins.mia.testing)
alias(libs.plugins.mia.autoversion)
alias(idofrontLibs.plugins.mia.kotlin.jvm)
alias(idofrontLibs.plugins.kotlinx.serialization)
alias(idofrontLibs.plugins.mia.papermc)
alias(idofrontLibs.plugins.mia.nms)
alias(idofrontLibs.plugins.mia.copyjar)
alias(idofrontLibs.plugins.mia.publication)
alias(idofrontLibs.plugins.mia.testing)
alias(idofrontLibs.plugins.mia.autoversion)
}

allprojects {
Expand All @@ -36,24 +36,24 @@ allprojects {
}

dependencies {
val idofrontLibs = rootProject.idofrontLibs
val libs = rootProject.libs
val myLibs = rootProject.myLibs

compileOnly(myLibs.geary.papermc)
compileOnly(libs.geary.papermc)

implementation(libs.bundles.idofront.core)
implementation(libs.idofront.nms)
implementation(idofrontLibs.bundles.idofront.core)
implementation(idofrontLibs.idofront.nms)
}
}

dependencies {
// MineInAbyss platform
compileOnly(libs.kotlin.stdlib)
compileOnly(libs.kotlinx.serialization.json)
compileOnly(libs.kotlinx.serialization.kaml)
compileOnly(libs.kotlinx.coroutines)
compileOnly(libs.minecraft.mccoroutine)
compileOnly(libs.idofront.di)
compileOnly(idofrontLibs.kotlin.stdlib)
compileOnly(idofrontLibs.kotlinx.serialization.json)
compileOnly(idofrontLibs.kotlinx.serialization.kaml)
compileOnly(idofrontLibs.kotlinx.coroutines)
compileOnly(idofrontLibs.minecraft.mccoroutine)
compileOnly(idofrontLibs.idofront.di)

// Shaded
api(project(":mobzy-pathfinding"))
Expand All @@ -63,8 +63,8 @@ dependencies {
api(project(":mobzy-modelengine"))

// Testing
testImplementation(libs.kotlin.statistics)
testImplementation(libs.minecraft.mockbukkit)
testImplementation(libs.kotlinx.serialization.json)
testImplementation(libs.kotlinx.serialization.kaml)
testImplementation(idofrontLibs.kotlin.statistics)
testImplementation(idofrontLibs.minecraft.mockbukkit)
testImplementation(idofrontLibs.kotlinx.serialization.json)
testImplementation(idofrontLibs.kotlinx.serialization.kaml)
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=0.24
idofrontVersion=0.21.12
idofrontVersion=0.22.3
2 changes: 1 addition & 1 deletion gradle/myLibs.versions.toml → gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
gearyPaper = "0.29-SNAPSHOT"
gearyPaper = "0.29.12-dev.1"

[libraries]
geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" }
2 changes: 1 addition & 1 deletion mobzy-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

dependencies {
compileOnly(libs.kotlinx.serialization.json)
compileOnly(idofrontLibs.kotlinx.serialization.json)

// As a rule, core must not depend on any other modules
}
10 changes: 5 additions & 5 deletions mobzy-features/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ plugins {
}

dependencies {
compileOnly(libs.kotlinx.serialization.json)
compileOnly(libs.kotlinx.serialization.kaml)
compileOnly(libs.kotlinx.coroutines)
compileOnly(libs.minecraft.mccoroutine)
compileOnly(idofrontLibs.kotlinx.serialization.json)
compileOnly(idofrontLibs.kotlinx.serialization.kaml)
compileOnly(idofrontLibs.kotlinx.coroutines)
compileOnly(idofrontLibs.minecraft.mccoroutine)

compileOnly(libs.minecraft.plugin.protocollib)
compileOnly(idofrontLibs.minecraft.plugin.protocollib)

compileOnly(project(":mobzy-core"))
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.mineinabyss.mobzy.features.bossbar

import com.mineinabyss.geary.autoscan.AutoScan
import com.mineinabyss.geary.modules.GearyModule
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
import com.mineinabyss.geary.systems.RepeatingSystem
import com.mineinabyss.geary.systems.accessors.Pointer
import com.mineinabyss.geary.systems.builders.system
import com.mineinabyss.geary.systems.query.Query
import com.mineinabyss.idofront.entities.toPlayer
import com.mineinabyss.idofront.typealiases.BukkitEntity
import com.mineinabyss.mobzy.features.bossbar.BossBarDisplayListener.Companion.updateHealth
import org.bukkit.attribute.Attribute
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
Expand All @@ -15,32 +17,32 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.event.entity.EntityDeathEvent
import kotlin.time.Duration.Companion.seconds

/**
* Handles displaying of boss bars to players in range.
* Uses values from the DisplayBossBar component.
*/
@AutoScan
class BossBarDisplaySystem : RepeatingSystem(interval = 0.5.seconds), Listener {
private val Pointer.bossbar by get<DisplayBossBar>()
private val Pointer.bukkitentity by get<BukkitEntity>()
fun GearyModule.createBossBarDisplaySystem() = system(object : Query() {
val bossbar by get<DisplayBossBar>()
val bukkitentity by get<BukkitEntity>()
}).every(0.5.seconds).exec {
val bukkit = bukkitentity as? LivingEntity ?: return@exec
val playersInRange = bukkitentity.getNearbyEntities(bossbar.range, bossbar.range, bossbar.range)
.filterIsInstance<Player>().mapTo(mutableSetOf()) { it.uniqueId }

override fun Pointer.tick() {
val bukkit = bukkitentity as? LivingEntity ?: return
val playersInRange = bukkitentity.getNearbyEntities(bossbar.range, bossbar.range, bossbar.range)
.filterIsInstance<Player>().mapTo(mutableSetOf()) { it.uniqueId }
// Gets players to add and remove
val addPlayers = playersInRange - bossbar.playersInRange
val removePlayers = bossbar.playersInRange - playersInRange

// Gets players to add and remove
val addPlayers = playersInRange - bossbar.playersInRange
val removePlayers = bossbar.playersInRange - playersInRange
// Removes and adds the necessary players
bossbar.playersInRange.removeAll(removePlayers)
bossbar.playersInRange.addAll(addPlayers)

// Removes and adds the necessary players
bossbar.playersInRange.removeAll(removePlayers)
bossbar.playersInRange.addAll(addPlayers)
addPlayers.forEach { it.toPlayer()?.showBossBar(bossbar.bossBar) }
removePlayers.forEach { it.toPlayer()?.hideBossBar(bossbar.bossBar) }
bossbar.updateHealth(bukkit)
}

addPlayers.forEach { it.toPlayer()?.showBossBar(bossbar.bossBar) }
removePlayers.forEach { it.toPlayer()?.hideBossBar(bossbar.bossBar) }
bossbar.updateHealth(bukkit)
}
/**
* Handles displaying of boss bars to players in range.
* Uses values from the DisplayBossBar component.
*/
class BossBarDisplayListener : Listener {

fun EntityDeathEvent.onDeath() {
val bossBar = entity.toGearyOrNull()?.get<DisplayBossBar>() ?: return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.mineinabyss.mobzy.features.copynbt

import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.autoscan.AutoScan
import com.mineinabyss.geary.modules.GearyModule
import com.mineinabyss.geary.papermc.datastore.loadComponentsFrom
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.Pointers
import com.mineinabyss.geary.systems.builders.listener
import com.mineinabyss.geary.systems.query.ListenerQuery
import com.mineinabyss.idofront.nms.aliases.toNMS
import com.mineinabyss.idofront.typealiases.BukkitEntity

Expand All @@ -14,14 +14,12 @@ import com.mineinabyss.idofront.typealiases.BukkitEntity
* This is useful for getting a duplicate version of an old entity.
*/
@AutoScan
class CopyNBTSystem : GearyListener() {
private val Pointers.nbt by get<CopyNBT>().whenSetOnTarget()
private val Pointers.bukkitEntity by get<BukkitEntity>().whenSetOnTarget()

@OptIn(UnsafeAccessors::class)
override fun Pointers.handle() {
bukkitEntity.toNMS().load(nbt.compound)
target.entity.loadComponentsFrom(bukkitEntity.persistentDataContainer)
target.entity.remove<CopyNBT>()
}
fun GearyModule.createCopyNBTSystem() = listener(object : ListenerQuery() {
val bukkitEntity by get<BukkitEntity>()
val nbt by get<CopyNBT>()
override fun ensure() = event.anySet(::bukkitEntity, ::nbt)
}).exec {
bukkitEntity.toNMS().load(nbt.compound)
entity.loadComponentsFrom(bukkitEntity.persistentDataContainer)
entity.remove<CopyNBT>()
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.mineinabyss.mobzy.features.drops

import com.mineinabyss.geary.autoscan.AutoScan
import com.mineinabyss.geary.modules.GearyModule
import com.mineinabyss.geary.papermc.bridge.events.entities.Drops
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.Pointers
import com.mineinabyss.geary.systems.builders.listener
import com.mineinabyss.geary.systems.query.ListenerQuery
import com.mineinabyss.idofront.spawning.spawn
import com.mineinabyss.idofront.typealiases.BukkitEntity
import com.mineinabyss.idofront.util.randomOrMin
Expand All @@ -12,35 +14,34 @@ import org.bukkit.entity.Item
import org.bukkit.entity.LivingEntity
import org.bukkit.event.entity.EntityDamageEvent.DamageCause

class DropsSystem : GearyListener() {
private val Pointers.drops by get<Drops>().orNull().on(event)
private val Pointers.bukkit by get<BukkitEntity>().on(target)
private val Pointers.deathLoot by get<DoDrop>().on(source)
@AutoScan
fun GearyModule.mobDropsSystem() = listener(object : ListenerQuery() {
val bukkit by get<BukkitEntity>()
val deathLoot by source.get<DoDrop>()
val drops by event.get<Drops>().orNull()
}).exec {
val bukkit = bukkit
val drops = drops

override fun Pointers.handle() {
val bukkit = bukkit
val drops = drops

// Drop equipped items from rideable entity
// Drop equipped items from rideable entity
// if(entity is Saddleable) drops.add(ItemStack(Material.SADDLE))
val ignoredCauses = mutableListOf<DamageCause>()
deathLoot.drops.forEach { mobDrop ->
ignoredCauses.addAll(mobDrop.ignoredCauses)
val ignoredCauses = mutableListOf<DamageCause>()
deathLoot.drops.forEach { mobDrop ->
ignoredCauses.addAll(mobDrop.ignoredCauses)
}
val exp = deathLoot.drops.mapNotNull { it.exp?.randomOrMin() }.sum()
if (bukkit.lastDamageCause?.cause !in ignoredCauses) {
drops?.items?.clear()
drops?.exp = 0
val looting = (bukkit as? LivingEntity)
?.killer?.inventory?.itemInMainHand
?.enchantments?.get(Enchantment.LOOT_BONUS_MOBS) ?: 0
val newDrops = deathLoot.drops.mapNotNull { it.chooseDrop(looting, bukkit.fireTicks > 0) }
newDrops.forEach {
bukkit.location.spawn<Item> { itemStack = it }
}
val exp = deathLoot.drops.mapNotNull { it.exp?.randomOrMin() }.sum()
if (bukkit.lastDamageCause?.cause !in ignoredCauses) {
drops?.items?.clear()
drops?.exp = 0
val looting = (bukkit as? LivingEntity)
?.killer?.inventory?.itemInMainHand
?.enchantments?.get(Enchantment.LOOT_BONUS_MOBS) ?: 0
val newDrops = deathLoot.drops.mapNotNull { it.chooseDrop(looting, bukkit.fireTicks > 0) }
newDrops.forEach {
bukkit.location.spawn<Item> { itemStack = it }
}
bukkit.location.spawn<ExperienceOrb>() {
experience = exp
}
bukkit.location.spawn<ExperienceOrb>() {
experience = exp
}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package com.mineinabyss.mobzy.features.initializers

import com.mineinabyss.geary.autoscan.AutoScan
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.Pointers
import com.mineinabyss.geary.datatypes.ComponentDefinition
import com.mineinabyss.geary.modules.GearyModule
import com.mineinabyss.geary.papermc.bridge.events.EventHelpers
import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn
import com.mineinabyss.geary.systems.builders.listener
import com.mineinabyss.geary.systems.query.ListenerQuery
import com.mineinabyss.idofront.typealiases.BukkitEntity
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.bukkit.entity.AbstractSkeleton
import org.bukkit.entity.Phantom
import org.bukkit.entity.Zombie

@JvmInline
@Serializable
@SerialName("mobzy:set.always_show_name")
value class SetAlwaysShowName(val value: Boolean = true)
value class SetAlwaysShowName(val value: Boolean = true) {
companion object : ComponentDefinition by EventHelpers.defaultTo<OnSpawn>()
}

@AutoScan
class SetAlwaysShowNameSystem : GearyListener() {
private val Pointers.visibility by get<SetAlwaysShowName>().whenSetOnTarget()
private val Pointers.bukkit by get<BukkitEntity>().whenSetOnTarget()

override fun Pointers.handle() {
bukkit.isCustomNameVisible = visibility.value
}
fun GearyModule.customNameVisibleSetter() = listener(object : ListenerQuery() {
val bukkit by get<BukkitEntity>()
val visibility by source.get<SetAlwaysShowName>()
}).exec {
bukkit.isCustomNameVisible = visibility.value
}
Loading

0 comments on commit b9cd23d

Please sign in to comment.