use of org.bukkit.attribute.AttributeInstance in project Denizen-For-Bukkit by DenizenScript.
the class EntityAttributeBaseValues method attributeBaseValues.
public MapTag attributeBaseValues() {
MapTag result = new MapTag();
Attributable ent = getAttributable();
for (Attribute attr : Attribute.values()) {
AttributeInstance instance = ent.getAttribute(attr);
if (instance != null) {
result.putObject(attr.name(), new ElementTag(instance.getBaseValue()));
}
}
return result;
}
use of org.bukkit.attribute.AttributeInstance in project Denizen-For-Bukkit by DenizenScript.
the class EntityAttributeBaseValues method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("attribute_base_values") && mechanism.requireObject(MapTag.class)) {
MapTag input = mechanism.valueAsType(MapTag.class);
Attributable ent = getAttributable();
for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
Attribute attr = Attribute.valueOf(subValue.getKey().str.toUpperCase());
AttributeInstance instance = ent.getAttribute(attr);
if (instance == null) {
mechanism.echoError("Attribute " + attr.name() + " is not applicable to entity of type " + entity.getBukkitEntityType().name());
continue;
}
ElementTag value = subValue.getValue().asElement();
if (!value.isDouble()) {
mechanism.echoError("Invalid input '" + value + "': must be a decimal number.");
continue;
}
instance.setBaseValue(value.asDouble());
}
}
}
use of org.bukkit.attribute.AttributeInstance in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method getDamageTo.
@Override
public double getDamageTo(LivingEntity attacker, Entity target) {
MobType monsterType;
if (target instanceof LivingEntity) {
monsterType = ((CraftLivingEntity) target).getHandle().getMobType();
} else {
monsterType = MobType.UNDEFINED;
}
double damage = 0;
AttributeInstance attrib = attacker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE);
if (attrib != null) {
damage = attrib.getValue();
}
if (attacker.getEquipment() != null && attacker.getEquipment().getItemInMainHand() != null) {
damage += EnchantmentHelper.getDamageBonus(CraftItemStack.asNMSCopy(attacker.getEquipment().getItemInMainHand()), monsterType);
}
if (damage <= 0) {
return 0;
}
if (target != null) {
DamageSource source;
if (attacker instanceof Player) {
source = DamageSource.playerAttack(((CraftPlayer) attacker).getHandle());
} else {
source = DamageSource.mobAttack(((CraftLivingEntity) attacker).getHandle());
}
net.minecraft.world.entity.Entity nmsTarget = ((CraftEntity) target).getHandle();
if (nmsTarget.isInvulnerableTo(source)) {
return 0;
}
if (!(nmsTarget instanceof net.minecraft.world.entity.LivingEntity)) {
return damage;
}
net.minecraft.world.entity.LivingEntity livingTarget = (net.minecraft.world.entity.LivingEntity) nmsTarget;
damage = CombatRules.getDamageAfterAbsorb((float) damage, (float) livingTarget.getArmorValue(), (float) livingTarget.getAttributeValue(Attributes.ARMOR_TOUGHNESS));
int enchantDamageModifier = EnchantmentHelper.getDamageProtection(livingTarget.getArmorSlots(), source);
if (enchantDamageModifier > 0) {
damage = CombatRules.getDamageAfterMagicAbsorb((float) damage, (float) enchantDamageModifier);
}
}
return damage;
}
use of org.bukkit.attribute.AttributeInstance in project solinia3-core by mixxit.
the class SoliniaLivingEntity method updateMaxHp.
@Override
public void updateMaxHp() {
double calculatedhp = getMaxHP();
AttributeInstance healthAttribute = getBukkitLivingEntity().getAttribute(Attribute.GENERIC_MAX_HEALTH);
healthAttribute.setBaseValue(calculatedhp);
}
use of org.bukkit.attribute.AttributeInstance 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