Search in sources :

Example 1 with EntityHuman

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

the class WorldHelper_v1_8_R3 method setWorldAccess.

@Override
public void setWorldAccess(World world, final WorldAccess worldAccess) {
    if (worldAccessMap.containsKey(world)) {
        removeWorldAccess(world);
    }
    IWorldAccess nmsWorldAccess = new IWorldAccess() {

        @Override
        public void a(BlockPosition blockPosition) {
        }

        @Override
        public void b(BlockPosition blockPosition) {
        }

        @Override
        public void a(int i, int i1, int i2, int i3, int i4, int i5) {
        }

        @Override
        public void a(String s, double v, double v1, double v2, float v3, float v4) {
        }

        @Override
        public void a(EntityHuman entityHuman, String s, double v, double v1, double v2, float v3, float v4) {
        }

        @Override
        public void a(int i, boolean b, double v, double v1, double v2, double v3, double v4, double v5, int... ints) {
        }

        @Override
        public void a(Entity entity) {
        }

        @Override
        public void b(Entity entity) {
            worldAccess.despawn(entity.getBukkitEntity());
        }

        @Override
        public void a(String s, BlockPosition blockPosition) {
        }

        @Override
        public void a(int i, BlockPosition blockPosition, int i1) {
        }

        @Override
        public void a(EntityHuman entityHuman, int i, BlockPosition blockPosition, int i1) {
        }

        @Override
        public void b(int i, BlockPosition blockPosition, int i1) {
        }
    };
    worldAccessMap.put(world, nmsWorldAccess);
    ((CraftWorld) world).getHandle().addIWorldAccess(nmsWorldAccess);
}
Also used : IWorldAccess(net.minecraft.server.v1_8_R3.IWorldAccess) EntityHuman(net.minecraft.server.v1_8_R3.EntityHuman) Entity(net.minecraft.server.v1_8_R3.Entity) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition)

Example 2 with EntityHuman

use of net.minecraft.server.v1_16_R3.EntityHuman in project Denizen-For-Bukkit 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 3 with EntityHuman

use of net.minecraft.server.v1_16_R3.EntityHuman in project MyPet by xXKeyleXx.

the class EntityMyPiglin method handlePlayerInteraction.

@Override
public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack) == EnumInteractionResult.CONSUME) {
        return EnumInteractionResult.CONSUME;
    }
    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
        if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
            boolean hadEquipment = false;
            for (EquipmentSlot slot : EquipmentSlot.values()) {
                ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
                if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) {
                    EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
                    entityitem.pickupDelay = 10;
                    entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
                    this.world.addEntity(entityitem);
                    getMyPet().setEquipment(slot, null);
                    hadEquipment = true;
                }
            }
            if (hadEquipment) {
                if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                    try {
                        itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
                    } catch (Error e) {
                        // TODO REMOVE
                        itemStack.damage(1, entityhuman, (entityhuman1) -> {
                            try {
                                ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
                            } catch (IllegalAccessException | InvocationTargetException ex) {
                                ex.printStackTrace();
                            }
                        });
                    }
                }
            }
            return EnumInteractionResult.CONSUME;
        } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
            EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.j(itemStack).getSlotFlag());
            ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
            if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
                entityitem.pickupDelay = 10;
                entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
                this.world.addEntity(entityitem);
            }
            getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
            if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                itemStack.subtract(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
                }
            }
            return EnumInteractionResult.CONSUME;
        } else if (Configuration.MyPet.Piglin.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
            if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                itemStack.subtract(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
                }
            }
            getMyPet().setBaby(false);
            return EnumInteractionResult.CONSUME;
        }
    }
    return EnumInteractionResult.PASS;
}
Also used : MyPet(de.Keyle.MyPet.api.entity.MyPet) Util(de.Keyle.MyPet.api.Util) Arrays(java.util.Arrays) PetState(de.Keyle.MyPet.api.entity.MyPet.PetState) EntitySize(de.Keyle.MyPet.api.entity.EntitySize) MyPetApi(de.Keyle.MyPet.MyPetApi) MyPiglin(de.Keyle.MyPet.api.entity.types.MyPiglin) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) Pair(com.mojang.datafixers.util.Pair) InvocationTargetException(java.lang.reflect.InvocationTargetException) ENTITY_LIVING_broadcastItemBreak(de.Keyle.MyPet.compat.v1_16_R3.CompatManager.ENTITY_LIVING_broadcastItemBreak) Configuration(de.Keyle.MyPet.api.Configuration) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet) Bukkit(org.bukkit.Bukkit) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)

Example 4 with EntityHuman

use of net.minecraft.server.v1_16_R3.EntityHuman in project MyPet by xXKeyleXx.

the class EntityMyPillager method handlePlayerInteraction.

/**
 * Is called when player rightclicks this MyPet
 * return:
 * true: there was a reaction on rightclick
 * false: no reaction on rightclick
 */
@Override
public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) {
        return EnumInteractionResult.CONSUME;
    }
    if (getOwner().equals(entityhuman) && itemStack != null) {
        if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
            boolean hadEquipment = false;
            for (EquipmentSlot slot : EquipmentSlot.values()) {
                ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
                if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) {
                    EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
                    entityitem.pickupDelay = 10;
                    entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
                    this.world.addEntity(entityitem);
                    getMyPet().setEquipment(slot, null);
                    hadEquipment = true;
                }
            }
            if (hadEquipment) {
                if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                    try {
                        itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
                    } catch (Error e) {
                        // TODO REMOVE
                        itemStack.damage(1, entityhuman, (entityhuman1) -> {
                            try {
                                ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
                            } catch (IllegalAccessException | InvocationTargetException ex) {
                                ex.printStackTrace();
                            }
                        });
                    }
                }
            }
            return EnumInteractionResult.CONSUME;
        } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
            EquipmentSlot slot = EquipmentSlot.getSlotById(EntityInsentient.j(itemStack).getSlotFlag());
            if (slot == EquipmentSlot.MainHand) {
                ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
                if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                    EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
                    entityitem.pickupDelay = 10;
                    entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
                    this.world.addEntity(entityitem);
                }
                getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
                if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                    itemStack.subtract(1);
                    if (itemStack.getCount() <= 0) {
                        entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
                    }
                }
                return EnumInteractionResult.CONSUME;
            }
        } else if (itemStack.getItem() instanceof ItemBanner && getOwner().getPlayer().isSneaking() && canEquip()) {
            ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(EquipmentSlot.Helmet));
            if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
                entityitem.pickupDelay = 10;
                entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
                this.world.addEntity(entityitem);
            }
            getMyPet().setEquipment(EquipmentSlot.Helmet, CraftItemStack.asBukkitCopy(itemStack));
            if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                itemStack.subtract(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
                }
            }
            return EnumInteractionResult.CONSUME;
        }
    }
    return EnumInteractionResult.PASS;
}
Also used : MyPet(de.Keyle.MyPet.api.entity.MyPet) Util(de.Keyle.MyPet.api.Util) Arrays(java.util.Arrays) MyPillager(de.Keyle.MyPet.api.entity.types.MyPillager) EntitySize(de.Keyle.MyPet.api.entity.EntitySize) MyPetApi(de.Keyle.MyPet.MyPetApi) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) Pair(com.mojang.datafixers.util.Pair) InvocationTargetException(java.lang.reflect.InvocationTargetException) ENTITY_LIVING_broadcastItemBreak(de.Keyle.MyPet.compat.v1_16_R3.CompatManager.ENTITY_LIVING_broadcastItemBreak) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet) Bukkit(org.bukkit.Bukkit) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)

Example 5 with EntityHuman

use of net.minecraft.server.v1_16_R3.EntityHuman in project MyPet by xXKeyleXx.

the class EntityMyGiant method handlePlayerInteraction.

@Override
public EnumInteractionResult handlePlayerInteraction(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemStack) {
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).a()) {
        return EnumInteractionResult.CONSUME;
    }
    if (getOwner().equals(entityhuman) && itemStack != null) {
        if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) {
            boolean hadEquipment = false;
            for (EquipmentSlot slot : EquipmentSlot.values()) {
                ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
                if (itemInSlot != null && itemInSlot.getItem() != Items.AIR) {
                    EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
                    entityitem.pickupDelay = 10;
                    entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
                    this.world.addEntity(entityitem);
                    getMyPet().setEquipment(slot, null);
                    hadEquipment = true;
                }
            }
            if (hadEquipment) {
                if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                    try {
                        itemStack.damage(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastItemBreak(enumhand));
                    } catch (Error e) {
                        // TODO REMOVE
                        itemStack.damage(1, entityhuman, (entityhuman1) -> {
                            try {
                                ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
                            } catch (IllegalAccessException | InvocationTargetException ex) {
                                ex.printStackTrace();
                            }
                        });
                    }
                }
            }
            return EnumInteractionResult.CONSUME;
        } else if (MyPetApi.getPlatformHelper().isEquipment(CraftItemStack.asBukkitCopy(itemStack)) && getOwner().getPlayer().isSneaking() && canEquip()) {
            EquipmentSlot slot = EquipmentSlot.getSlotById(j(itemStack).getSlotFlag());
            ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot));
            if (itemInSlot != null && itemInSlot.getItem() != Items.AIR && itemInSlot != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + 1, this.locZ(), itemInSlot);
                entityitem.pickupDelay = 10;
                entityitem.setMot(entityitem.getMot().add(0, this.random.nextFloat() * 0.05F, 0));
                this.world.addEntity(entityitem);
            }
            getMyPet().setEquipment(slot, CraftItemStack.asBukkitCopy(itemStack));
            if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                itemStack.subtract(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
                }
            }
            return EnumInteractionResult.CONSUME;
        }
    }
    return EnumInteractionResult.PASS;
}
Also used : MyPet(de.Keyle.MyPet.api.entity.MyPet) Util(de.Keyle.MyPet.api.Util) Arrays(java.util.Arrays) EntitySize(de.Keyle.MyPet.api.entity.EntitySize) MyPetApi(de.Keyle.MyPet.MyPetApi) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) Pair(com.mojang.datafixers.util.Pair) MeleeAttack(de.Keyle.MyPet.compat.v1_16_R3.entity.ai.attack.MeleeAttack) InvocationTargetException(java.lang.reflect.InvocationTargetException) ENTITY_LIVING_broadcastItemBreak(de.Keyle.MyPet.compat.v1_16_R3.CompatManager.ENTITY_LIVING_broadcastItemBreak) MyGiant(de.Keyle.MyPet.api.entity.types.MyGiant) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet) Bukkit(org.bukkit.Bukkit) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)

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