diff --git a/build.gradle.kts b/build.gradle.kts index 099df877f..cbc7bbcb5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -32,6 +32,7 @@ allprojects { maven("https://maven.enginehub.org/repo/") //WorldGuard/Edit maven("https://mvn.lumine.io/repository/maven-public/") maven("https://jitpack.io") + mavenLocal() } dependencies { diff --git a/gradle.properties b/gradle.properties index c48283f2f..996645148 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=com.mineinabyss -version=0.23 -idofrontVersion=0.20.14 +version=0.24 +idofrontVersion=0.21.5 diff --git a/gradle/myLibs.versions.toml b/gradle/myLibs.versions.toml index 1d4ccf285..3f003fbbe 100644 --- a/gradle/myLibs.versions.toml +++ b/gradle/myLibs.versions.toml @@ -1,5 +1,5 @@ [versions] -gearyPaper = "0.28.4" +gearyPaper = "0.29.0" [libraries] geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 15bc9344b..c64ee91b7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/deathloot/DeathLoot.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/deathloot/DeathLoot.kt deleted file mode 100644 index 6f5bc88e2..000000000 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/deathloot/DeathLoot.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.mineinabyss.mobzy.features.deathloot - -import com.mineinabyss.idofront.serialization.IntRangeSerializer -import com.mineinabyss.idofront.util.randomOrMin -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable -import org.bukkit.event.entity.EntityDamageEvent.DamageCause - -/** - * A component for loot that should drop on entity death. - * - * @param minExp The minimum amount of exp to drop. - * @param maxExp The maximum amount of exp to drop. - * @param deathCommands A list of commands to run. - * @param drops A list of [MobDrop]s to spawn. - */ -@Serializable -@SerialName("mobzy:death_loot") -class DeathLoot( - val exp: @Serializable(with = IntRangeSerializer::class) IntRange? = null, - val deathCommands: List = listOf(), - val drops: List = listOf(), - val ignoredCauses: List = listOf( - DamageCause.SUFFOCATION, - DamageCause.DROWNING, - DamageCause.DRYOUT, - DamageCause.CRAMMING, - DamageCause.FALL - ), -) { - /** Helper function for randomly picking some amount of exp to drop. */ - fun expToDrop(): Int? = exp?.randomOrMin() -} diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/deathloot/DeathLootSystem.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/deathloot/DeathLootSystem.kt deleted file mode 100644 index 885f86202..000000000 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/deathloot/DeathLootSystem.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.mineinabyss.mobzy.features.deathloot - -import com.mineinabyss.geary.helpers.with -import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull -import net.minecraft.world.entity.Saddleable -import org.bukkit.Material -import org.bukkit.enchantments.Enchantment -import org.bukkit.event.EventHandler -import org.bukkit.event.EventPriority -import org.bukkit.event.Listener -import org.bukkit.event.entity.EntityDeathEvent -import org.bukkit.inventory.ItemStack - -class DeathLootSystem: Listener { - @EventHandler(priority = EventPriority.LOW) - fun EntityDeathEvent.setCustomDeathLoot() { - val gearyEntity = entity.toGearyOrNull() ?: return - - gearyEntity.with { deathLoot: DeathLoot -> - drops.clear() - droppedExp = 0 - - // Drop equipped items from rideable entity - if(entity is Saddleable) drops.add(ItemStack(Material.SADDLE)) - if (entity.lastDamageCause?.cause !in deathLoot.ignoredCauses) { - deathLoot.expToDrop()?.let { droppedExp = it } - val heldItem = entity.killer?.inventory?.itemInMainHand - val looting = heldItem?.enchantments?.get(Enchantment.LOOT_BONUS_MOBS) ?: 0 - drops.addAll(deathLoot.drops.mapNotNull { it.chooseDrop(looting, entity.fireTicks > 0) }) - } - } - } -} diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/DoDrop.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/DoDrop.kt new file mode 100644 index 000000000..c17a05814 --- /dev/null +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/DoDrop.kt @@ -0,0 +1,31 @@ +package com.mineinabyss.mobzy.features.drops + +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnDeath +import com.mineinabyss.geary.serialization.serializers.InnerSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.builtins.ListSerializer + + +/** + * A component for loot that should drop on entity death. + * + * @param minExp The minimum amount of exp to drop. + * @param maxExp The maximum amount of exp to drop. + * @param deathCommands A list of commands to run. + * @param drops A list of [Drop]s to spawn. + */ +@Serializable(with = DoDrop.Serializer::class) +class DoDrop( + val drops: List = listOf(), +) { + class Serializer : InnerSerializer, DoDrop>( + "mobzy:drop", + ListSerializer(Drop.serializer()), + { DoDrop(it) }, + { it.drops }, + ) + + companion object : ComponentDefinition by EventHelpers.defaultTo() +} diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/deathloot/MobDrop.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/Drop.kt similarity index 80% rename from mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/deathloot/MobDrop.kt rename to mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/Drop.kt index 1e5d4c5c5..2dc77e5ed 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/deathloot/MobDrop.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/Drop.kt @@ -1,8 +1,9 @@ -package com.mineinabyss.mobzy.features.deathloot +package com.mineinabyss.mobzy.features.drops import com.mineinabyss.idofront.serialization.IntRangeSerializer import com.mineinabyss.idofront.serialization.SerializableItemStack import kotlinx.serialization.Serializable +import org.bukkit.event.entity.EntityDamageEvent.DamageCause import org.bukkit.inventory.ItemStack import kotlin.math.roundToInt import kotlin.random.Random @@ -22,17 +23,26 @@ import kotlin.random.Random * */ @Serializable -data class MobDrop( - val item: SerializableItemStack, +data class Drop( + val exp: @Serializable(with = IntRangeSerializer::class) IntRange? = null, + val item: SerializableItemStack? = null, val cooked: SerializableItemStack? = null, val cookExp: Float = 0f, val cookTime: Int = 200, val amount: @Serializable(with = IntRangeSerializer::class) IntRange = 1..1, - val dropChance: Double = 1.0 + val dropChance: Double = 1.0, + val ignoredCauses: List = listOf( + DamageCause.SUFFOCATION, + DamageCause.DROWNING, + DamageCause.DRYOUT, + DamageCause.CRAMMING, + DamageCause.FALL + ), ) { /** @return The amount of items to be dropped, or null if the drop does not succeed */ // TODO I'd like to use exactly what Minecraft's existing system is, but I can't seem to find a way to reuse that. fun chooseDrop(lootingLevel: Int, fire: Boolean): ItemStack? { + if(item == null) return null val lootingPercent = lootingLevel / 100.0 val lootingMaxAmount: Int = diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/DropsSystem.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/DropsSystem.kt new file mode 100644 index 000000000..f2f8b30dd --- /dev/null +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/drops/DropsSystem.kt @@ -0,0 +1,46 @@ +package com.mineinabyss.mobzy.features.drops + +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.idofront.spawning.spawn +import com.mineinabyss.idofront.typealiases.BukkitEntity +import com.mineinabyss.idofront.util.randomOrMin +import org.bukkit.enchantments.Enchantment +import org.bukkit.entity.ExperienceOrb +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().orNull().on(event) + private val Pointers.bukkit by get().on(target) + private val Pointers.deathLoot by get().on(source) + + override fun Pointers.handle() { + val bukkit = bukkit + val drops = drops + + // Drop equipped items from rideable entity +// if(entity is Saddleable) drops.add(ItemStack(Material.SADDLE)) + val ignoredCauses = mutableListOf() + 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 { itemStack = it } + } + bukkit.location.spawn() { + experience = exp + } + } + } +} diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/sheep/SetWoolColor.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/sheep/SetWoolColor.kt index 29e04410c..22ecf7bfe 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/sheep/SetWoolColor.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/sheep/SetWoolColor.kt @@ -1,27 +1,35 @@ package com.mineinabyss.mobzy.features.initializers.sheep +import com.mineinabyss.geary.annotations.optin.UnsafeAccessors import com.mineinabyss.geary.autoscan.AutoScan +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn import com.mineinabyss.geary.systems.GearyListener import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.typealiases.BukkitEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import org.bukkit.DyeColor -import org.bukkit.entity.Sheep +import org.bukkit.material.Colorable @JvmInline @Serializable @SerialName("mobzy:set.wool_color") -value class SetWoolColor(val value: DyeColor) +value class SetWoolColor(val value: DyeColor) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} @AutoScan class SetWoolColorSystem : GearyListener() { - private val Pointers.woolColor by get().whenSetOnTarget() - private val Pointers.bukkit by get().whenSetOnTarget() + private val Pointers.bukkit by get().on(target) + private val Pointers.woolColor by get().on(source) + @OptIn(UnsafeAccessors::class) override fun Pointers.handle() { - when(val mob = bukkit) { - is Sheep -> mob.color = woolColor.value + target.entity.set(SetWoolColor(woolColor.value)) + when (val mob = bukkit) { + is Colorable -> mob.color = woolColor.value } } } diff --git a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/slime/SetSlimeSize.kt b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/slime/SetSlimeSize.kt index 2acb5d6bb..6a42d4df5 100644 --- a/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/slime/SetSlimeSize.kt +++ b/mobzy-features/src/main/kotlin/com/mineinabyss/mobzy/features/initializers/slime/SetSlimeSize.kt @@ -1,6 +1,9 @@ package com.mineinabyss.mobzy.features.initializers.slime import com.mineinabyss.geary.autoscan.AutoScan +import com.mineinabyss.geary.datatypes.ComponentDefinition +import com.mineinabyss.geary.papermc.bridge.events.EventHelpers +import com.mineinabyss.geary.papermc.bridge.events.entities.OnSpawn import com.mineinabyss.geary.systems.GearyListener import com.mineinabyss.geary.systems.accessors.Pointers import com.mineinabyss.idofront.serialization.IntRangeSerializer @@ -13,12 +16,14 @@ import org.bukkit.entity.Slime @JvmInline @Serializable @SerialName("mobzy:set.slime_size") -value class SetSlimeSize(@Serializable(with = IntRangeSerializer::class) val size: IntRange) +value class SetSlimeSize(@Serializable(with = IntRangeSerializer::class) val size: IntRange) { + companion object : ComponentDefinition by EventHelpers.defaultTo() +} @AutoScan class SetSlimeSizeSystem : GearyListener() { - private val Pointers.slimeSize by get().whenSetOnTarget() - private val Pointers.bukkit by get().whenSetOnTarget() + private val Pointers.bukkit by get().on(target) + private val Pointers.slimeSize by get().on(source) override fun Pointers.handle() { val slime = (bukkit as? Slime) ?: return diff --git a/mobzy-pathfinding/gradle.properties b/mobzy-pathfinding/gradle.properties deleted file mode 100644 index 60b871ee0..000000000 --- a/mobzy-pathfinding/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -useNMS=true diff --git a/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/bindings/goals/TemptBehavior.kt b/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/bindings/goals/TemptBehavior.kt index a83b7ddcb..6e8c181bc 100644 --- a/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/bindings/goals/TemptBehavior.kt +++ b/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/bindings/goals/TemptBehavior.kt @@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable import net.minecraft.world.entity.PathfinderMob import net.minecraft.world.entity.ai.goal.TemptGoal import net.minecraft.world.item.crafting.Ingredient -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack import org.bukkit.entity.Mob import org.bukkit.inventory.ItemStack diff --git a/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/components/Pathfinders.kt b/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/components/Pathfinders.kt index de488482a..3a0c77abb 100644 --- a/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/components/Pathfinders.kt +++ b/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/components/Pathfinders.kt @@ -1,6 +1,6 @@ package com.mineinabyss.mobzy.pathfinding.components -import com.mineinabyss.geary.prefabs.serializers.PolymorphicListAsMapSerializer +import com.mineinabyss.geary.serialization.serializers.PolymorphicListAsMapSerializer import kotlinx.serialization.Polymorphic import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/custom/goals/hostile/ThrowItemsGoal.kt b/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/custom/goals/hostile/ThrowItemsGoal.kt index 8a2e17258..9632e14ae 100644 --- a/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/custom/goals/hostile/ThrowItemsGoal.kt +++ b/mobzy-pathfinding/src/main/kotlin/com/mineinabyss/mobzy/pathfinding/custom/goals/hostile/ThrowItemsGoal.kt @@ -1,15 +1,13 @@ package com.mineinabyss.mobzy.pathfinding.custom.goals.hostile import com.mineinabyss.geary.datatypes.GearyEntity -import com.mineinabyss.geary.papermc.configlang.helpers.parseEntity +import com.mineinabyss.geary.papermc.bridge.helpers.parseEntity import com.mineinabyss.geary.papermc.tracking.entities.helpers.spawnFromPrefab import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.idofront.destructure.component1 import com.mineinabyss.idofront.destructure.component2 import com.mineinabyss.idofront.destructure.component3 import com.mineinabyss.idofront.location.up -import com.mineinabyss.idofront.operators.plus -import com.mineinabyss.idofront.operators.times import com.mineinabyss.idofront.serialization.DurationSerializer import com.mineinabyss.mobzy.pathfinding.MobzyPathfinderGoal import com.mineinabyss.mobzy.pathfinding.components.PathfinderComponent diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnRegistry.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnRegistry.kt index 1e8db7848..acf4286e5 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnRegistry.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/SpawnRegistry.kt @@ -28,7 +28,7 @@ class SpawnRegistry { fun reloadSpawns() { unregisterSpawns() spawnConfigsQuery.matchedEntities.forEach { - prefabLoader.reread(it) + prefabLoader.reload(it) } } diff --git a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/vertical/SpawnInfo.kt b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/vertical/SpawnInfo.kt index 3935c37ca..310f62da7 100644 --- a/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/vertical/SpawnInfo.kt +++ b/mobzy-spawning/src/main/kotlin/com/mineinabyss/mobzy/spawning/vertical/SpawnInfo.kt @@ -2,7 +2,6 @@ package com.mineinabyss.mobzy.spawning.vertical import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull import com.mineinabyss.geary.prefabs.PrefabKey -import com.mineinabyss.geary.prefabs.helpers.prefabs import com.mineinabyss.idofront.location.down import com.mineinabyss.idofront.location.up import com.mineinabyss.mobzy.spawning.SpawnPosition diff --git a/settings.gradle.kts b/settings.gradle.kts index f50dd44bf..c82e9c121 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,6 +5,7 @@ pluginManagement { gradlePluginPortal() maven("https://repo.mineinabyss.com/releases") google() + mavenLocal() } val idofrontVersion: String by settings @@ -21,6 +22,7 @@ dependencyResolutionManagement { repositories { maven("https://repo.mineinabyss.com/releases") + mavenLocal() } versionCatalogs { diff --git a/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt b/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt index 9ab989f5c..be411afe3 100644 --- a/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt +++ b/src/main/kotlin/com/mineinabyss/mobzy/MobzyPlugin.kt @@ -12,9 +12,9 @@ import com.mineinabyss.idofront.plugin.Plugins import com.mineinabyss.idofront.plugin.actions import com.mineinabyss.idofront.plugin.listeners import com.mineinabyss.mobzy.features.copynbt.CopyNBTSystem -import com.mineinabyss.mobzy.features.deathloot.DeathLootSystem import com.mineinabyss.mobzy.features.despawning.RemoveOnChunkUnloadSystem import com.mineinabyss.mobzy.features.displayname.ShowDisplayNameOnKillerSystem +import com.mineinabyss.mobzy.features.drops.DropsSystem import com.mineinabyss.mobzy.features.prevent.breeding.PreventBreedingSystem import com.mineinabyss.mobzy.features.prevent.interaction.PreventInteractionSystem import com.mineinabyss.mobzy.features.prevent.regen.PreventRegenerationSystem @@ -57,7 +57,6 @@ class MobzyPlugin : JavaPlugin() { listeners( PreventBreedingSystem(), - DeathLootSystem(), RemoveOnChunkUnloadSystem(), ShowDisplayNameOnKillerSystem(), TamableListener(), @@ -69,6 +68,7 @@ class MobzyPlugin : JavaPlugin() { geary.pipeline.addSystems( CopyNBTSystem(), + DropsSystem(), ) geary {