From cad8333ea6b386d5923708555ecd28fe9c308269 Mon Sep 17 00:00:00 2001 From: TomTom <93038247+AverageGithub@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:38:29 +0200 Subject: [PATCH] Damage as dummy armorstand --- .../axminions/nms/v1_20_R1/DamageHandler.kt | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/nms/v1_20_R1/src/main/kotlin/com/artillexstudios/axminions/nms/v1_20_R1/DamageHandler.kt b/nms/v1_20_R1/src/main/kotlin/com/artillexstudios/axminions/nms/v1_20_R1/DamageHandler.kt index 7104e93..ad9a657 100644 --- a/nms/v1_20_R1/src/main/kotlin/com/artillexstudios/axminions/nms/v1_20_R1/DamageHandler.kt +++ b/nms/v1_20_R1/src/main/kotlin/com/artillexstudios/axminions/nms/v1_20_R1/DamageHandler.kt @@ -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)