Search in sources :

Example 6 with EntityInsentient

use of net.minecraft.server.v1_15_R1.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method updateAI.

public static void updateAI(EntityLiving entity) {
    if (entity instanceof EntityInsentient) {
        EntityInsentient handle = (EntityInsentient) entity;
        handle.getEntitySenses().a();
        NMSImpl.updateNavigation(handle.getNavigation());
        handle.getControllerMove().a();
        handle.getControllerLook().a();
        handle.getControllerJump().b();
    } else if (entity instanceof EntityHumanNPC) {
        ((EntityHumanNPC) entity).updateAI();
    }
}
Also used : EntityInsentient(net.minecraft.server.v1_12_R1.EntityInsentient) EntityHumanNPC(net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)

Example 7 with EntityInsentient

use of net.minecraft.server.v1_15_R1.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method updatePathfindingRange.

@Override
public void updatePathfindingRange(NPC npc, float pathfindingRange) {
    if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
        return;
    EntityLiving en = NMSImpl.getHandle((LivingEntity) npc.getEntity());
    if (!(en instanceof EntityInsentient)) {
        if (en instanceof EntityHumanNPC) {
            ((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange);
        }
        return;
    }
    if (PATHFINDING_RANGE == null)
        return;
    EntityInsentient handle = (EntityInsentient) en;
    NavigationAbstract navigation = handle.getNavigation();
    try {
        AttributeInstance inst = (AttributeInstance) PATHFINDING_RANGE.get(navigation);
        inst.setValue(pathfindingRange);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : EntityLiving(net.minecraft.server.v1_12_R1.EntityLiving) AttributeInstance(net.minecraft.server.v1_12_R1.AttributeInstance) EntityInsentient(net.minecraft.server.v1_12_R1.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_12_R1.NavigationAbstract) EntityHumanNPC(net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)

Example 8 with EntityInsentient

use of net.minecraft.server.v1_15_R1.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method look.

@Override
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
    Entity handle = NMSImpl.getHandle(entity);
    if (immediate || headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType()) || (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
        Location fromLocation = entity.getLocation(FROM_LOCATION);
        double xDiff, yDiff, zDiff;
        xDiff = to.getX() - fromLocation.getX();
        yDiff = to.getY() - fromLocation.getY();
        zDiff = to.getZ() - fromLocation.getZ();
        double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
        double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff);
        double yaw = Math.toDegrees(Math.acos(xDiff / distanceXZ));
        double pitch = Math.toDegrees(Math.acos(yDiff / distanceY)) - 90;
        if (zDiff < 0.0)
            yaw += Math.abs(180 - yaw) * 2;
        if (handle instanceof EntityEnderDragon) {
            yaw = getDragonYaw(handle, to.getX(), to.getZ());
        } else {
            yaw = yaw - 90;
        }
        if (headOnly) {
            setHeadYaw(entity, (float) yaw);
        } else {
            look(entity, (float) yaw, (float) pitch);
        }
        return;
    }
    if (handle instanceof EntityInsentient) {
        ((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(), ((EntityInsentient) handle).cL(), ((EntityInsentient) handle).N());
        while (((EntityLiving) handle).aP >= 180F) {
            ((EntityLiving) handle).aP -= 360F;
        }
        while (((EntityLiving) handle).aP < -180F) {
            ((EntityLiving) handle).aP += 360F;
        }
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).setTargetLook(to);
    }
}
Also used : PathEntity(net.minecraft.server.v1_11_R1.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) Entity(net.minecraft.server.v1_11_R1.Entity) EntityEnderDragon(net.minecraft.server.v1_11_R1.EntityEnderDragon) EntityInsentient(net.minecraft.server.v1_11_R1.EntityInsentient) EntityHumanNPC(net.citizensnpcs.nms.v1_11_R1.entity.EntityHumanNPC) Location(org.bukkit.Location)

Example 9 with EntityInsentient

use of net.minecraft.server.v1_15_R1.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method updatePathfindingRange.

@Override
public void updatePathfindingRange(NPC npc, float pathfindingRange) {
    if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
        return;
    EntityLiving en = NMSImpl.getHandle((LivingEntity) npc.getEntity());
    if (!(en instanceof EntityInsentient)) {
        if (en instanceof EntityHumanNPC) {
            ((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange);
        }
        return;
    }
    if (PATHFINDING_RANGE == null)
        return;
    EntityInsentient handle = (EntityInsentient) en;
    NavigationAbstract navigation = handle.getNavigation();
    try {
        AttributeInstance inst = (AttributeInstance) PATHFINDING_RANGE.get(navigation);
        inst.setValue(pathfindingRange);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : EntityLiving(net.minecraft.server.v1_11_R1.EntityLiving) AttributeInstance(net.minecraft.server.v1_11_R1.AttributeInstance) EntityInsentient(net.minecraft.server.v1_11_R1.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_11_R1.NavigationAbstract) EntityHumanNPC(net.citizensnpcs.nms.v1_11_R1.entity.EntityHumanNPC)

Example 10 with EntityInsentient

use of net.minecraft.server.v1_15_R1.EntityInsentient in project solinia3-core by mixxit.

the class CommandPet method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    // TODO Auto-generated method stub
    if (sender instanceof Player) {
        try {
            Player player = (Player) sender;
            LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(player.getUniqueId());
            if (pet == null) {
                player.sendMessage("You don't have a pet");
                return true;
            }
            if (pet instanceof Sittable) {
                Sittable sittable = (Sittable) pet;
                if (sittable.isSitting()) {
                    player.sendMessage("You cannot control a pet which is sitting");
                    return true;
                }
            }
            ISoliniaLivingEntity petLivingEntity = SoliniaLivingEntityAdapter.Adapt(pet);
            ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
            if (petLivingEntity == null || solPlayer == null)
                return false;
            if (args.length > 0) {
                String petcommand = args[0];
                if (petcommand.equals("leave")) {
                    if (petLivingEntity != null) {
                        petLivingEntity.clearHateList();
                        if (petLivingEntity.IsCorePet()) {
                            solPlayer.killAllPets();
                        } else {
                            StateManager.getInstance().getEntityManager().removePet(player.getUniqueId(), !petLivingEntity.isCharmed());
                            petLivingEntity.clearHateList();
                        }
                        player.setLastDamageCause(null);
                    }
                }
                if (petcommand.equals("back")) {
                    if (petLivingEntity != null) {
                        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(petLivingEntity.getNpcid());
                        if (npc != null)
                            if (npc.isPetControllable() == false) {
                                player.sendMessage("This pet is not controllable");
                                return true;
                            }
                        player.setLastDamageCause(null);
                        petLivingEntity.clearHateList();
                        ChatUtils.SendHint(player, HINT.PET_BACKINGOFFTGT, "", false);
                        EntityUtils.teleportSafely(pet, player.getLocation());
                    }
                }
                if (petcommand.equals("attack")) {
                    if (solPlayer.getEntityTarget() == null) {
                        ChatUtils.SendHint(player, HINT.NEED_TARGET, "", false);
                    }
                    LivingEntity targetentity = solPlayer.getEntityTarget();
                    if (targetentity != null && !targetentity.getUniqueId().equals(player.getUniqueId())) {
                        if (petLivingEntity != null) {
                            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(petLivingEntity.getNpcid());
                            if (npc != null)
                                if (npc.isPetControllable() == false) {
                                    player.sendMessage("This pet is not controllable");
                                    return true;
                                }
                        }
                        EntityUtils.teleportSafely(pet, player.getLocation());
                        petLivingEntity.setAttackTarget(null);
                        // Mez cancel target
                        Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed(targetentity);
                        if (mezExpiry != null) {
                            petLivingEntity.setAttackTarget(null);
                            player.sendMessage("You cannot send your pet to attack a mezzed target");
                            return false;
                        }
                        if (pet.getUniqueId().equals(targetentity.getUniqueId())) {
                            petLivingEntity.setAttackTarget(null);
                            player.sendMessage("You cannot send your pet to attack itself");
                            return false;
                        }
                        if (petLivingEntity.getOwnerEntity().getUniqueId().equals(targetentity.getUniqueId())) {
                            petLivingEntity.setAttackTarget(null);
                            player.sendMessage("You cannot send your pet to attack you!");
                            return false;
                        }
                        ISoliniaPlayer tmpPlayer = SoliniaPlayerAdapter.Adapt(player);
                        if (tmpPlayer != null && tmpPlayer.isInGroup(targetentity)) {
                            petLivingEntity.setAttackTarget(null);
                            player.sendMessage("You cannot send your pet to attack your group!");
                            return false;
                        }
                        if (!pet.getUniqueId().equals(targetentity.getUniqueId())) {
                            petLivingEntity.setAttackTarget(targetentity);
                            player.sendMessage("You send your pet to attack!");
                            return true;
                        }
                        ChatUtils.SendHint(player, HINT.PET_ATTACKINGTGT, targetentity.getCustomName(), false);
                    }
                    return true;
                }
                if (petcommand.equals("equip")) {
                    if (petLivingEntity != null) {
                        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(petLivingEntity.getNpcid());
                        if (npc != null)
                            if (npc.isPetControllable() == false) {
                                player.sendMessage("This pet is not controllable/equippable");
                                return true;
                            }
                    }
                    PetEquip(player, pet);
                }
                if (petcommand.equals("hatelist")) {
                    player.sendMessage("Hate List: ");
                    if (petLivingEntity != null) {
                        petLivingEntity.sendHateList(player);
                    }
                }
            }
            player.sendMessage("Pet Name: " + pet.getName() + " Pet Level: " + petLivingEntity.getMentorLevel());
            player.sendMessage("Pet HP: " + pet.getHealth() + "/" + pet.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
            EntityInsentient entityhandle = (EntityInsentient) ((org.bukkit.craftbukkit.v1_15_R1.entity.CraftLivingEntity) pet).getHandle();
            double dmg = entityhandle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).getValue();
            player.sendMessage("Pet DMG: " + dmg + " (Hand to Hand)");
            Entity target = ((Creature) pet).getTarget();
            if (target == null) {
                player.sendMessage("Pet Target: None");
            } else {
                player.sendMessage("Pet Target: " + target.getCustomName() + "/" + target.getName());
            }
            player.sendMessage("STR: " + petLivingEntity.getStrength() + " STA: " + petLivingEntity.getStamina() + " AGI: " + petLivingEntity.getAgility() + " DEX: " + petLivingEntity.getDexterity() + " INT: " + petLivingEntity.getIntelligence() + " WIS: " + petLivingEntity.getWisdom() + " CHA: " + petLivingEntity.getCharisma());
            player.sendMessage("Pet Armour Class Mitigation (AC): " + petLivingEntity.getMitigationAC());
            player.sendMessage("Pet Attack Value: " + petLivingEntity.getTotalAtk());
            player.sendMessage("Pet Attack Speed: " + ChatColor.GOLD + petLivingEntity.getHaste() + "%" + ChatColor.RESET);
            player.sendMessage("Pet MainWeapon Attack Rate (Seconds): " + ChatColor.GOLD + petLivingEntity.getAutoAttackTimerFrequencySeconds() + ChatColor.RESET);
            player.sendMessage("Pet Total Rune of: " + petLivingEntity.getRune());
            player.sendMessage("Skills:");
            if (petLivingEntity.getClassObj() != null) {
                if (petLivingEntity.getClassObj().getDodgelevel() > 0)
                    if (petLivingEntity.getMentorLevel() >= petLivingEntity.getClassObj().getDodgelevel())
                        player.sendMessage(ChatColor.GRAY + "Dodge Skill: " + petLivingEntity.getSkill(SkillType.Dodge));
                if (petLivingEntity.getClassObj().getRipostelevel() > 0)
                    if (petLivingEntity.getMentorLevel() >= petLivingEntity.getClassObj().getRipostelevel())
                        player.sendMessage(ChatColor.GRAY + "Riposte Skill: " + petLivingEntity.getSkill(SkillType.Riposte));
                if (petLivingEntity.getClassObj().getDoubleattacklevel() > 0)
                    if (petLivingEntity.getMentorLevel() >= petLivingEntity.getClassObj().getDoubleattacklevel())
                        player.sendMessage(ChatColor.GRAY + "Double Attack Skill: " + petLivingEntity.getSkill(SkillType.DoubleAttack));
                if (petLivingEntity.getClassObj().getSafefalllevel() > 0)
                    if (petLivingEntity.getMentorLevel() >= petLivingEntity.getClassObj().getSafefalllevel())
                        player.sendMessage(ChatColor.GRAY + "Safefall Skill: " + petLivingEntity.getSkill(SkillType.SafeFall));
                if (petLivingEntity.getClassObj().getDualwieldlevel() > 0)
                    if (petLivingEntity.getMentorLevel() >= petLivingEntity.getClassObj().getDualwieldlevel())
                        player.sendMessage(ChatColor.GRAY + "Dual Wield: " + petLivingEntity.getSkill(SkillType.DualWield));
            }
            player.sendMessage("Active Effects:");
            SoliniaEntitySpells spells = StateManager.getInstance().getEntityManager().getActiveEntitySpells(pet);
            for (SoliniaActiveSpell activeSpell : spells.getActiveSpells()) {
                ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
                String removetext = "";
                ChatColor spellcolor = ChatColor.GREEN;
                if (spell.isBeneficial()) {
                    removetext = "Removable spell";
                } else {
                    removetext = "Unremovable spell";
                    spellcolor = ChatColor.RED;
                }
                TextComponent tc = new TextComponent();
                tc.setText("- " + spellcolor + spell.getName() + ChatColor.RESET + " " + activeSpell.getTicksLeft() + " ticks left - ");
                TextComponent tc2 = new TextComponent();
                tc2.setText(removetext);
                tc.addExtra(tc2);
                sender.spigot().sendMessage(tc);
            }
            player.sendMessage("Pet subcommands: /pet back | /pet equip | /pet attack | /pet leave");
            return true;
        } catch (CoreStateInitException e) {
        }
    }
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Sittable(org.bukkit.entity.Sittable) Creature(org.bukkit.entity.Creature) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) EntityInsentient(net.minecraft.server.v1_15_R1.EntityInsentient) Timestamp(java.sql.Timestamp) SoliniaEntitySpells(com.solinia.solinia.Models.SoliniaEntitySpells) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ChatColor(net.md_5.bungee.api.ChatColor) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)14 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)13 EntityInsentient (net.minecraft.server.v1_12_R1.EntityInsentient)6 EntityHumanNPC (net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)5 EntityInsentient (net.minecraft.server.v1_10_R1.EntityInsentient)5 EntityInsentient (net.minecraft.server.v1_11_R1.EntityInsentient)5 EntityInsentient (net.minecraft.server.v1_8_R3.EntityInsentient)5 CommandException (net.citizensnpcs.api.command.exception.CommandException)4 EntityHumanNPC (net.citizensnpcs.nms.v1_10_R1.entity.EntityHumanNPC)4 EntityHumanNPC (net.citizensnpcs.nms.v1_11_R1.entity.EntityHumanNPC)4 EntityHumanNPC (net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC)4 Entity (net.minecraft.server.v1_12_R1.Entity)4 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)4 Location (org.bukkit.Location)4 Entity (net.minecraft.server.v1_10_R1.Entity)3 PathEntity (net.minecraft.server.v1_10_R1.PathEntity)3 Entity (net.minecraft.server.v1_11_R1.Entity)3 PathEntity (net.minecraft.server.v1_11_R1.PathEntity)3 Entity (net.minecraft.server.v1_8_R3.Entity)3 PathEntity (net.minecraft.server.v1_8_R3.PathEntity)3