use of net.minecraft.item.ItemArmor in project SilentGems by SilentChaos512.
the class EquipmentTooltips method getToughness.
private float getToughness(ItemStack stack, float defaultValue) {
if (StackHelper.isEmpty(stack))
return defaultValue;
ItemArmor itemArmor = (ItemArmor) stack.getItem();
EntityEquipmentSlot slot = itemArmor.armorType;
UUID uuid = ItemArmor.ARMOR_MODIFIERS[slot.getIndex()];
Multimap<String, AttributeModifier> multimap = stack.getAttributeModifiers(slot);
for (Entry<String, AttributeModifier> entry : multimap.entries()) {
String key = entry.getKey();
AttributeModifier mod = entry.getValue();
if (key.equals(SharedMonsterAttributes.ARMOR_TOUGHNESS.getName()) && mod.getID().equals(uuid)) {
return (float) mod.getAmount();
}
}
return 0f;
}
use of net.minecraft.item.ItemArmor in project SilentGems by SilentChaos512.
the class EquipmentTooltips method onRenderTooltip.
@SubscribeEvent
public void onRenderTooltip(RenderTooltipEvent.PostText event) {
ItemStack stack = event.getStack();
Item item = stack.getItem();
boolean isTinkersHarvestTool = isTinkersLoaded && item instanceof slimeknights.tconstruct.library.tools.AoeToolCore;
boolean isTinkersWeapon = isTinkersLoaded && item instanceof slimeknights.tconstruct.library.tools.SwordCore;
boolean isTinkersBow = isTinkersLoaded && item instanceof slimeknights.tconstruct.library.tools.ranged.BowCore;
// Tools (pickaxes, shovels, axes, and more)
if (item instanceof ItemTool || item instanceof ItemHoe || item instanceof ItemShears || item instanceof ItemFishingRod || isTinkersHarvestTool) {
renderBackground(event);
renderForTool(event, stack);
} else // Swords
if (item instanceof ItemSword || isTinkersWeapon) {
boolean isCaster = item instanceof ITool && ToolHelper.getToolTier(stack).ordinal() >= EnumMaterialTier.SUPER.ordinal();
renderBackground(event);
renderForWeapon(event, stack);
} else // Bows
if (item instanceof ItemBow || isTinkersBow) {
renderBackground(event);
renderForBow(event, stack);
} else // Shields
if (item instanceof ItemShield) {
renderBackground(event);
renderForShield(event, stack);
} else // Armor
if (item instanceof ItemArmor) {
renderBackground(event);
renderForArmor(event, stack);
}
// Unknown
}
use of net.minecraft.item.ItemArmor in project SilentGems by SilentChaos512.
the class EquipmentTooltips method getProtection.
private float getProtection(ItemStack stack, float defaultValue) {
if (StackHelper.isEmpty(stack))
return defaultValue;
ItemArmor itemArmor = (ItemArmor) stack.getItem();
EntityEquipmentSlot slot = itemArmor.armorType;
UUID uuid = ItemArmor.ARMOR_MODIFIERS[slot.getIndex()];
Multimap<String, AttributeModifier> multimap = stack.getAttributeModifiers(slot);
for (Entry<String, AttributeModifier> entry : multimap.entries()) {
String key = entry.getKey();
AttributeModifier mod = entry.getValue();
if (key.equals(SharedMonsterAttributes.ARMOR.getName()) && mod.getID().equals(uuid)) {
return (float) mod.getAmount();
}
}
return 0f;
}
use of net.minecraft.item.ItemArmor in project SpongeCommon by SpongePowered.
the class DamageEventHandler method createArmorModifiers.
public static Optional<List<DamageFunction>> createArmorModifiers(EntityLivingBase entityLivingBase, DamageSource damageSource, double damage) {
if (!damageSource.isUnblockable()) {
damage *= 25;
net.minecraft.item.ItemStack[] inventory = Iterables.toArray(entityLivingBase.getArmorInventoryList(), net.minecraft.item.ItemStack.class);
List<DamageFunction> modifiers = new ArrayList<>();
List<DamageObject> damageObjects = new ArrayList<>();
for (int index = 0; index < inventory.length; index++) {
net.minecraft.item.ItemStack itemStack = inventory[index];
if (itemStack.isEmpty()) {
continue;
}
Item item = itemStack.getItem();
if (item instanceof ItemArmor) {
ItemArmor armor = (ItemArmor) item;
double reduction = armor.damageReduceAmount / 25D;
DamageObject object = new DamageObject();
object.slot = index;
object.ratio = reduction;
damageObjects.add(object);
}
}
boolean first = true;
double ratio = 0;
for (DamageObject prop : damageObjects) {
EquipmentType type = resolveEquipment(prop.slot);
final DamageObject object = new DamageObject();
object.ratio = ratio;
if (first) {
object.previousDamage = damage;
object.augment = true;
}
DoubleUnaryOperator function = incomingDamage -> {
incomingDamage *= 25;
if (object.augment) {
// This is the damage that needs to be archived for the "first" armor modifier
// function since the armor modifiers work based on the initial damage and not as
// a chain one after another.
damageToHandle = incomingDamage;
}
double functionDamage = damageToHandle;
object.previousDamage = functionDamage;
object.ratio = prop.ratio;
object.ratio += prop.ratio;
return -((functionDamage * prop.ratio) / 25);
};
ratio += prop.ratio;
// TODO: direct cause creation: bad bad bad
DamageModifier modifier = DamageModifier.builder().cause(Cause.of(EventContext.empty(), ((org.spongepowered.api.item.inventory.ItemStack) inventory[prop.slot]).createSnapshot(), // We need this property to refer to the slot.
prop, // We need this object later on.
object)).type(DamageModifierTypes.ARMOR).build();
modifiers.add(new DamageFunction(modifier, function));
first = false;
}
if (!modifiers.isEmpty()) {
return Optional.of(modifiers);
}
}
return Optional.empty();
}
use of net.minecraft.item.ItemArmor in project SpongeCommon by SpongePowered.
the class DamageAbsorptionPropertyStore method getFor.
@Override
protected Optional<DamageAbsorptionProperty> getFor(ItemStack itemStack) {
if (itemStack.getItem() instanceof ItemArmor) {
final ItemArmor armor = (ItemArmor) itemStack.getItem();
final int reduction = armor.damageReduceAmount;
return Optional.of(new DamageAbsorptionProperty(reduction));
}
return Optional.empty();
}
Aggregations