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;
}
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
}
Aggregations