Search in sources :

Example 41 with CraftEntity

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project MagicPlugin by elBukkit.

the class CompatibilityUtils method setEntityMotion.

@Override
public void setEntityMotion(Entity entity, Vector motion) {
    net.minecraft.world.entity.Entity nms = ((CraftEntity) entity).getHandle();
    nms.setDeltaMovement(new Vec3(motion.getX(), motion.getY(), motion.getZ()));
}
Also used : Vec3(net.minecraft.world.phys.Vec3) CraftEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity)

Example 42 with CraftEntity

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project MagicPlugin by elBukkit.

the class CompatibilityUtils method magicDamage.

@Override
public void magicDamage(Damageable target, double amount, Entity source) {
    try {
        if (target == null || target.isDead())
            return;
        // Might need to config-drive this, or just go back to defaulting to normal damage
        if (!USE_MAGIC_DAMAGE || target instanceof Witch || target instanceof Enderman || target instanceof ArmorStand || !(target instanceof LivingEntity)) {
            damage(target, amount, source);
            return;
        }
        net.minecraft.world.entity.Entity targetHandle = ((CraftEntity) target).getHandle();
        if (targetHandle == null)
            return;
        net.minecraft.world.entity.Entity sourceHandle = source == null ? null : ((CraftEntity) source).getHandle();
        // Bukkit won't allow magic damage from anything but a potion..
        if (sourceHandle != null && source instanceof LivingEntity) {
            Location location = target.getLocation();
            ThrownPotion potion = getOrCreatePotionEntity(location);
            net.minecraft.world.entity.Entity potionHandle = ((CraftEntity) potion).getHandle();
            potion.setShooter((LivingEntity) source);
            DamageSource magicSource = DamageSource.indirectMagic(potionHandle, sourceHandle);
            // This is a bit of hack that lets us damage the ender dragon, who is a weird and annoying collection
            // of various non-living entity pieces.
            ((EntityDamageSource) magicSource).setThorns();
            try (EnteredStateTracker.Touchable damaging = isDamaging.enter()) {
                damaging.touch();
                targetHandle.hurt(magicSource, (float) amount);
            }
        } else {
            try (EnteredStateTracker.Touchable damaging = isDamaging.enter()) {
                damaging.touch();
                targetHandle.hurt(DamageSource.MAGIC, (float) amount);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : EntityDamageSource(net.minecraft.world.damagesource.EntityDamageSource) DamageSource(net.minecraft.world.damagesource.DamageSource) CraftEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity) EntityDamageSource(net.minecraft.world.damagesource.EntityDamageSource) LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftLivingEntity) CraftArmorStand(org.bukkit.craftbukkit.v1_18_R1.entity.CraftArmorStand) ArmorStand(org.bukkit.entity.ArmorStand) Enderman(org.bukkit.entity.Enderman) ThrownPotion(org.bukkit.entity.ThrownPotion) EnteredStateTracker(com.elmakers.mine.bukkit.utility.EnteredStateTracker) Witch(org.bukkit.entity.Witch) Location(org.bukkit.Location)

Example 43 with CraftEntity

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project MagicPlugin by elBukkit.

the class CompatibilityUtils method damage.

@Override
public void damage(Damageable target, double amount, Entity source, String damageType) {
    if (target == null || target.isDead())
        return;
    if (damageType.equalsIgnoreCase("direct")) {
        double health = target.getHealth() - amount;
        target.setHealth(Math.max(health, 0));
        return;
    }
    if (damageType.equalsIgnoreCase("magic")) {
        magicDamage(target, amount, source);
        return;
    }
    DamageSource damageSource = getDamageSource(damageType);
    if (damageSource == null) {
        magicDamage(target, amount, source);
        return;
    }
    net.minecraft.world.entity.Entity targetHandle = ((CraftEntity) target).getHandle();
    if (targetHandle == null)
        return;
    try (EnteredStateTracker.Touchable damaging = isDamaging.enter()) {
        damaging.touch();
        targetHandle.hurt(damageSource, (float) amount);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : EntityDamageSource(net.minecraft.world.damagesource.EntityDamageSource) DamageSource(net.minecraft.world.damagesource.DamageSource) CraftEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity) EnteredStateTracker(com.elmakers.mine.bukkit.utility.EnteredStateTracker)

Example 44 with CraftEntity

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project MagicPlugin by elBukkit.

the class CompatibilityUtils method getHitbox.

@Override
public BoundingBox getHitbox(Entity entity) {
    net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
    AABB aabb = nmsEntity.getBoundingBox();
    if (aabb == null) {
        return null;
    }
    return new BoundingBox(aabb.minX, aabb.maxX, aabb.minY, aabb.maxY, aabb.minZ, aabb.maxZ);
}
Also used : BoundingBox(com.elmakers.mine.bukkit.utility.BoundingBox) CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity) AABB(net.minecraft.world.phys.AABB)

Example 45 with CraftEntity

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project MagicPlugin by elBukkit.

the class CompatibilityUtils method magicDamage.

@Override
public void magicDamage(Damageable target, double amount, Entity source) {
    try {
        if (target == null || target.isDead())
            return;
        // Might need to config-drive this, or just go back to defaulting to normal damage
        if (!USE_MAGIC_DAMAGE || target instanceof Witch || target instanceof Enderman || target instanceof ArmorStand || !(target instanceof LivingEntity)) {
            damage(target, amount, source);
            return;
        }
        net.minecraft.world.entity.Entity targetHandle = ((CraftEntity) target).getHandle();
        if (targetHandle == null)
            return;
        net.minecraft.world.entity.Entity sourceHandle = source == null ? null : ((CraftEntity) source).getHandle();
        // Bukkit won't allow magic damage from anything but a potion..
        if (sourceHandle != null && source instanceof LivingEntity) {
            Location location = target.getLocation();
            ThrownPotion potion = getOrCreatePotionEntity(location);
            net.minecraft.world.entity.Entity potionHandle = ((CraftEntity) potion).getHandle();
            potion.setShooter((LivingEntity) source);
            DamageSource magicSource = DamageSource.indirectMagic(potionHandle, sourceHandle);
            // This is a bit of hack that lets us damage the ender dragon, who is a weird and annoying collection
            // of various non-living entity pieces.
            ((EntityDamageSource) magicSource).setThorns();
            try (EnteredStateTracker.Touchable damaging = isDamaging.enter()) {
                damaging.touch();
                targetHandle.hurt(magicSource, (float) amount);
            }
        } else {
            try (EnteredStateTracker.Touchable damaging = isDamaging.enter()) {
                damaging.touch();
                targetHandle.hurt(DamageSource.MAGIC, (float) amount);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : EntityDamageSource(net.minecraft.world.damagesource.EntityDamageSource) DamageSource(net.minecraft.world.damagesource.DamageSource) CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity) EntityDamageSource(net.minecraft.world.damagesource.EntityDamageSource) CraftLivingEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ArmorStand(org.bukkit.entity.ArmorStand) CraftArmorStand(org.bukkit.craftbukkit.v1_18_R2.entity.CraftArmorStand) Enderman(org.bukkit.entity.Enderman) ThrownPotion(org.bukkit.entity.ThrownPotion) EnteredStateTracker(com.elmakers.mine.bukkit.utility.EnteredStateTracker) Witch(org.bukkit.entity.Witch) Location(org.bukkit.Location)

Aggregations

Entity (org.bukkit.entity.Entity)29 Iterator (java.util.Iterator)21 List (java.util.List)21 LivingEntity (org.bukkit.entity.LivingEntity)21 CraftEntity (org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity)17 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)16 UUID (java.util.UUID)12 Location (org.bukkit.Location)11 EnteredStateTracker (com.elmakers.mine.bukkit.utility.EnteredStateTracker)10 DamageSource (net.minecraft.world.damagesource.DamageSource)10 EntityDamageSource (net.minecraft.world.damagesource.EntityDamageSource)10 CraftEntity (org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity)10 HashSet (java.util.HashSet)8 Set (java.util.Set)8 CraftEntity (org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity)8 CraftEntity (org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity)8 CraftEntity (org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity)7 CraftEntity (org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity)6 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 EntityAttachmentHelper (com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper)5