use of am2.api.items.armor.IArmorImbuement in project ArsMagica2 by Mithion.
the class ArmorEventHandler method doInfusions.
private void doInfusions(ImbuementApplicationTypes type, Event event, EntityPlayer player) {
ExtendedProperties props = ExtendedProperties.For(player);
for (int i = 0; i < 4; ++i) {
IArmorImbuement[] infusions = ArmorHelper.getInfusionsOnArmor(player, i);
int cd = props.armorProcCooldowns[i];
for (IArmorImbuement inf : infusions) {
if (inf == null)
continue;
if (inf.getApplicationTypes().contains(type)) {
if (cd == 0 || inf.canApplyOnCooldown()) {
if (inf.applyEffect(player, player.worldObj, player.getCurrentArmor(i), type, event)) {
if (inf.getCooldown() > 0) {
if (props.armorProcCooldowns[i] < inf.getCooldown()) {
props.armorProcCooldowns[i] = inf.getCooldown();
if (player instanceof EntityPlayerMP)
AMCore.proxy.blackoutArmorPiece((EntityPlayerMP) player, i, inf.getCooldown());
}
}
}
}
}
}
}
}
use of am2.api.items.armor.IArmorImbuement in project ArsMagica2 by Mithion.
the class ArmorHelper method getInfusionsOnArmor.
public static IArmorImbuement[] getInfusionsOnArmor(ItemStack stack) {
if (stack == null || !stack.hasTagCompound() || !(stack.getItem() instanceof ItemArmor))
return new IArmorImbuement[0];
NBTTagCompound armorProps = (NBTTagCompound) stack.stackTagCompound.getTag(AMArmor.NBT_KEY_AMPROPS);
if (armorProps != null) {
String infusionList = armorProps.getString(AMArmor.NBT_KEY_EFFECTS);
if (infusionList != null && infusionList != "") {
String[] ids = infusionList.split(AMArmor.INFUSION_DELIMITER);
IArmorImbuement[] infusions = new IArmorImbuement[ids.length];
for (int i = 0; i < ids.length; ++i) {
infusions[i] = ImbuementRegistry.instance.getImbuementByID(ids[i]);
}
return infusions;
}
}
return new IArmorImbuement[0];
}
use of am2.api.items.armor.IArmorImbuement in project ArsMagica2 by Mithion.
the class GuiArmorImbuer method drawGuiContainerBackgroundLayer.
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
int l = (width - xSize) / 2;
int i1 = (height - ySize) / 2;
ItemStack stack = tileEntity.getStackInSlot(0);
int startX = l + 22;
int stepX = 52;
int startY = i1 + 23;
int stepY = 45;
int drawX = startX;
int drawY = startY;
ArrayList<String> hoverLines = new ArrayList<String>();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
GL11.glColor3f(0, 0, 0);
drawTexturedModalRect(l, i1, 0, 0, xSize, ySize);
GL11.glColor3f(1, 1, 1);
hoveredID = null;
if (stack != null) {
int armorType = -1;
if (stack.getItem() instanceof ItemArmor) {
armorType = ((ItemArmor) stack.getItem()).armorType;
}
mc.renderEngine.bindTexture(background_bw);
for (ImbuementTiers tier : ImbuementTiers.values()) {
IArmorImbuement[] infusions = ImbuementRegistry.instance.getImbuementsForTier(tier, armorType);
for (IArmorImbuement infusion : infusions) {
drawInfusionIconAt(drawX, drawY, infusion.getIconIndex());
if (i >= drawX && i <= drawX + spriteWidth) {
if (j >= drawY && j <= drawY + spriteHeight) {
hoverLines.add(StatCollector.translateToLocal("am2.tooltip." + infusion.getID()));
}
}
drawX += stepX;
}
drawY += stepY;
drawX = startX;
}
drawX = startX;
drawY = startY;
int highestSelectedTier = 0;
mc.renderEngine.bindTexture(background);
for (ImbuementTiers tier : ImbuementTiers.values()) {
IArmorImbuement[] infusions = ImbuementRegistry.instance.getImbuementsForTier(tier, armorType);
IArmorImbuement[] existingInfusions = ArmorHelper.getInfusionsOnArmor(stack);
IArmorImbuement tierInfusion = null;
for (IArmorImbuement infusion : existingInfusions) {
if (infusion == null)
continue;
if (infusion.getTier() == tier) {
tierInfusion = infusion;
if (tier.ordinal() >= highestSelectedTier)
highestSelectedTier = tier.ordinal() + 1;
break;
}
}
for (IArmorImbuement infusion : infusions) {
if ((tierInfusion == null && infusion.getTier().ordinal() <= highestSelectedTier)) {
if (tileEntity.isCreativeAllowed() || ArmorHelper.getArmorLevel(stack) >= ArmorHelper.getImbueCost(tier)) {
drawInfusionIconAt(drawX, drawY, infusion.getIconIndex());
if (i >= drawX && i <= drawX + spriteWidth) {
if (j >= drawY && j <= drawY + spriteHeight) {
hoveredID = infusion.getID();
}
}
}
} else if (tierInfusion == infusion) {
drawInfusionIconAt(drawX, drawY, infusion.getIconIndex());
}
drawX += stepX;
}
drawY += stepY;
drawX = startX;
}
}
mc.renderEngine.bindTexture(foreground);
drawTexturedModalRect(l, i1, 0, 0, xSize, ySize);
if (hoverLines.size() > 0)
AMGuiHelper.instance.drawHoveringText(hoverLines, i, j, fontRendererObj, width, height);
}
use of am2.api.items.armor.IArmorImbuement in project ArsMagica2 by Mithion.
the class ArmorHelper method imbueArmor.
public static void imbueArmor(ItemStack armorStack, String id, boolean ignoreLevelRequirement) {
IArmorImbuement imbuement = ImbuementRegistry.instance.getImbuementByID(id);
if (armorStack != null && imbuement != null && armorStack.getItem() instanceof ItemArmor) {
if (!ignoreLevelRequirement && getArmorLevel(armorStack) < getImbueCost(imbuement.getTier()))
return;
for (int i : imbuement.getValidSlots()) {
if (i == ((ItemArmor) armorStack.getItem()).armorType) {
if (!armorStack.hasTagCompound())
armorStack.setTagCompound(new NBTTagCompound());
NBTTagCompound armorProps = (NBTTagCompound) armorStack.stackTagCompound.getTag(AMArmor.NBT_KEY_AMPROPS);
if (armorProps == null)
armorProps = new NBTTagCompound();
String infusionList = armorProps.getString(AMArmor.NBT_KEY_EFFECTS);
if (infusionList == null || infusionList == "")
infusionList = id;
else
infusionList += "|" + id;
armorProps.setString(AMArmor.NBT_KEY_EFFECTS, infusionList);
armorStack.stackTagCompound.setTag(AMArmor.NBT_KEY_AMPROPS, armorProps);
deductXPFromArmor(EntityUtilities.getXPFromLevel(getImbueCost(imbuement.getTier())), armorStack);
break;
}
}
}
}
Aggregations