use of net.minecraft.entity.ai.attributes.AttributeModifier in project Bewitchment by Um-Mitternacht.
the class BrewUtils method addPotionTooltip.
@SideOnly(Side.CLIENT)
public static void addPotionTooltip(ItemStack itemIn, List<String> tooltip) {
List<PotionEffect> list = PotionUtils.getEffectsFromStack(itemIn);
List<Tuple<String, AttributeModifier>> attributes = Lists.newArrayList();
if (list.isEmpty()) {
tooltip.add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + "---");
} else {
for (PotionEffect effect : list) {
StringBuilder string = new StringBuilder();
string.append(" - ").append(I18n.format(effect.getEffectName()).trim());
Potion potion = effect.getPotion();
Map<IAttribute, AttributeModifier> map = potion.getAttributeModifierMap();
if (!map.isEmpty()) {
for (Map.Entry<IAttribute, AttributeModifier> entry : map.entrySet()) {
AttributeModifier attribute = entry.getValue();
attribute = new AttributeModifier(attribute.getName(), potion.getAttributeModifierAmount(effect.getAmplifier(), attribute), attribute.getOperation());
attributes.add(new Tuple<>(entry.getKey().getName(), attribute));
}
}
if (effect.getAmplifier() > 0) {
string.append(" ").append(RomanNumber.getRoman(effect.getAmplifier()));
}
if (effect.getDuration() > 20) {
string.append(" (").append(Potion.getPotionDurationString(effect, 1.0F)).append(")");
}
if (potion.isBadEffect()) {
tooltip.add(TextFormatting.DARK_RED + string.toString());
} else {
tooltip.add(TextFormatting.DARK_BLUE + string.toString());
}
}
}
if (!attributes.isEmpty()) {
tooltip.add("");
tooltip.add(TextFormatting.DARK_PURPLE + I18n.format("potion.whenDrank"));
for (Tuple<String, AttributeModifier> tuple : attributes) {
AttributeModifier modifier = tuple.getSecond();
double amount = modifier.getAmount();
double newAmount;
if (modifier.getOperation() != 1 && modifier.getOperation() != 2) {
newAmount = modifier.getAmount();
} else {
newAmount = modifier.getAmount() * 100.0D;
}
if (amount > 0.0D) {
tooltip.add(TextFormatting.BLUE + I18n.format("attribute.modifier.plus." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(newAmount), I18n.format("attribute.name." + tuple.getFirst())));
} else if (amount < 0.0D) {
newAmount = newAmount * -1.0D;
tooltip.add(TextFormatting.RED + I18n.format("attribute.modifier.take." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(newAmount), I18n.format("attribute.name." + tuple.getFirst())));
}
}
}
}
use of net.minecraft.entity.ai.attributes.AttributeModifier in project BuildCraft by BuildCraft.
the class EntityRobot method attackTargetEntityWithCurrentItem.
public void attackTargetEntityWithCurrentItem(Entity par1Entity) {
BlockPos entPos = Utils.convertFloor(Utils.getVec(par1Entity));
if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(CoreProxy.proxy.getBuildCraftPlayer((WorldServer) worldObj, entPos).get(), par1Entity))) {
return;
}
if (par1Entity.canAttackWithItem()) {
if (!par1Entity.hitByEntity(this)) {
Multimap<String, AttributeModifier> attributes = itemInUse != null ? (Multimap<String, AttributeModifier>) itemInUse.getAttributeModifiers() : null;
float attackDamage = 2.0F;
int knockback = 0;
if (attributes != null) {
for (AttributeModifier modifier : attributes.get(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName())) {
switch(modifier.getOperation()) {
case 0:
attackDamage += modifier.getAmount();
break;
case 1:
attackDamage *= modifier.getAmount();
break;
case 2:
attackDamage *= 1.0F + modifier.getAmount();
break;
}
}
}
if (par1Entity instanceof EntityLivingBase) {
// FIXME: This was probably meant to do something at some point
// attackDamage += EnchantmentHelper.getEnchantmentModifierDamage(this, (EntityLivingBase)
// par1Entity);
knockback += EnchantmentHelper.getKnockbackModifier(this);
}
if (attackDamage > 0.0F) {
int fireAspect = EnchantmentHelper.getFireAspectModifier(this);
if (par1Entity instanceof EntityLivingBase && fireAspect > 0 && !par1Entity.isBurning()) {
par1Entity.setFire(fireAspect * 4);
}
if (par1Entity.attackEntityFrom(new EntityDamageSource("robot", this), attackDamage)) {
this.setLastAttacker(par1Entity);
if (knockback > 0) {
par1Entity.addVelocity(-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F, 0.1D, MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F);
this.motionX *= 0.6D;
this.motionZ *= 0.6D;
this.setSprinting(false);
}
// FIXME: This was probably meant to do something at some point...
// if (par1Entity instanceof EntityLivingBase) {
// EnchantmentHelper.((EntityLivingBase) par1Entity, this);
// }
//
// EnchantmentHelper.func_151385_b(this, par1Entity);
ItemStack itemstack = itemInUse;
if (itemstack != null && par1Entity instanceof EntityLivingBase) {
itemstack.getItem().hitEntity(itemstack, (EntityLivingBase) par1Entity, this);
}
if (itemInUse.stackSize == 0) {
setItemInUse(null);
}
}
}
}
}
}
use of net.minecraft.entity.ai.attributes.AttributeModifier in project BaseMetals by MinecraftModDevelopmentMods.
the class ItemMMDSickle method getItemAttributeModifiers.
/**
* Gets a map of item attribute modifiers, used by ItemSword to increase hit
* damage.
* @deprecated
*/
@Override
@Deprecated
@SuppressWarnings("unused")
public Multimap<String, AttributeModifier> getItemAttributeModifiers(final EntityEquipmentSlot equipmentSlot) {
final Multimap<String, AttributeModifier> multimap = super.getAttributeModifiers(equipmentSlot, ItemStack.EMPTY);
// XXX: We drop the returns in booleans because it makes findbugs happy, maybe we should do something with them?
if (equipmentSlot == EntityEquipmentSlot.MAINHAND) {
final boolean attackDamageReturned = multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Tool modifier", (double) this.attackDamage, 0));
final boolean attackSpeedReturned = multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Tool modifier", (double) this.attackSpeed, 0));
}
return multimap;
}
use of net.minecraft.entity.ai.attributes.AttributeModifier in project Skree by Skelril.
the class ICustomTool method getItemAttributeModifiers.
/**
* Gets a map of item attribute modifiers, used by ItemSword to increase hit damage.
*/
@SuppressWarnings("unchecked")
default Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) {
Multimap<String, AttributeModifier> multimap = __superGetItemAttributeModifiers(equipmentSlot);
if (equipmentSlot == EntityEquipmentSlot.MAINHAND) {
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Tool modifier", __getHitPower(), 0));
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Tool modifier", __getAttackSpeed(), 0));
}
return multimap;
}
use of net.minecraft.entity.ai.attributes.AttributeModifier in project Skree by Skelril.
the class ICustomSword method getItemAttributeModifiers.
/**
* Gets a map of item attribute modifiers, used by ItemSword to increase hit damage.
*/
@SuppressWarnings("unchecked")
default Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) {
Multimap<String, AttributeModifier> multimap = __superGetItemAttributeModifiers(equipmentSlot);
if (equipmentSlot == EntityEquipmentSlot.MAINHAND) {
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", __getHitPower(), 0));
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", __getAttackSpeed(), 0));
}
return multimap;
}
Aggregations