mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-22 11:35:19 +01:00
Damage as dummy armorstand
This commit is contained in:
parent
0a6e666e37
commit
cad8333ea6
@ -3,12 +3,8 @@ package com.artillexstudios.axminions.nms.v1_20_R1
|
||||
import com.artillexstudios.axminions.api.events.MinionKillEntityEvent
|
||||
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import com.mojang.authlib.GameProfile
|
||||
import java.util.UUID
|
||||
import net.minecraft.core.particles.ParticleTypes
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.effect.MobEffectInstance
|
||||
import net.minecraft.world.effect.MobEffects
|
||||
@ -31,19 +27,16 @@ import org.bukkit.entity.Entity
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
|
||||
object DamageHandler {
|
||||
private var DUMMY_PLAYER: ServerPlayer? = null
|
||||
private var DUMMY_ENTITY: LivingEntity? = null
|
||||
|
||||
fun damage(source: Minion, entity: Entity) {
|
||||
val nmsEntity = (entity as CraftEntity).handle
|
||||
if (DUMMY_PLAYER === null) {
|
||||
DUMMY_PLAYER = ServerPlayer(
|
||||
MinecraftServer.getServer(),
|
||||
nmsEntity.level() as ServerLevel,
|
||||
GameProfile(UUID.randomUUID(), "axdummy")
|
||||
)
|
||||
if (DUMMY_ENTITY === null) {
|
||||
DUMMY_ENTITY =
|
||||
ArmorStand(net.minecraft.world.entity.EntityType.ARMOR_STAND, nmsEntity.level() as ServerLevel)
|
||||
}
|
||||
|
||||
synchronized(DUMMY_PLAYER!!) {
|
||||
synchronized(DUMMY_ENTITY!!) {
|
||||
var f = 1
|
||||
|
||||
val nmsItem: ItemStack
|
||||
@ -65,7 +58,7 @@ object DamageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
DUMMY_PLAYER?.setItemSlot(EquipmentSlot.MAINHAND, nmsItem)
|
||||
DUMMY_ENTITY?.setItemSlot(EquipmentSlot.MAINHAND, nmsItem)
|
||||
|
||||
if (!nmsEntity.isAttackable) return
|
||||
val f2 = 1.0f
|
||||
@ -109,7 +102,7 @@ object DamageHandler {
|
||||
return
|
||||
}
|
||||
|
||||
val flag5 = nmsEntity.hurt(nmsEntity.damageSources().playerAttack(DUMMY_PLAYER!!), f.toFloat())
|
||||
val flag5 = nmsEntity.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY!!), f.toFloat())
|
||||
|
||||
if (flag5) {
|
||||
if ((nmsEntity as LivingEntity).isDeadOrDying) {
|
||||
@ -160,7 +153,7 @@ object DamageHandler {
|
||||
}
|
||||
|
||||
// CraftBukkit start - Only apply knockback if the damage hits
|
||||
if (entityliving.hurt(nmsEntity.damageSources().playerAttack(DUMMY_PLAYER!!), f4)) {
|
||||
if (entityliving.hurt(nmsEntity.damageSources().noAggroMobAttack(DUMMY_ENTITY!!), f4)) {
|
||||
if (entityliving.isDeadOrDying) {
|
||||
val killEvent = MinionKillEntityEvent(source, entity, entityliving.drops)
|
||||
Bukkit.getPluginManager().callEvent(killEvent)
|
||||
|
Loading…
Reference in New Issue
Block a user