Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheXFactor117/3c8887f0ab369234fb667a51d52f2fc0 to your computer and use it in GitHub Desktop.
Save TheXFactor117/3c8887f0ab369234fb667a51d52f2fc0 to your computer and use it in GitHub Desktop.
// retrieves the default attributes, like damage and attack speed.
Multimap<String, AttributeModifier> map = stack.getAttributeModifiers(EntityEquipmentSlot.MAINHAND);
Collection<AttributeModifier> damageCollection = map.get(SharedMonsterAttributes.ATTACK_DAMAGE.getName());
Collection<AttributeModifier> speedCollection = map.get(SharedMonsterAttributes.ATTACK_SPEED.getName());
AttributeModifier damageModifier = (AttributeModifier) damageCollection.toArray()[0];
AttributeModifier speedModifier = (AttributeModifier) speedCollection.toArray()[0];
double baseDamage = damageModifier.getAmount() + 1; // add one to base damage for player strength
double baseSpeed = speedModifier.getAmount();
double damage = getWeightedDamage(Rarity.getRarity(nbt), baseDamage);
double speed = getWeightedAttackSpeed(Rarity.getRarity(nbt), baseSpeed);
AugmentedWeaponry.LOGGER.info("Base Speed: " + baseSpeed);
AugmentedWeaponry.LOGGER.info("Speed: " + speed);
AugmentedWeaponry.LOGGER.info("Rarity: " + Rarity.getRarity(nbt));
// Creates new AttributeModifier's and applies them to the stack's NBT tag compound.
AttributeModifier attackDamage = new AttributeModifier(ATTACK_DAMAGE, "attackDamage", damage, 0);
AttributeModifier attackSpeed = new AttributeModifier(ATTACK_SPEED, "attackSpeed", baseSpeed, 0);
NBTTagCompound damageNbt = writeAttributeModifierToNBT(SharedMonsterAttributes.ATTACK_DAMAGE, attackDamage, EntityEquipmentSlot.MAINHAND);
NBTTagCompound speedNbt = writeAttributeModifierToNBT(SharedMonsterAttributes.ATTACK_SPEED, attackSpeed, EntityEquipmentSlot.MAINHAND);
NBTTagList list = new NBTTagList();
list.appendTag(damageNbt);
list.appendTag(speedNbt);
nbt.setTag("AttributeModifiers", list);
NBTHelper.saveStackNBT(stack, nbt);
==========================================================
private static NBTTagCompound writeAttributeModifierToNBT(IAttribute attribute, AttributeModifier modifier, EntityEquipmentSlot slot)
{
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("AttributeName", attribute.getName());
nbt.setString("Name", modifier.getName());
nbt.setString("Slot", slot.getName());
nbt.setDouble("Amount", modifier.getAmount());
nbt.setInteger("Operation", modifier.getOperation());
nbt.setLong("UUIDMost", modifier.getID().getMostSignificantBits());
nbt.setLong("UUIDLeast", modifier.getID().getLeastSignificantBits());
return nbt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment