Search in sources :

Example 61 with EntityHuman

use of net.minecraft.server.v1_16_R3.EntityHuman in project Denizen by DenizenScript.

the class EntityHelperImpl method damage.

@Override
public void damage(LivingEntity target, float amount, Entity source, EntityDamageEvent.DamageCause cause) {
    if (target == null) {
        return;
    }
    EntityLiving nmsTarget = ((CraftLivingEntity) target).getHandle();
    net.minecraft.server.v1_16_R3.Entity nmsSource = source == null ? null : ((CraftEntity) source).getHandle();
    CraftEventFactory.entityDamage = nmsSource;
    try {
        DamageSource src = DamageSource.GENERIC;
        if (nmsSource != null) {
            if (nmsSource instanceof EntityHuman) {
                src = DamageSource.playerAttack((EntityHuman) nmsSource);
            } else if (nmsSource instanceof EntityLiving) {
                src = DamageSource.mobAttack((EntityLiving) nmsSource);
            }
        }
        if (cause != null) {
            switch(cause) {
                case CONTACT:
                    src = DamageSource.CACTUS;
                    break;
                case ENTITY_ATTACK:
                    src = DamageSource.mobAttack(nmsSource instanceof EntityLiving ? (EntityLiving) nmsSource : null);
                    break;
                case ENTITY_SWEEP_ATTACK:
                    if (src != DamageSource.GENERIC) {
                        src.sweep();
                    }
                    break;
                case PROJECTILE:
                    src = DamageSource.projectile(nmsSource, source instanceof Projectile && ((Projectile) source).getShooter() instanceof Entity ? ((CraftEntity) ((Projectile) source).getShooter()).getHandle() : null);
                    break;
                case SUFFOCATION:
                    src = DamageSource.STUCK;
                    break;
                case FALL:
                    src = DamageSource.FALL;
                    break;
                case FIRE:
                    src = DamageSource.FIRE;
                    break;
                case FIRE_TICK:
                    src = DamageSource.BURN;
                    break;
                case MELTING:
                    src = CraftEventFactory.MELTING;
                    break;
                case LAVA:
                    src = DamageSource.LAVA;
                    break;
                case DROWNING:
                    src = DamageSource.DROWN;
                    break;
                case BLOCK_EXPLOSION:
                    src = DamageSource.d(nmsSource instanceof TNTPrimed && ((TNTPrimed) nmsSource).getSource() instanceof EntityLiving ? (EntityLiving) ((TNTPrimed) nmsSource).getSource() : null);
                    break;
                case ENTITY_EXPLOSION:
                    src = DamageSource.d(nmsSource instanceof EntityLiving ? (EntityLiving) nmsSource : null);
                    break;
                case VOID:
                    src = DamageSource.OUT_OF_WORLD;
                    break;
                case LIGHTNING:
                    src = DamageSource.LIGHTNING;
                    break;
                case STARVATION:
                    src = DamageSource.STARVE;
                    break;
                case POISON:
                    src = CraftEventFactory.POISON;
                    break;
                case MAGIC:
                    src = DamageSource.MAGIC;
                    break;
                case WITHER:
                    src = DamageSource.WITHER;
                    break;
                case FALLING_BLOCK:
                    src = DamageSource.FALLING_BLOCK;
                    break;
                case THORNS:
                    src = DamageSource.a(nmsSource);
                    break;
                case DRAGON_BREATH:
                    src = DamageSource.DRAGON_BREATH;
                    break;
                case CUSTOM:
                    src = DamageSource.GENERIC;
                    break;
                case FLY_INTO_WALL:
                    src = DamageSource.FLY_INTO_WALL;
                    break;
                case HOT_FLOOR:
                    src = DamageSource.HOT_FLOOR;
                    break;
                case CRAMMING:
                    src = DamageSource.CRAMMING;
                    break;
                case DRYOUT:
                    src = DamageSource.DRYOUT;
                    break;
                // case SUICIDE:
                default:
                    EntityDamageEvent ede = fireFakeDamageEvent(target, source, cause, amount);
                    if (ede.isCancelled()) {
                        return;
                    }
                    break;
            }
        }
        nmsTarget.damageEntity(src, amount);
    } finally {
        CraftEventFactory.entityDamage = null;
    }
}
Also used : Entity(org.bukkit.entity.Entity) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 62 with EntityHuman

use of net.minecraft.server.v1_16_R3.EntityHuman in project PublicCrafters by BananaPuncher714.

the class CustomTileEntityContainerWorkbench method createMenu.

/**
 * This is an ITileEntityContainer method that returns a new container for whatever tile entity
 */
@Override
public Container createMenu(int id, PlayerInventory inv, EntityHuman ent) {
    CustomInventoryCrafting crafting = manager.benches.get(bloc);
    if (crafting == null) {
        crafting = new CustomInventoryCrafting(bloc, manager, new SelfContainer(id), 3, 3);
        manager.put(bloc, crafting);
    }
    IInventory inventory = crafting.resultInventory;
    InventoryCraftResult result;
    if (inventory instanceof InventoryCraftResult || inventory == null) {
        result = new InventoryCraftResult();
        crafting.resultInventory = result;
    } else {
        result = (InventoryCraftResult) inventory;
    }
    Container container = new CustomContainerWorkbench(id, ent.getBukkitEntity(), bloc, crafting, result);
    crafting.addContainer(container);
    return container;
}
Also used : IInventory(net.minecraft.server.v1_16_R3.IInventory) Container(net.minecraft.server.v1_16_R3.Container) SelfContainer(io.github.bananapuncher714.crafters.implementation.v1_16_R3.ContainerManager_v1_16_R3.SelfContainer) ITileEntityContainer(net.minecraft.server.v1_16_R3.ITileEntityContainer) SelfContainer(io.github.bananapuncher714.crafters.implementation.v1_16_R3.ContainerManager_v1_16_R3.SelfContainer) InventoryCraftResult(net.minecraft.server.v1_16_R3.InventoryCraftResult)

Aggregations

net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)20 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)19 MyPetApi (de.Keyle.MyPet.MyPetApi)18 EntitySize (de.Keyle.MyPet.api.entity.EntitySize)18 MyPet (de.Keyle.MyPet.api.entity.MyPet)18 EntityMyPet (de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 Pair (com.mojang.datafixers.util.Pair)17 Util (de.Keyle.MyPet.api.Util)17 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)17 Arrays (java.util.Arrays)17 Bukkit (org.bukkit.Bukkit)17 ENTITY_LIVING_broadcastItemBreak (de.Keyle.MyPet.compat.v1_16_R3.CompatManager.ENTITY_LIVING_broadcastItemBreak)15 LivingEntity (org.bukkit.entity.LivingEntity)15 Configuration (de.Keyle.MyPet.api.Configuration)10 EntityHuman (net.minecraft.server.v1_11_R1.EntityHuman)7 PetState (de.Keyle.MyPet.api.entity.MyPet.PetState)6 EntityHuman (net.minecraft.server.v1_12_R1.EntityHuman)6 EntityHuman (net.minecraft.server.v1_8_R3.EntityHuman)6 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)5