/** * Creates an NBTTagCompound from an AttributeInstance, including its AttributeModifiers */ private static NBTTagCompound writeAttributeInstanceToNBT(IAttributeInstance instance) { NBTTagCompound nbttagcompound = new NBTTagCompound(); IAttribute iattribute = instance.getAttribute(); nbttagcompound.setString("Name", iattribute.getAttributeUnlocalizedName()); nbttagcompound.setDouble("Base", instance.getBaseValue()); Collection<AttributeModifier> collection = instance.getModifiers(); if (collection != null && !collection.isEmpty()) { NBTTagList nbttaglist = new NBTTagList(); for (AttributeModifier attributemodifier : collection) { if (attributemodifier.isSaved()) { nbttaglist.appendTag(writeAttributeModifierToNBT(attributemodifier)); } } nbttagcompound.setTag("Modifiers", nbttaglist); } return nbttagcompound; }
protected void updateAITasks() { IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); if (this.isAngry()) { --this.angerLevel; } if (this.randomSoundDelay > 0 && --this.randomSoundDelay == 0) { this.playSound(SoundEvents.ENTITY_ZOMBIE_PIG_ANGRY, this.getSoundVolume() * 2.0F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) * 1.8F); } if (this.angerLevel > 0 && this.angerTargetUUID != null && this.getAITarget() == null) { EntityPlayer entityplayer = this.world.getPlayerEntityByUUID(this.angerTargetUUID); this.setRevengeTarget(entityplayer); this.attackingPlayer = entityplayer; this.recentlyHit = this.getRevengeTimer(); } super.updateAITasks(); }
private static void applyModifiersToAttributeInstance(IAttributeInstance instance, NBTTagCompound compound) { instance.setBaseValue(compound.getDouble("Base")); if (compound.hasKey("Modifiers", 9)) { NBTTagList nbttaglist = compound.getTagList("Modifiers", 10); for (int i = 0; i < nbttaglist.tagCount(); ++i) { AttributeModifier attributemodifier = readAttributeModifierFromNBT(nbttaglist.getCompoundTagAt(i)); if (attributemodifier != null) { AttributeModifier attributemodifier1 = instance.getModifier(attributemodifier.getID()); if (attributemodifier1 != null) { instance.removeModifier(attributemodifier1); } instance.applyModifier(attributemodifier); } } } }
/** * Sends the entity metadata (DataWatcher) and attributes to all players tracking this entity, including the entity * itself if a player. */ private void sendMetadataToAllAssociatedPlayers() { EntityDataManager entitydatamanager = this.trackedEntity.getDataManager(); if (entitydatamanager.isDirty()) { this.sendToTrackingAndSelf(new SPacketEntityMetadata(this.trackedEntity.getEntityId(), entitydatamanager, false)); } if (this.trackedEntity instanceof EntityLivingBase) { AttributeMap attributemap = (AttributeMap)((EntityLivingBase)this.trackedEntity).getAttributeMap(); Set<IAttributeInstance> set = attributemap.getAttributeInstanceSet(); if (!set.isEmpty()) { this.sendToTrackingAndSelf(new SPacketEntityProperties(this.trackedEntity.getEntityId(), set)); } set.clear(); } }
/** * Set whether this zombie is a child. */ public void setChild(boolean childZombie) { this.getDataWatcher().updateObject(12, Byte.valueOf((byte)(childZombie ? 1 : 0))); if (this.worldObj != null && !this.worldObj.isRemote) { IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed); iattributeinstance.removeModifier(babySpeedBoostModifier); if (childZombie) { iattributeinstance.applyModifier(babySpeedBoostModifier); } } this.setChildSize(childZombie); }
/** * Creates an NBTTagCompound from an AttributeInstance, including its AttributeModifiers */ private static NBTTagCompound writeAttributeInstanceToNBT(IAttributeInstance p_111261_0_) { NBTTagCompound nbttagcompound = new NBTTagCompound(); IAttribute iattribute = p_111261_0_.getAttribute(); nbttagcompound.setString("Name", iattribute.getAttributeUnlocalizedName()); nbttagcompound.setDouble("Base", p_111261_0_.getBaseValue()); Collection<AttributeModifier> collection = p_111261_0_.func_111122_c(); if (collection != null && !collection.isEmpty()) { NBTTagList nbttaglist = new NBTTagList(); for (AttributeModifier attributemodifier : collection) { if (attributemodifier.isSaved()) { nbttaglist.appendTag(writeAttributeModifierToNBT(attributemodifier)); } } nbttagcompound.setTag("Modifiers", nbttaglist); } return nbttagcompound; }
public static void func_151475_a(BaseAttributeMap p_151475_0_, NBTTagList p_151475_1_) { for (int i = 0; i < p_151475_1_.tagCount(); ++i) { NBTTagCompound nbttagcompound = p_151475_1_.getCompoundTagAt(i); IAttributeInstance iattributeinstance = p_151475_0_.getAttributeInstanceByName(nbttagcompound.getString("Name")); if (iattributeinstance != null) { applyModifiersToAttributeInstance(iattributeinstance, nbttagcompound); } else { logger.warn("Ignoring unknown attribute \'" + nbttagcompound.getString("Name") + "\'"); } } }
private static void applyModifiersToAttributeInstance(IAttributeInstance p_111258_0_, NBTTagCompound p_111258_1_) { p_111258_0_.setBaseValue(p_111258_1_.getDouble("Base")); if (p_111258_1_.hasKey("Modifiers", 9)) { NBTTagList nbttaglist = p_111258_1_.getTagList("Modifiers", 10); for (int i = 0; i < nbttaglist.tagCount(); ++i) { AttributeModifier attributemodifier = readAttributeModifierFromNBT(nbttaglist.getCompoundTagAt(i)); if (attributemodifier != null) { AttributeModifier attributemodifier1 = p_111258_0_.getModifier(attributemodifier.getID()); if (attributemodifier1 != null) { p_111258_0_.removeModifier(attributemodifier1); } p_111258_0_.applyModifier(attributemodifier); } } } }
/** * Sends the entity metadata (DataWatcher) and attributes to all players tracking this entity, including the entity * itself if a player. */ private void sendMetadataToAllAssociatedPlayers() { DataWatcher datawatcher = this.trackedEntity.getDataWatcher(); if (datawatcher.hasObjectChanged()) { this.func_151261_b(new S1CPacketEntityMetadata(this.trackedEntity.getEntityId(), datawatcher, false)); } if (this.trackedEntity instanceof EntityLivingBase) { ServersideAttributeMap serversideattributemap = (ServersideAttributeMap)((EntityLivingBase)this.trackedEntity).getAttributeMap(); Set<IAttributeInstance> set = serversideattributemap.getAttributeInstanceSet(); if (!set.isEmpty()) { this.func_151261_b(new S20PacketEntityProperties(this.trackedEntity.getEntityId(), set)); } set.clear(); } }
public static void setAttributeModifiers(AbstractAttributeMap map, NBTTagList list) { for (int i = 0; i < list.tagCount(); ++i) { NBTTagCompound nbttagcompound = list.getCompoundTagAt(i); IAttributeInstance iattributeinstance = map.getAttributeInstanceByName(nbttagcompound.getString("Name")); if (iattributeinstance != null) { applyModifiersToAttributeInstance(iattributeinstance, nbttagcompound); } else { LOGGER.warn("Ignoring unknown attribute \'{}\'", new Object[] {nbttagcompound.getString("Name")}); } } }
public static void setAttributeModifiers(AbstractAttributeMap map, NBTTagList list) { for (int i = 0; i < list.tagCount(); ++i) { NBTTagCompound nbttagcompound = list.getCompoundTagAt(i); IAttributeInstance iattributeinstance = map.getAttributeInstanceByName(nbttagcompound.getString("Name")); if (iattributeinstance == null) { LOGGER.warn("Ignoring unknown attribute \'{}\'", new Object[] {nbttagcompound.getString("Name")}); } else { applyModifiersToAttributeInstance(iattributeinstance, nbttagcompound); } } }
/** * Sets the active target the Task system uses for tracking */ public void setAttackTarget(@Nullable EntityLivingBase entitylivingbaseIn) { super.setAttackTarget(entitylivingbaseIn); IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); if (entitylivingbaseIn == null) { this.targetChangeTime = 0; this.dataManager.set(SCREAMING, Boolean.valueOf(false)); iattributeinstance.removeModifier(ATTACKING_SPEED_BOOST); } else { this.targetChangeTime = this.ticksExisted; this.dataManager.set(SCREAMING, Boolean.valueOf(true)); if (!iattributeinstance.hasModifier(ATTACKING_SPEED_BOOST)) { iattributeinstance.applyModifier(ATTACKING_SPEED_BOOST); } } }
/** * Set whether this zombie is a child. */ public void setChild(boolean childZombie) { this.getDataManager().set(IS_CHILD, Boolean.valueOf(childZombie)); if (this.world != null && !this.world.isRemote) { IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); iattributeinstance.removeModifier(BABY_SPEED_BOOST); if (childZombie) { iattributeinstance.applyModifier(BABY_SPEED_BOOST); } } this.setChildSize(childZombie); }
public void setSprintingGay(boolean sprinting) { SprintEvent event = new SprintEvent(sprinting); event.call(); sprinting = event.sprint; super.setSprinting(sprinting); IAttributeInstance var2 = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed); if (var2.getModifier(sprintingSpeedBoostModifierUUID) != null) { var2.removeModifier(sprintingSpeedBoostModifier); } if (sprinting) { var2.applyModifier(sprintingSpeedBoostModifier); } }
/** * Set sprinting switch for Entity. */ public void setSprinting(boolean sprinting) { super.setSprinting(sprinting); IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed); if (iattributeinstance.getModifier(sprintingSpeedBoostModifierUUID) != null) { iattributeinstance.removeModifier(sprintingSpeedBoostModifier); } if (sprinting) { iattributeinstance.applyModifier(sprintingSpeedBoostModifier); } }
/** * Set sprinting switch for Entity. */ public void setSprinting(boolean sprinting) { super.setSprinting(sprinting); IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); if (iattributeinstance.getModifier(SPRINTING_SPEED_BOOST_ID) != null) { iattributeinstance.removeModifier(SPRINTING_SPEED_BOOST); } if (sprinting) { iattributeinstance.applyModifier(SPRINTING_SPEED_BOOST); } }
@Override public void setAttackTarget(@Nullable EntityLivingBase entitylivingbaseIn) { if (isTamed() && entitylivingbaseIn == getOwner()) { return; } super.setAttackTarget(entitylivingbaseIn); IAttributeInstance iattributeinstance = getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); if (entitylivingbaseIn == null) { dataManager.set(SCREAMING, Boolean.valueOf(false)); iattributeinstance.removeModifier(ATTACKING_SPEED_BOOST); } else { dataManager.set(SCREAMING, Boolean.valueOf(true)); if (isTamed() && isSitting()) { setSitting(false); } if (!iattributeinstance.hasModifier(ATTACKING_SPEED_BOOST)) { iattributeinstance.applyModifier(ATTACKING_SPEED_BOOST); } } }
@Override public void synchronise() { if (entity != null && !entity.getEntityWorld().isRemote) { final IAttributeInstance health = entity.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH); final IAttributeInstance attack = entity.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE); final IAttributeInstance follow = entity.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE); final SPacketEntityProperties packet = new SPacketEntityProperties(entity.getEntityId(), Arrays.asList(new IAttributeInstance[] { health, attack, follow })); ((WorldServer) entity.getEntityWorld()).getEntityTracker().sendToTrackingAndSelf(entity, packet); } }
/** * Updates en entity's attributes and their respective modifiers, which are used for speed bonusses (player * sprinting, animals fleeing, baby speed), weapon/tool attackDamage, hostiles followRange randomization, zombie * maxHealth and knockback resistance as well as reinforcement spawning chance. */ public void handleEntityProperties(SPacketEntityProperties packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); if (entity != null) { if (!(entity instanceof EntityLivingBase)) { throw new IllegalStateException("Server tried to update attributes of a non-living entity (actually: " + entity + ")"); } else { AbstractAttributeMap abstractattributemap = ((EntityLivingBase)entity).getAttributeMap(); for (SPacketEntityProperties.Snapshot spacketentityproperties$snapshot : packetIn.getSnapshots()) { IAttributeInstance iattributeinstance = abstractattributemap.getAttributeInstanceByName(spacketentityproperties$snapshot.getName()); if (iattributeinstance == null) { iattributeinstance = abstractattributemap.registerAttribute(new RangedAttribute((IAttribute)null, spacketentityproperties$snapshot.getName(), 0.0D, 2.2250738585072014E-308D, Double.MAX_VALUE)); } iattributeinstance.setBaseValue(spacketentityproperties$snapshot.getBaseValue()); iattributeinstance.removeAllModifiers(); for (AttributeModifier attributemodifier : spacketentityproperties$snapshot.getModifiers()) { iattributeinstance.applyModifier(attributemodifier); } } } } }
@Override public void onAdd(EntityPlayer player, int slot) { IAttributeInstance attributeHealth = player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH); AttributeModifier modifierHealth = new AttributeModifier(UUID.fromString("d20525ee-98b2-402f-b298-61bc19a9e0c5"), "elementalPendantHealth4", 4, 0).setSaved(true); if(!attributeHealth.hasModifier(modifierHealth)) attributeHealth.applyModifier(modifierHealth); IAttributeInstance attributeArmour = player.getEntityAttribute(SharedMonsterAttributes.ARMOR); AttributeModifier modifierArmour = new AttributeModifier(UUID.fromString("82b79e32-3c85-4132-b121-03807793338c"), "elementalPendantArmour2", 2, 0).setSaved(true); if(!attributeArmour.hasModifier(modifierArmour)) attributeArmour.applyModifier(modifierArmour); }
@Override public void onAdd(EntityPlayer player, int slot) { IAttributeInstance attributeHealth = player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH); AttributeModifier modifierHealth = new AttributeModifier(UUID.fromString("72eb8438-8f2b-11e7-bb31-be2e44b06b34"), "criminalPendantHealth6", 6, 0).setSaved(true); if(!attributeHealth.hasModifier(modifierHealth)) attributeHealth.applyModifier(modifierHealth); }
private void addHealthAction(AttributeMap map) { float m = map.has(ACTION_HEALTHMULTIPLY) ? map.get(ACTION_HEALTHMULTIPLY) : 1; float a = map.has(ACTION_HEALTHADD) ? map.get(ACTION_HEALTHADD) : 0; actions.add(event -> { EntityZombie helper = getHelper(event); IAttributeInstance entityAttribute = helper.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH); if (entityAttribute != null) { double newMax = entityAttribute.getBaseValue() * m + a; entityAttribute.setBaseValue(newMax); helper.setHealth((float) newMax); } }); }
private void addDamageAction(AttributeMap map) { float m = map.has(ACTION_DAMAGEMULTIPLY) ? map.get(ACTION_DAMAGEMULTIPLY) : 1; float a = map.has(ACTION_DAMAGEADD) ? map.get(ACTION_DAMAGEADD) : 0; actions.add(event -> { EntityZombie helper = getHelper(event); IAttributeInstance entityAttribute = helper.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE); if (entityAttribute != null) { double newMax = entityAttribute.getBaseValue() * m + a; entityAttribute.setBaseValue(newMax); } }); }
private void addHealthAction(AttributeMap map) { float m = map.has(ACTION_HEALTHMULTIPLY) ? map.get(ACTION_HEALTHMULTIPLY) : 1; float a = map.has(ACTION_HEALTHADD) ? map.get(ACTION_HEALTHADD) : 0; actions.add(event -> { EntityLivingBase entityLiving = event.getEntityLiving(); if (entityLiving != null) { IAttributeInstance entityAttribute = entityLiving.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH); if (entityAttribute != null) { double newMax = entityAttribute.getBaseValue() * m + a; entityAttribute.setBaseValue(newMax); entityLiving.setHealth((float) newMax); } } }); }
private void addDamageAction(AttributeMap map) { float m = map.has(ACTION_DAMAGEMULTIPLY) ? map.get(ACTION_DAMAGEMULTIPLY) : 1; float a = map.has(ACTION_DAMAGEADD) ? map.get(ACTION_DAMAGEADD) : 0; actions.add(event -> { EntityLivingBase entityLiving = event.getEntityLiving(); if (entityLiving != null) { IAttributeInstance entityAttribute = entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE); if (entityAttribute != null) { double newMax = entityAttribute.getBaseValue() * m + a; entityAttribute.setBaseValue(newMax); } } }); }
public float getFovModifier() { float f = 1.0F; if (this.capabilities.isFlying) { f *= 1.1F; } IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); f = (float)((double)f * ((iattributeinstance.getAttributeValue() / (double)this.capabilities.getWalkSpeed() + 1.0D) / 2.0D)); if (this.capabilities.getWalkSpeed() == 0.0F || Float.isNaN(f) || Float.isInfinite(f)) { f = 1.0F; } if (this.isHandActive() && this.getActiveItemStack().getItem() == Items.BOW) { int i = this.getItemInUseMaxCount(); float f1 = (float)i / 20.0F; if (f1 > 1.0F) { f1 = 1.0F; } else { f1 = f1 * f1; } f *= 1.0F - f1 * 0.15F; } return Reflector.ForgeHooksClient_getOffsetFOV.exists() ? Reflector.callFloat(Reflector.ForgeHooksClient_getOffsetFOV, new Object[] {this, Float.valueOf(f)}): f; }
public void resetTask() { this.player = null; this.enderman.setScreaming(false); IAttributeInstance iattributeinstance = this.enderman.getEntityAttribute(SharedMonsterAttributes.movementSpeed); iattributeinstance.removeModifier(EntityEnderman.attackingSpeedBoostModifier); super.resetTask(); }
public SPacketEntityProperties(int entityIdIn, Collection<IAttributeInstance> instances) { this.entityId = entityIdIn; for (IAttributeInstance iattributeinstance : instances) { this.snapshots.add(new SPacketEntityProperties.Snapshot(iattributeinstance.getAttribute().getAttributeUnlocalizedName(), iattributeinstance.getBaseValue(), iattributeinstance.getModifiers())); } }
/** * Creates an NBTTagList from a BaseAttributeMap, including all its AttributeInstances */ public static NBTTagList writeBaseAttributeMapToNBT(BaseAttributeMap p_111257_0_) { NBTTagList nbttaglist = new NBTTagList(); for (IAttributeInstance iattributeinstance : p_111257_0_.getAllAttributes()) { nbttaglist.appendTag(writeAttributeInstanceToNBT(iattributeinstance)); } return nbttaglist; }
public S20PacketEntityProperties(int entityIdIn, Collection<IAttributeInstance> p_i45236_2_) { this.entityId = entityIdIn; for (IAttributeInstance iattributeinstance : p_i45236_2_) { this.field_149444_b.add(new S20PacketEntityProperties.Snapshot(iattributeinstance.getAttribute().getAttributeUnlocalizedName(), iattributeinstance.getBaseValue(), iattributeinstance.func_111122_c())); } }