use of io.lumine.xikage.mythicmobs.api.exceptions.InvalidMobTypeException in project solinia3-core by mixxit.
the class EntityManager method SpawnPet.
@Override
public LivingEntity SpawnPet(Player owner, ISoliniaSpell spell) {
if (owner.isDead())
return null;
try {
LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(owner.getUniqueId());
if (pet != null) {
// insta kill old pet
pet.damage(10000000);
// ISoliniaLivingEntity solLivingEntity = SoliniaLivingEntityAdapter.Adapt(pet);
// solLivingEntity.get
// StateManager.getInstance().getEntityManager().removePet(owner.getUniqueId(), !solLivingEntity.isCharmed());
}
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(spell.getTeleportZone());
if (npc == null)
return null;
if (npc.isCorePet() == false)
return null;
//
// PET FOCUS ITEM
// If owner is wearing a focus item at this point, and it is valid then we should record the mob is now
// part of this focus
LivingEntity spawnedMob = (LivingEntity) MythicMobs.inst().getAPIHelper().spawnMythicMob("NPCID_" + npc.getId(), owner.getLocation());
spawnedMob.setCollidable(false);
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(owner);
int petFocus = solplayer.getPetFocus(npc);
if (petFocus > 0) {
StateManager.getInstance().getEntityManager().setPetFocus(spawnedMob.getUniqueId(), petFocus);
solplayer.getBukkitPlayer().sendMessage("Your pet focus shimmers with a bright light");
}
ISoliniaLivingEntity solPet = SoliniaLivingEntityAdapter.Adapt((LivingEntity) spawnedMob);
StateManager.getInstance().getEntityManager().setPet(owner.getUniqueId(), spawnedMob);
spawnedMob.setCustomName(solplayer.getForename() + "s_Pet");
spawnedMob.setCustomNameVisible(true);
spawnedMob.setCanPickupItems(false);
spawnedMob.setRemoveWhenFarAway(false);
double maxHp = solPet.getMaxHP();
if (npc.getForcedMaxHp() > 0) {
maxHp = (double) npc.getForcedMaxHp();
}
AttributeInstance healthAttribute = spawnedMob.getAttribute(Attribute.GENERIC_MAX_HEALTH);
healthAttribute.setBaseValue(maxHp);
if (!spawnedMob.isDead())
spawnedMob.setHealth(maxHp);
net.minecraft.server.v1_15_R1.EntityInsentient entityhandle = (net.minecraft.server.v1_15_R1.EntityInsentient) ((org.bukkit.craftbukkit.v1_15_R1.entity.CraftLivingEntity) spawnedMob).getHandle();
entityhandle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue((double) npc.getBaseDamage());
entityhandle.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue((double) 0.4D);
owner.sendMessage("New Pet spawned with HP: " + spawnedMob.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() + " and " + npc.getBaseDamage() + " dmg");
Disguise disg = new MobDisguise(DisguiseType.WOLF);
if (npc.getDisguiseId() > 0 && npc.getDisguise() != null)
disg = npc.getDisguise().getLibsDisguise(0);
if (npc.isRacialPet() && solplayer.getRace() != null && solplayer.getRace().getRacePetDisguiseId() > 0 && solplayer.getRace().getRacePetDisguise() != null)
disg = solplayer.getRace().getRacePetDisguise().getLibsDisguise(0);
DisguiseAPI.disguiseEntity(spawnedMob, disg);
return spawnedMob;
} catch (CoreStateInitException e) {
return null;
} catch (InvalidMobTypeException e) {
return null;
}
}
Aggregations