Search in sources :

Example 11 with ItemArmor

use of net.minecraft.item.ItemArmor in project PneumaticCraft by MineMaarten.

the class TileEntityAerialInterface method canInsertItem.

@Override
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
    if (i < 4)
        return true;
    EntityPlayer player = getPlayer();
    if (player == null)
        return false;
    if (getPressure(ForgeDirection.UNKNOWN) > PneumaticValues.MIN_PRESSURE_AERIAL_INTERFACE) {
        if (!dispenserUpgradeInserted || i >= 40 && i <= 43) {
            return i < 40 || itemstack != null && itemstack.getItem() instanceof ItemArmor && ((ItemArmor) itemstack.getItem()).armorType == 43 - i;
        } else {
            if (i == 4 + player.inventory.getSizeInventory() && getFoodValue(itemstack) > 0) {
                int foodValue = getFoodValue(itemstack);
                int curFoodLevel = player.getFoodStats().getFoodLevel();
                int feedMode = this.feedMode;
                if (feedMode == 2) {
                    feedMode = player.getMaxHealth() - player.getHealth() > 0 ? 1 : 0;
                }
                switch(feedMode) {
                    case 0:
                        return 20 - curFoodLevel >= foodValue * itemstack.stackSize;
                    case 1:
                        return 20 - curFoodLevel >= foodValue * (itemstack.stackSize - 1) + 1;
                }
            }
            return false;
        }
    } else {
        return false;
    }
}
Also used : ItemArmor(net.minecraft.item.ItemArmor) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 12 with ItemArmor

use of net.minecraft.item.ItemArmor 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];
}
Also used : ItemArmor(net.minecraft.item.ItemArmor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IArmorImbuement(am2.api.items.armor.IArmorImbuement)

Example 13 with ItemArmor

use of net.minecraft.item.ItemArmor in project ArsMagica2 by Mithion.

the class ArmorHelper method deductXPFromArmor.

public static void deductXPFromArmor(float amt, ItemStack armor) {
    if (armor != null && armor.getItem() instanceof ItemArmor) {
        if (!armor.hasTagCompound())
            armor.setTagCompound(new NBTTagCompound());
        NBTTagCompound armorProps = (NBTTagCompound) armor.stackTagCompound.getTag(AMArmor.NBT_KEY_AMPROPS);
        if (armorProps == null)
            armorProps = new NBTTagCompound();
        armorProps.setDouble(AMArmor.NBT_KEY_TOTALXP, Math.max(armorProps.getDouble(AMArmor.NBT_KEY_TOTALXP) - amt, 0));
        armorProps.setInteger(AMArmor.NBT_KEY_ARMORLEVEL, EntityUtilities.getLevelFromXP((float) armorProps.getDouble(AMArmor.NBT_KEY_TOTALXP)));
        armor.stackTagCompound.setTag(AMArmor.NBT_KEY_AMPROPS, armorProps);
    }
}
Also used : ItemArmor(net.minecraft.item.ItemArmor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 14 with ItemArmor

use of net.minecraft.item.ItemArmor 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);
}
Also used : ImbuementTiers(am2.api.items.armor.ImbuementTiers) ItemArmor(net.minecraft.item.ItemArmor) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IArmorImbuement(am2.api.items.armor.IArmorImbuement)

Example 15 with ItemArmor

use of net.minecraft.item.ItemArmor in project ArsMagica2 by Mithion.

the class AMClientEventHandler method onItemTooltip.

@SubscribeEvent
public void onItemTooltip(ItemTooltipEvent event) {
    ItemStack stack = event.itemStack;
    if (stack != null && stack.getItem() instanceof ItemArmor) {
        double xp = 0;
        int armorLevel = 0;
        String[] effects = new String[0];
        if (stack.hasTagCompound()) {
            NBTTagCompound armorCompound = (NBTTagCompound) stack.stackTagCompound.getTag(AMArmor.NBT_KEY_AMPROPS);
            if (armorCompound != null) {
                xp = armorCompound.getDouble(AMArmor.NBT_KEY_TOTALXP);
                armorLevel = armorCompound.getInteger(AMArmor.NBT_KEY_ARMORLEVEL);
                String effectsList = armorCompound.getString(AMArmor.NBT_KEY_EFFECTS);
                if (effectsList != null && effectsList != "") {
                    effects = effectsList.split(AMArmor.INFUSION_DELIMITER);
                }
            }
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
            event.toolTip.add(StatCollector.translateToLocalFormatted("am2.tooltip.armorxp", String.format("%.2f", xp)));
            event.toolTip.add(String.format(StatCollector.translateToLocal("am2.tooltip.armorlevel"), armorLevel));
            for (String s : effects) {
                event.toolTip.add(StatCollector.translateToLocal("am2.tooltip." + s));
            }
        } else {
            event.toolTip.add(StatCollector.translateToLocal("am2.tooltip.shiftForDetails"));
        }
    } else if (stack.getItem() instanceof ItemBlock) {
        if (((ItemBlock) stack.getItem()).field_150939_a == BlocksCommonProxy.manaBattery) {
            if (stack.hasTagCompound()) {
                float batteryCharge = stack.stackTagCompound.getFloat("mana_battery_charge");
                PowerTypes powerType = PowerTypes.getByID(stack.stackTagCompound.getInteger("mana_battery_powertype"));
                if (batteryCharge != 0) {
                    // TODO localize this tooltip
                    event.toolTip.add(String.format("\u00A7r\u00A79Contains \u00A75%.2f %s%s \u00A79etherium", batteryCharge, powerType.chatColor(), powerType.name()));
                }
            }
        }
    }
}
Also used : PowerTypes(am2.api.power.PowerTypes) ItemArmor(net.minecraft.item.ItemArmor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

ItemArmor (net.minecraft.item.ItemArmor)45 ItemStack (net.minecraft.item.ItemStack)27 Item (net.minecraft.item.Item)12 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 ModelBiped (net.minecraft.client.model.ModelBiped)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 Color (java.awt.Color)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)4 IArmorImbuement (am2.api.items.armor.IArmorImbuement)3 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)3 Slot (net.minecraft.inventory.Slot)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 Minecraft (net.minecraft.client.Minecraft)2 TextureManager (net.minecraft.client.renderer.texture.TextureManager)2 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)2 ItemBlock (net.minecraft.item.ItemBlock)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2