1.19.x support

This commit is contained in:
AverageGithub 2024-04-05 15:13:49 +02:00
parent 69d9ef092c
commit afa576f21d
15 changed files with 1018 additions and 5 deletions

View File

@ -7,7 +7,7 @@ plugins {
}
group = 'com.artillexstudios.axminions'
version = '1.0.7'
version = '1.0.8'
repositories {
mavenCentral()
@ -20,6 +20,9 @@ repositories {
dependencies {
implementation project(path: ":api")
implementation project(path: ":common")
implementation project(path: ":nms:v1_19_R1", configuration: "reobf")
implementation project(path: ":nms:v1_19_R2", configuration: "reobf")
implementation project(path: ":nms:v1_19_R3", configuration: "reobf")
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")
@ -128,7 +131,7 @@ allprojects {
compileOnly 'com.github.LoneDev6:api-itemsadder:3.6.1'
compileOnly 'com.palmergames.bukkit.towny:towny:0.100.1.0'
implementation platform('com.intellectualsites.bom:bom-newest:1.35')
implementation("com.artillexstudios.axapi:axapi:1.4.100")
implementation("com.artillexstudios.axapi:axapi:1.4.134")
implementation("com.zaxxer:HikariCP:5.1.0")
implementation("org.bstats:bstats-bukkit:3.0.2")
compileOnly 'org.black_ixx:playerpoints:3.2.6'
@ -161,4 +164,4 @@ kotlin {
jvmToolchain(17)
}
tasks.build.dependsOn(shadowJar)
tasks.build.dependsOn(shadowJar)

View File

@ -79,8 +79,8 @@ class SellerMinionType : MinionType("seller", AxMinionsPlugin.INSTANCE.getResour
continue
}
minion.setActions(minion.getActionAmount() + it.amount)
minion.damageTool(it.amount)
minion.setActions(minion.getActionAmount() + 1)
minion.damageTool()
minion.setStorage(minion.getStorage() + price)
it.amount = 0
}

20
nms/v1_19_R1/build.gradle Normal file
View File

@ -0,0 +1,20 @@
plugins {
id("io.papermc.paperweight.userdev")
}
group = 'com.artillexstudios.axminions.nms'
version = '1.0-SNAPSHOT'
dependencies {
paperweight.paperDevBundle("1.19.2-R0.1-SNAPSHOT")
}
tasks {
build {
dependsOn(reobfJar)
}
reobfJar {
mustRunAfter(shadowJar)
}
}

View File

@ -0,0 +1,238 @@
package com.artillexstudios.axminions.nms.v1_19_R1
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
import com.artillexstudios.axminions.api.minions.Minion
import java.util.UUID
import net.minecraft.core.particles.ParticleTypes
import net.minecraft.server.level.ServerLevel
import net.minecraft.util.Mth
import net.minecraft.world.damagesource.DamageSource
import net.minecraft.world.effect.MobEffectInstance
import net.minecraft.world.effect.MobEffects
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.EquipmentSlot
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.MobType
import net.minecraft.world.entity.animal.Fox
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_19_R1.CraftWorld
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity
import org.bukkit.craftbukkit.v1_19_R1.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 = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
fun getUUID() : UUID {
return DUMMY_ENTITY.uuid
}
fun damage(source: Minion, entity: Entity) {
val nmsEntity = (entity as CraftEntity).handle
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(DamageSource.mobAttack(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(DamageSource.mobAttack(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()
}
}
}
}
}
}

View File

@ -0,0 +1,39 @@
package com.artillexstudios.axminions.nms.v1_19_R1
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.LootContext
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_19_R1.CraftWorld
import org.bukkit.craftbukkit.v1_19_R1.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 = LootContext.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().lootTables.get(BuiltInLootTables.FISHING)
return lootTable.getRandomItems(lootparams).stream().map { original: net.minecraft.world.item.ItemStack? ->
CraftItemStack.asBukkitCopy(
original
)
}.toList()
}
}

View File

@ -0,0 +1,39 @@
package com.artillexstudios.axminions.nms.v1_19_R1
import com.artillexstudios.axminions.api.minions.Minion
import com.artillexstudios.axminions.nms.NMSHandler
import java.util.UUID
import net.minecraft.core.BlockPos
import net.minecraft.world.entity.MobCategory
import org.bukkit.Location
import org.bukkit.block.Block
import org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock
import org.bukkit.craftbukkit.v1_19_R1.block.CraftBlockState
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack
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
}
override fun getAnimalUUID(): UUID {
return DamageHandler.getUUID()
}
override fun getExp(block: Block, itemStack: ItemStack): Int {
val craftBlock = block as CraftBlock
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, BlockPos(block.location.blockX, block.location.blockY, block.location.blockZ), CraftItemStack.asNMSCopy(itemStack), true)
}
}

20
nms/v1_19_R2/build.gradle Normal file
View File

@ -0,0 +1,20 @@
plugins {
id("io.papermc.paperweight.userdev")
}
group = 'com.artillexstudios.axminions.nms'
version = '1.0-SNAPSHOT'
dependencies {
paperweight.paperDevBundle("1.19.3-R0.1-SNAPSHOT")
}
tasks {
build {
dependsOn(reobfJar)
}
reobfJar {
mustRunAfter(shadowJar)
}
}

View File

@ -0,0 +1,238 @@
package com.artillexstudios.axminions.nms.v1_19_R2
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
import com.artillexstudios.axminions.api.minions.Minion
import java.util.UUID
import net.minecraft.core.particles.ParticleTypes
import net.minecraft.server.level.ServerLevel
import net.minecraft.util.Mth
import net.minecraft.world.damagesource.DamageSource
import net.minecraft.world.effect.MobEffectInstance
import net.minecraft.world.effect.MobEffects
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.EquipmentSlot
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.MobType
import net.minecraft.world.entity.animal.Fox
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_19_R2.CraftWorld
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity
import org.bukkit.craftbukkit.v1_19_R2.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 = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
fun getUUID() : UUID {
return DUMMY_ENTITY.uuid
}
fun damage(source: Minion, entity: Entity) {
val nmsEntity = (entity as CraftEntity).handle
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(DamageSource.mobAttack(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(DamageSource.mobAttack(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()
}
}
}
}
}
}

View File

@ -0,0 +1,39 @@
package com.artillexstudios.axminions.nms.v1_19_R2
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.LootContext
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_19_R2.CraftWorld
import org.bukkit.craftbukkit.v1_19_R2.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 = LootContext.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().lootTables.get(BuiltInLootTables.FISHING)
return lootTable.getRandomItems(lootparams).stream().map { original: net.minecraft.world.item.ItemStack? ->
CraftItemStack.asBukkitCopy(
original
)
}.toList()
}
}

View File

@ -0,0 +1,39 @@
package com.artillexstudios.axminions.nms.v1_19_R2
import com.artillexstudios.axminions.api.minions.Minion
import com.artillexstudios.axminions.nms.NMSHandler
import java.util.UUID
import net.minecraft.core.BlockPos
import net.minecraft.world.entity.MobCategory
import org.bukkit.Location
import org.bukkit.block.Block
import org.bukkit.craftbukkit.v1_19_R2.block.CraftBlock
import org.bukkit.craftbukkit.v1_19_R2.block.CraftBlockState
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity
import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack
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
}
override fun getAnimalUUID(): UUID {
return DamageHandler.getUUID()
}
override fun getExp(block: Block, itemStack: ItemStack): Int {
val craftBlock = block as CraftBlock
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, BlockPos(block.location.blockX, block.location.blockY, block.location.blockZ), CraftItemStack.asNMSCopy(itemStack), true)
}
}

20
nms/v1_19_R3/build.gradle Normal file
View File

@ -0,0 +1,20 @@
plugins {
id("io.papermc.paperweight.userdev")
}
group = 'com.artillexstudios.axminions.nms'
version = '1.0-SNAPSHOT'
dependencies {
paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT")
}
tasks {
build {
dependsOn(reobfJar)
}
reobfJar {
mustRunAfter(shadowJar)
}
}

View File

@ -0,0 +1,237 @@
package com.artillexstudios.axminions.nms.v1_19_R3
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
import com.artillexstudios.axminions.api.minions.Minion
import java.util.UUID
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.EntityType
import net.minecraft.world.entity.EquipmentSlot
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.MobType
import net.minecraft.world.entity.animal.Fox
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_19_R3.CraftWorld
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity
import org.bukkit.craftbukkit.v1_19_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 = Fox(EntityType.FOX, (Bukkit.getWorlds().get(0) as CraftWorld).handle)
fun getUUID() : UUID {
return DUMMY_ENTITY.uuid
}
fun damage(source: Minion, entity: Entity) {
val nmsEntity = (entity as CraftEntity).handle
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()
}
}
}
}
}
}

View File

@ -0,0 +1,39 @@
package com.artillexstudios.axminions.nms.v1_19_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.LootContext
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_19_R3.CraftWorld
import org.bukkit.craftbukkit.v1_19_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 = LootContext.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().lootTables.get(BuiltInLootTables.FISHING)
return lootTable.getRandomItems(lootparams).stream().map { original: net.minecraft.world.item.ItemStack? ->
CraftItemStack.asBukkitCopy(
original
)
}.toList()
}
}

View File

@ -0,0 +1,39 @@
package com.artillexstudios.axminions.nms.v1_19_R3
import com.artillexstudios.axminions.api.minions.Minion
import com.artillexstudios.axminions.nms.NMSHandler
import java.util.UUID
import net.minecraft.world.entity.MobCategory
import org.bukkit.Location
import org.bukkit.block.Block
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlock
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlockState
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity
import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack
import org.bukkit.craftbukkit.v1_19_R3.util.CraftLocation
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
}
override fun getAnimalUUID(): UUID {
return DamageHandler.getUUID()
}
override fun getExp(block: Block, itemStack: ItemStack): Int {
val craftBlock = block as CraftBlock
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, CraftLocation.toBlockPosition(block.location), CraftItemStack.asNMSCopy(itemStack), true)
}
}

View File

@ -13,6 +13,9 @@ rootProject.name = 'AxMinions'
include 'api'
include 'common'
include 'nms'
include 'nms:v1_19_R1'
include 'nms:v1_19_R2'
include 'nms:v1_19_R3'
include 'nms:v1_20_R1'
include 'nms:v1_20_R2'
include 'nms:v1_20_R3'