mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2025-02-07 23:51:25 +01:00
1.20.4 support
This commit is contained in:
parent
8141023570
commit
1dc72a5d4f
@ -5,7 +5,7 @@ import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.event.HandlerList
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class MinionKillEntityEvent(minion: Minion, val target: LivingEntity, val loot: List<ItemStack>) : MinionEvent(minion) {
|
||||
class MinionKillEntityEvent(minion: Minion, val target: LivingEntity) : MinionEvent(minion) {
|
||||
companion object {
|
||||
private val handlerList = HandlerList()
|
||||
|
||||
|
@ -22,6 +22,7 @@ dependencies {
|
||||
implementation project(path: ":common")
|
||||
implementation project(path: ":nms:v1_20_R1", configuration: "reobf")
|
||||
implementation project(path: ":nms:v1_20_R2", configuration: "reobf")
|
||||
implementation project(path: ":nms:v1_20_R3", configuration: "reobf")
|
||||
}
|
||||
|
||||
allprojects {
|
||||
@ -91,6 +92,10 @@ allprojects {
|
||||
maven {
|
||||
url = uri('https://repo.alessiodp.com/releases/')
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri("https://repo.artillex-studios.com/releases")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -115,7 +120,7 @@ allprojects {
|
||||
compileOnly 'com.intellectualsites.plotsquared:plotsquared-core:7.0.0-rc.4'
|
||||
compileOnly 'com.intellectualsites.plotsquared:plotsquared-bukkit:7.0.0-rc.4'
|
||||
implementation platform('com.intellectualsites.bom:bom-newest:1.35')
|
||||
implementation 'com.github.Artillex-Studios.AxAPI:AxAPI:1.2-Hotfix-2'
|
||||
implementation("com.artillexstudios.axapi:axapi:1.4.10")
|
||||
implementation("net.byteflux:libby-bukkit:1.3.0")
|
||||
compileOnly files('../libs/CMI-API9.5.0.8.jar')
|
||||
compileOnly files('../libs/IridiumSkyblock-3.2.12.jar')
|
||||
|
@ -107,7 +107,7 @@ object DamageHandler {
|
||||
|
||||
if (flag5) {
|
||||
if ((nmsEntity as LivingEntity).isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity, nmsEntity.drops)
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ object DamageHandler {
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY!!), f4)) {
|
||||
if (entityliving.isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity, entityliving.drops)
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
entityliving.knockback(
|
||||
|
@ -107,7 +107,7 @@ object DamageHandler {
|
||||
|
||||
if (flag5) {
|
||||
if ((nmsEntity as LivingEntity).isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity, nmsEntity.drops)
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ object DamageHandler {
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY!!), f4)) {
|
||||
if (entityliving.isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity, entityliving.drops)
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
entityliving.knockback(
|
||||
|
20
nms/v1_20_R3/build.gradle
Normal file
20
nms/v1_20_R3/build.gradle
Normal file
@ -0,0 +1,20 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
group = 'com.artillexstudios.axminions.nms'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
dependencies {
|
||||
paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
tasks {
|
||||
build {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
|
||||
reobfJar {
|
||||
mustRunAfter(shadowJar)
|
||||
}
|
||||
}
|
@ -0,0 +1,233 @@
|
||||
package com.artillexstudios.axminions.nms.v1_20_R3
|
||||
|
||||
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
|
||||
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.effect.MobEffectInstance
|
||||
import net.minecraft.world.effect.MobEffects
|
||||
import net.minecraft.world.entity.EquipmentSlot
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.MobType
|
||||
import net.minecraft.world.entity.decoration.ArmorStand
|
||||
import net.minecraft.world.item.AxeItem
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.item.SwordItem
|
||||
import net.minecraft.world.item.TridentItem
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper
|
||||
import net.minecraft.world.item.enchantment.SweepingEdgeEnchantment
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld
|
||||
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
|
||||
object DamageHandler {
|
||||
private var DUMMY_ENTITY: LivingEntity? = null
|
||||
|
||||
fun damage(source: Minion, entity: Entity) {
|
||||
val nmsEntity = (entity as CraftEntity).handle
|
||||
if (DUMMY_ENTITY === null) {
|
||||
DUMMY_ENTITY =
|
||||
ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, nmsEntity.level() as ServerLevel)
|
||||
}
|
||||
|
||||
synchronized(DUMMY_ENTITY!!) {
|
||||
var f = 1
|
||||
|
||||
val nmsItem: ItemStack
|
||||
if (source.getTool() == null) {
|
||||
nmsItem = ItemStack.EMPTY
|
||||
} else {
|
||||
nmsItem = CraftItemStack.asNMSCopy(source.getTool())
|
||||
|
||||
if (nmsItem.item is SwordItem) {
|
||||
f = (f + (nmsItem.item as SwordItem).damage).toInt()
|
||||
}
|
||||
|
||||
if (nmsItem.item is AxeItem) {
|
||||
f = (f + (nmsItem.item as AxeItem).attackDamage).toInt()
|
||||
}
|
||||
|
||||
if (nmsItem.item is TridentItem) {
|
||||
f = (f + TridentItem.BASE_DAMAGE).toInt()
|
||||
}
|
||||
}
|
||||
|
||||
DUMMY_ENTITY?.setItemSlot(EquipmentSlot.MAINHAND, nmsItem)
|
||||
|
||||
if (!nmsEntity.isAttackable) return
|
||||
val f2 = 1.0f
|
||||
|
||||
var f1 = if (nmsEntity is LivingEntity) {
|
||||
EnchantmentHelper.getDamageBonus(nmsItem, (nmsEntity).mobType)
|
||||
} else {
|
||||
EnchantmentHelper.getDamageBonus(nmsItem, MobType.UNDEFINED)
|
||||
}
|
||||
|
||||
f = (f * (0.2f + f2 * f2 * 0.8f)).toInt()
|
||||
f1 *= f2
|
||||
|
||||
if (f > 0.0f || f1 > 0.0f) {
|
||||
var flag3 = false
|
||||
val b0: Byte = 0
|
||||
val i = b0 + (source.getTool()?.getEnchantmentLevel(Enchantment.KNOCKBACK) ?: 0)
|
||||
|
||||
f = (f * 1.5f).toInt()
|
||||
f = (f + f1).toInt()
|
||||
|
||||
if (nmsItem.item is SwordItem) {
|
||||
flag3 = true
|
||||
}
|
||||
|
||||
var f3 = 0.0f
|
||||
var flag4 = false
|
||||
val j = (source.getTool()?.getEnchantmentLevel(Enchantment.FIRE_ASPECT) ?: 0)
|
||||
|
||||
if (nmsEntity is LivingEntity) {
|
||||
f3 = nmsEntity.health
|
||||
if (j > 0 && !nmsEntity.isOnFire()) {
|
||||
flag4 = true
|
||||
nmsEntity.setSecondsOnFire(1, false)
|
||||
}
|
||||
}
|
||||
|
||||
val event = PreMinionDamageEntityEvent(source, entity as org.bukkit.entity.LivingEntity, f.toDouble())
|
||||
Bukkit.getPluginManager().callEvent(event)
|
||||
if (event.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
val flag5 = nmsEntity.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY!!), f.toFloat())
|
||||
|
||||
if (flag5) {
|
||||
if ((nmsEntity as LivingEntity).isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
if (nmsEntity is LivingEntity) {
|
||||
(nmsEntity).knockback(
|
||||
(i.toFloat() * 0.5f).toDouble(),
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
(-Mth.cos(source.getLocation().yaw * 0.017453292f)).toDouble()
|
||||
)
|
||||
} else {
|
||||
nmsEntity.push(
|
||||
(-Mth.sin(source.getLocation().yaw * 0.017453292f) * i.toFloat() * 0.5f).toDouble(),
|
||||
0.1,
|
||||
(Mth.cos(source.getLocation().yaw * 0.017453292f) * i.toFloat() * 0.5f).toDouble()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (flag3) {
|
||||
val sweep = source.getTool()?.getEnchantmentLevel(Enchantment.SWEEPING_EDGE) ?: 0
|
||||
val f4 =
|
||||
1.0f + if (sweep > 0) SweepingEdgeEnchantment.getSweepingDamageRatio(sweep) else 0.0f * f
|
||||
val list: List<LivingEntity> = (source.getLocation().world as CraftWorld).handle
|
||||
.getEntitiesOfClass(LivingEntity::class.java, nmsEntity.boundingBox.inflate(1.0, 0.25, 1.0)).filter { it !is Player }
|
||||
val iterator: Iterator<*> = list.iterator()
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
val entityliving: LivingEntity = iterator.next() as LivingEntity
|
||||
|
||||
if ((entityliving !is ArmorStand || !(entityliving).isMarker) && source.getLocation()
|
||||
.distanceSquared(
|
||||
(entity as Entity).location
|
||||
) < 9.0
|
||||
) {
|
||||
val damageEvent = PreMinionDamageEntityEvent(
|
||||
source,
|
||||
entityliving.bukkitEntity as org.bukkit.entity.LivingEntity,
|
||||
f4.toDouble()
|
||||
)
|
||||
Bukkit.getPluginManager().callEvent(damageEvent)
|
||||
if (event.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY!!), f4)) {
|
||||
if (entityliving.isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
}
|
||||
entityliving.knockback(
|
||||
0.4000000059604645,
|
||||
Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble(),
|
||||
(-Mth.cos(source.getLocation().yaw * 0.017453292f)).toDouble()
|
||||
)
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
}
|
||||
|
||||
val d0 = -Mth.sin(source.getLocation().yaw * 0.017453292f).toDouble()
|
||||
val d1 = Mth.cos(source.getLocation().yaw * 0.017453292f).toDouble()
|
||||
|
||||
if ((source.getLocation().world as CraftWorld).handle is ServerLevel) {
|
||||
((source.getLocation().world as CraftWorld).handle as ServerLevel).sendParticles(
|
||||
ParticleTypes.SWEEP_ATTACK,
|
||||
source.getLocation().x + d0,
|
||||
source.getLocation().y + 0.5,
|
||||
source.getLocation().z + d1,
|
||||
0,
|
||||
d0,
|
||||
0.0,
|
||||
d1,
|
||||
0.0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val baneOfArthropods = source.getTool()?.getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS) ?: 0
|
||||
if (nmsEntity is LivingEntity) {
|
||||
if (baneOfArthropods > 0 && (nmsEntity.mobType === MobType.ARTHROPOD)) {
|
||||
val p: Int = 20 + nmsEntity.random.nextInt(10 * baneOfArthropods)
|
||||
nmsEntity.addEffect(
|
||||
MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, p, 3),
|
||||
EntityPotionEffectEvent.Cause.ATTACK
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (nmsEntity is LivingEntity) {
|
||||
val f5: Float = f3 - nmsEntity.health
|
||||
|
||||
if (j > 0) {
|
||||
nmsEntity.setSecondsOnFire(j * 4, false)
|
||||
}
|
||||
|
||||
if ((source.getLocation().world as CraftWorld).handle is ServerLevel && f5 > 2.0f) {
|
||||
val k = (f5.toDouble() * 0.5).toInt()
|
||||
|
||||
((source.getLocation().world as CraftWorld).handle).sendParticles(
|
||||
ParticleTypes.DAMAGE_INDICATOR,
|
||||
nmsEntity.getX(),
|
||||
nmsEntity.getY(0.5),
|
||||
nmsEntity.getZ(),
|
||||
k,
|
||||
0.1,
|
||||
0.0,
|
||||
0.1,
|
||||
0.2
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (flag4) {
|
||||
nmsEntity.clearFire()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.artillexstudios.axminions.nms.v1_20_R3
|
||||
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.world.level.storage.loot.BuiltInLootTables
|
||||
import net.minecraft.world.level.storage.loot.LootParams
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld
|
||||
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
object LootHandler {
|
||||
|
||||
fun generateFishingLoot(minion: Minion, waterLocation: Location): List<ItemStack> {
|
||||
val nmsItem: net.minecraft.world.item.ItemStack = if (minion.getTool() == null) {
|
||||
net.minecraft.world.item.ItemStack.EMPTY
|
||||
} else {
|
||||
CraftItemStack.asNMSCopy(minion.getTool())
|
||||
}
|
||||
|
||||
val level = (minion.getLocation().world as CraftWorld).handle
|
||||
|
||||
val lootparams = LootParams.Builder(level).withParameter(
|
||||
LootContextParams.ORIGIN, Vec3(waterLocation.x, waterLocation.y, waterLocation.z)
|
||||
).withParameter(LootContextParams.TOOL, nmsItem).withOptionalParameter(LootContextParams.THIS_ENTITY, null)
|
||||
.create(LootContextParamSets.FISHING)
|
||||
|
||||
val lootTable = MinecraftServer.getServer().lootData.getLootTable(BuiltInLootTables.FISHING)
|
||||
|
||||
return lootTable.getRandomItems(lootparams).stream().map { original: net.minecraft.world.item.ItemStack? ->
|
||||
CraftItemStack.asBukkitCopy(
|
||||
original
|
||||
)
|
||||
}.toList()
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.artillexstudios.axminions.nms.v1_20_R3
|
||||
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import com.artillexstudios.axminions.nms.NMSHandler
|
||||
import net.minecraft.world.entity.MobCategory
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class NMSHandler : NMSHandler {
|
||||
|
||||
override fun attack(source: Minion, target: Entity) {
|
||||
DamageHandler.damage(source, target)
|
||||
}
|
||||
|
||||
override fun generateRandomFishingLoot(minion: Minion, waterLocation: Location): List<ItemStack> {
|
||||
return LootHandler.generateFishingLoot(minion, waterLocation)
|
||||
}
|
||||
|
||||
override fun isAnimal(entity: Entity): Boolean {
|
||||
return (entity as CraftEntity).handle.type.category == MobCategory.CREATURE
|
||||
}
|
||||
}
|
@ -15,4 +15,5 @@ include 'common'
|
||||
include 'nms'
|
||||
include 'nms:v1_20_R1'
|
||||
include 'nms:v1_20_R2'
|
||||
include 'nms:v1_20_R3'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user