Search in sources :

Example 1 with Upgrade

use of mekanism.api.Upgrade in project Mekanism by mekanism.

the class GuiSupportedUpgrades method renderToolTip.

@Override
public void renderToolTip(@Nonnull MatrixStack matrix, int mouseX, int mouseY) {
    super.renderToolTip(matrix, mouseX, mouseY);
    for (int i = 0; i < EnumUtils.UPGRADES.length; i++) {
        UpgradePos pos = getUpgradePos(i);
        if (mouseX >= relativeX + 1 + pos.x && mouseX < relativeX + 1 + pos.x + ELEMENT_SIZE && mouseY >= relativeY + 1 + pos.y && mouseY < relativeY + 1 + pos.y + ELEMENT_SIZE) {
            Upgrade upgrade = EnumUtils.UPGRADES[i];
            ITextComponent upgradeName = MekanismLang.UPGRADE_TYPE.translateColored(EnumColor.YELLOW, upgrade);
            List<ITextComponent> tooltip;
            if (supportedUpgrades.contains(upgrade)) {
                tooltip = Arrays.asList(upgradeName, upgrade.getDescription());
            } else {
                tooltip = Arrays.asList(MekanismLang.UPGRADE_NOT_SUPPORTED.translateColored(EnumColor.RED, upgradeName), upgrade.getDescription());
            }
            displayTooltips(matrix, tooltip, mouseX, mouseY, getGuiWidth());
            // We can break once we managed to find a tooltip to render
            break;
        }
    }
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) Upgrade(mekanism.api.Upgrade)

Example 2 with Upgrade

use of mekanism.api.Upgrade in project Mekanism by mekanism.

the class TileComponentUpgrade method read.

@Override
public void read(CompoundNBT nbtTags) {
    if (nbtTags.contains(NBTConstants.COMPONENT_UPGRADE, NBT.TAG_COMPOUND)) {
        CompoundNBT upgradeNBT = nbtTags.getCompound(NBTConstants.COMPONENT_UPGRADE);
        upgrades = Upgrade.buildMap(upgradeNBT);
        for (Upgrade upgrade : getSupportedTypes()) {
            tile.recalculateUpgrades(upgrade);
        }
        // Load the inventory
        NBTUtils.setListIfPresent(upgradeNBT, NBTConstants.ITEMS, NBT.TAG_COMPOUND, list -> DataHandlerUtils.readContainers(getSlots(), list));
        // TODO - 1.18: Remove this, it is the legacy way of loading
        NBTUtils.setCompoundIfPresent(upgradeNBT, NBTConstants.SLOT, upgradeSlot::deserializeNBT);
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) Upgrade(mekanism.api.Upgrade)

Example 3 with Upgrade

use of mekanism.api.Upgrade in project Mekanism by mekanism.

the class UpgradesRecipeData method applyToStack.

@Override
public boolean applyToStack(ItemStack stack) {
    if (upgrades.isEmpty()) {
        return true;
    }
    Set<Upgrade> supportedUpgrades = Attribute.get(((BlockItem) stack.getItem()).getBlock(), AttributeUpgradeSupport.class).getSupportedUpgrades();
    for (Upgrade upgrade : upgrades.keySet()) {
        if (!supportedUpgrades.contains(upgrade)) {
            return false;
        }
    }
    // Only transfer upgrades if we were able to find any
    CompoundNBT nbt = new CompoundNBT();
    Upgrade.saveMap(upgrades, nbt);
    ItemDataUtils.setCompound(stack, NBTConstants.COMPONENT_UPGRADE, nbt);
    return true;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) Upgrade(mekanism.api.Upgrade) BlockItem(net.minecraft.item.BlockItem) AttributeUpgradeSupport(mekanism.common.block.attribute.AttributeUpgradeSupport)

Example 4 with Upgrade

use of mekanism.api.Upgrade in project Mekanism by mekanism.

the class GuiUpgradeWindow method renderForeground.

@Override
public void renderForeground(MatrixStack matrix, int mouseX, int mouseY) {
    super.renderForeground(matrix, mouseX, mouseY);
    drawTitleText(matrix, MekanismLang.UPGRADES.translate(), 5);
    if (scrollList.hasSelection()) {
        Upgrade selectedType = scrollList.getSelection();
        int amount = tile.getComponent().getUpgrades(selectedType);
        int textY = relativeY + 20;
        WrappedTextRenderer textRenderer = upgradeTypeData.computeIfAbsent(selectedType, type -> new WrappedTextRenderer(this, MekanismLang.UPGRADE_TYPE.translate(type)));
        int lines = textRenderer.renderWithScale(matrix, relativeX + 74, textY, screenTextColor(), 56, 0.6F);
        textY += 6 * lines + 2;
        drawTextWithScale(matrix, MekanismLang.UPGRADE_COUNT.translate(amount, selectedType.getMax()), relativeX + 74, textY, screenTextColor(), 0.6F);
        for (ITextComponent component : UpgradeUtils.getInfo(tile, selectedType)) {
            // Note: We add the six here instead of after to account for the line above this for loop that draws the upgrade count
            textY += 6;
            drawTextWithScale(matrix, component, relativeX + 74, textY, screenTextColor(), 0.6F);
        }
    } else {
        noSelection.renderWithScale(matrix, relativeX + 74, relativeY + 20, screenTextColor(), 56, 0.8F);
    }
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) Upgrade(mekanism.api.Upgrade)

Example 5 with Upgrade

use of mekanism.api.Upgrade in project Mekanism by mekanism.

the class GuiSupportedUpgrades method drawBackground.

@Override
public void drawBackground(@Nonnull MatrixStack matrix, int mouseX, int mouseY, float partialTicks) {
    super.drawBackground(matrix, mouseX, mouseY, partialTicks);
    // Draw the background
    renderBackgroundTexture(matrix, GuiElementHolder.HOLDER, GuiElementHolder.HOLDER_SIZE, GuiElementHolder.HOLDER_SIZE);
    int backgroundColor = Color.argb(GuiElementHolder.getBackgroundColor()).alpha(0.5).argb();
    for (int i = 0; i < EnumUtils.UPGRADES.length; i++) {
        Upgrade upgrade = EnumUtils.UPGRADES[i];
        UpgradePos pos = getUpgradePos(i);
        int xPos = x + 1 + pos.x;
        int yPos = y + 1 + pos.y;
        gui().renderItem(matrix, UpgradeUtils.getStack(upgrade), xPos, yPos, 0.75F);
        if (!supportedUpgrades.contains(upgrade)) {
            // Make the upgrade appear faded if it is not supported
            RenderSystem.depthFunc(GL11.GL_GREATER);
            AbstractGui.fill(matrix, xPos, yPos, xPos + ELEMENT_SIZE, yPos + ELEMENT_SIZE, backgroundColor);
            RenderSystem.depthFunc(GL11.GL_LEQUAL);
        }
    }
}
Also used : Upgrade(mekanism.api.Upgrade)

Aggregations

Upgrade (mekanism.api.Upgrade)9 ItemStack (net.minecraft.item.ItemStack)3 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 IUpgradeItem (mekanism.common.item.interfaces.IUpgradeItem)2 TileComponentUpgrade (mekanism.common.tile.component.TileComponentUpgrade)2 ITextComponent (net.minecraft.util.text.ITextComponent)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 EnumMap (java.util.EnumMap)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Nonnull (javax.annotation.Nonnull)1 Action (mekanism.api.Action)1 DataHandlerUtils (mekanism.api.DataHandlerUtils)1 NBTConstants (mekanism.api.NBTConstants)1 AutomationType (mekanism.api.inventory.AutomationType)1 IInventorySlot (mekanism.api.inventory.IInventorySlot)1 AttributeUpgradeSupport (mekanism.common.block.attribute.AttributeUpgradeSupport)1