Search in sources :

Example 1 with ILangEntry

use of mekanism.api.text.ILangEntry in project Mekanism by mekanism.

the class GuiDigitalMiner method addGuiElements.

@Override
protected void addGuiElements() {
    super.addGuiElements();
    addButton(new GuiInnerScreen(this, 7, 19, 77, 69, () -> {
        List<ITextComponent> list = new ArrayList<>();
        ILangEntry runningType;
        if (tile.getEnergyContainer().getEnergyPerTick().greaterThan(tile.getEnergyContainer().getMaxEnergy())) {
            runningType = MekanismLang.MINER_LOW_POWER;
        } else if (tile.isRunning()) {
            runningType = MekanismLang.MINER_RUNNING;
        } else {
            runningType = MekanismLang.IDLE;
        }
        list.add(runningType.translate());
        list.add(tile.searcher.state.getTextComponent());
        list.add(MekanismLang.MINER_TO_MINE.translate(TextUtils.format(tile.getToMine())));
        return list;
    }).spacing(1).clearFormat());
    addButton(new GuiDigitalSwitch(this, 19, 56, EJECT, tile::getDoEject, MekanismLang.AUTO_EJECT.translate(), () -> Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.AUTO_EJECT_BUTTON, tile)), SwitchType.LOWER_ICON));
    addButton(new GuiDigitalSwitch(this, 38, 56, INPUT, tile::getDoPull, MekanismLang.AUTO_PULL.translate(), () -> Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.AUTO_PULL_BUTTON, tile)), SwitchType.LOWER_ICON));
    addButton(new GuiDigitalSwitch(this, 57, 56, SILK, tile::getSilkTouch, MekanismLang.MINER_SILK.translate(), () -> Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.SILK_TOUCH_BUTTON, tile)), SwitchType.LOWER_ICON));
    addButton(new GuiVerticalPowerBar(this, tile.getEnergyContainer(), 157, 39, 47));
    addButton(new GuiVisualsTab(this, tile));
    addButton(new GuiSlot(SlotType.DIGITAL, this, 64, 21).setRenderAboveSlots().validity(() -> tile.missingStack).with(() -> tile.missingStack.isEmpty() ? SlotOverlay.CHECK : null).hover(getOnHover(() -> tile.missingStack.isEmpty() ? MekanismLang.MINER_WELL.translate() : MekanismLang.MINER_MISSING_BLOCK.translate())));
    addButton(new GuiEnergyTab(this, () -> {
        MinerEnergyContainer energyContainer = tile.getEnergyContainer();
        FloatingLong perTick = energyContainer.getEnergyPerTick();
        ArrayList<ITextComponent> ret = new ArrayList<>(4);
        ret.add(MekanismLang.MINER_ENERGY_CAPACITY.translate(EnergyDisplay.of(energyContainer.getMaxEnergy())));
        ret.add(MekanismLang.NEEDED_PER_TICK.translate(EnergyDisplay.of(perTick)));
        if (perTick.greaterThan(energyContainer.getMaxEnergy())) {
            ret.add(MekanismLang.MINER_INSUFFICIENT_BUFFER.translateColored(EnumColor.RED));
        }
        ret.add(MekanismLang.MINER_BUFFER_FREE.translate(EnergyDisplay.of(energyContainer.getNeeded())));
        return ret;
    }));
    int buttonStart = 19;
    startButton = addButton(new TranslationButton(this, 87, buttonStart, 61, 18, MekanismLang.BUTTON_START, () -> Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.START_BUTTON, tile))));
    stopButton = addButton(new TranslationButton(this, 87, buttonStart + 17, 61, 18, MekanismLang.BUTTON_STOP, () -> Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.STOP_BUTTON, tile))));
    configButton = addButton(new TranslationButton(this, 87, buttonStart + 34, 61, 18, MekanismLang.BUTTON_CONFIG, () -> Mekanism.packetHandler.sendToServer(new PacketGuiButtonPress(ClickedTileButton.DIGITAL_MINER_CONFIG, tile))));
    addButton(new TranslationButton(this, 87, buttonStart + 51, 61, 18, MekanismLang.MINER_RESET, () -> Mekanism.packetHandler.sendToServer(new PacketGuiInteract(GuiInteraction.RESET_BUTTON, tile))));
    updateEnabledButtons();
    trackWarning(WarningType.FILTER_HAS_BLACKLISTED_ELEMENT, () -> tile.getFilters().stream().anyMatch(MinerFilter::hasBlacklistedElement));
}
Also used : PacketGuiButtonPress(mekanism.common.network.to_server.PacketGuiButtonPress) TranslationButton(mekanism.client.gui.element.button.TranslationButton) GuiDigitalSwitch(mekanism.client.gui.element.GuiDigitalSwitch) ArrayList(java.util.ArrayList) GuiSlot(mekanism.client.gui.element.slot.GuiSlot) PacketGuiInteract(mekanism.common.network.to_server.PacketGuiInteract) GuiVerticalPowerBar(mekanism.client.gui.element.bar.GuiVerticalPowerBar) GuiEnergyTab(mekanism.client.gui.element.tab.GuiEnergyTab) GuiInnerScreen(mekanism.client.gui.element.GuiInnerScreen) FloatingLong(mekanism.api.math.FloatingLong) MinerEnergyContainer(mekanism.common.capabilities.energy.MinerEnergyContainer) ArrayList(java.util.ArrayList) List(java.util.List) GuiVisualsTab(mekanism.client.gui.element.tab.GuiVisualsTab) ILangEntry(mekanism.api.text.ILangEntry)

Example 2 with ILangEntry

use of mekanism.api.text.ILangEntry in project Mekanism by mekanism.

the class GuiWindGenerator method addGuiElements.

@Override
protected void addGuiElements() {
    super.addGuiElements();
    addButton(new GuiInnerScreen(this, 48, 21, 80, 44, () -> {
        List<ITextComponent> list = new ArrayList<>();
        list.add(EnergyDisplay.of(tile.getEnergyContainer()).getTextComponent());
        list.add(GeneratorsLang.POWER.translate(MekanismUtils.convertToDisplay(MekanismGeneratorsConfig.generators.windGenerationMin.get().multiply(tile.getCurrentMultiplier())).toString(2)));
        list.add(GeneratorsLang.OUTPUT_RATE_SHORT.translate(EnergyDisplay.of(tile.getMaxOutput())));
        if (!tile.getActive()) {
            ILangEntry reason = tile.isBlacklistDimension() ? GeneratorsLang.NO_WIND : GeneratorsLang.SKY_BLOCKED;
            list.add(reason.translateColored(EnumColor.DARK_RED));
        }
        return list;
    }));
    addButton(new GuiEnergyTab(this, () -> Arrays.asList(GeneratorsLang.PRODUCING_AMOUNT.translate(tile.getActive() ? EnergyDisplay.of(MekanismGeneratorsConfig.generators.windGenerationMin.get().multiply(tile.getCurrentMultiplier())) : EnergyDisplay.ZERO), MekanismLang.MAX_OUTPUT.translate(EnergyDisplay.of(tile.getMaxOutput())))));
    addButton(new GuiVerticalPowerBar(this, tile.getEnergyContainer(), 164, 15));
    addButton(new GuiStateTexture(this, 18, 35, tile::getActive, MekanismGenerators.rl(ResourceType.GUI.getPrefix() + "wind_on.png"), MekanismGenerators.rl(ResourceType.GUI.getPrefix() + "wind_off.png")));
}
Also used : GuiInnerScreen(mekanism.client.gui.element.GuiInnerScreen) GuiStateTexture(mekanism.generators.client.gui.element.GuiStateTexture) ArrayList(java.util.ArrayList) List(java.util.List) GuiVerticalPowerBar(mekanism.client.gui.element.bar.GuiVerticalPowerBar) GuiEnergyTab(mekanism.client.gui.element.tab.GuiEnergyTab) ILangEntry(mekanism.api.text.ILangEntry)

Example 3 with ILangEntry

use of mekanism.api.text.ILangEntry in project Mekanism by mekanism.

the class Module method init.

public void init() {
    enabled = addConfigItem(new ModuleConfigItem<Boolean>(this, ENABLED_KEY, MekanismLang.MODULE_ENABLED, new ModuleBooleanData(!data.isDisabledByDefault())) {

        @Override
        public void set(@Nonnull Boolean val, @Nullable Runnable callback) {
            // Custom override of set to see if it changed and if so notify the custom module of that fact
            boolean wasEnabled = get();
            super.set(val, callback);
            // we can assume it is server side
            if (callback == null && wasEnabled != get()) {
                customModule.onEnabledStateChange(Module.this);
            }
        }
    });
    if (data.handlesModeChange()) {
        handleModeChange = addConfigItem(new ModuleConfigItem<>(this, HANDLE_MODE_CHANGE_KEY, MekanismLang.MODULE_HANDLE_MODE_CHANGE, new ModuleBooleanData()));
    }
    if (data.rendersHUD()) {
        renderHUD = addConfigItem(new ModuleConfigItem<>(this, "renderHUD", MekanismLang.MODULE_RENDER_HUD, new ModuleBooleanData()));
    }
    customModule.init(this, new ModuleConfigItemCreator() {

        @Override
        public <TYPE> IModuleConfigItem<TYPE> createConfigItem(String name, ILangEntry description, ModuleConfigData<TYPE> data) {
            return addConfigItem(new ModuleConfigItem<>(Module.this, name, description, data));
        }

        @Override
        public IModuleConfigItem<Boolean> createDisableableConfigItem(String name, ILangEntry description, boolean def, BooleanSupplier isConfigEnabled) {
            return addConfigItem(new DisableableModuleConfigItem(Module.this, name, description, def, isConfigEnabled));
        }
    });
}
Also used : DisableableModuleConfigItem(mekanism.common.content.gear.ModuleConfigItem.DisableableModuleConfigItem) Nonnull(javax.annotation.Nonnull) IModuleConfigItem(mekanism.api.gear.config.IModuleConfigItem) ModuleBooleanData(mekanism.api.gear.config.ModuleBooleanData) ModuleConfigItemCreator(mekanism.api.gear.config.ModuleConfigItemCreator) IModuleConfigItem(mekanism.api.gear.config.IModuleConfigItem) DisableableModuleConfigItem(mekanism.common.content.gear.ModuleConfigItem.DisableableModuleConfigItem) BooleanSupplier(java.util.function.BooleanSupplier) Nullable(javax.annotation.Nullable) ILangEntry(mekanism.api.text.ILangEntry)

Example 4 with ILangEntry

use of mekanism.api.text.ILangEntry in project Mekanism by mekanism.

the class StorageUtils method addStoredSubstance.

/**
 * @implNote Assumes there is only one "tank"
 */
public static void addStoredSubstance(@Nonnull ItemStack stack, @Nonnull List<ITextComponent> tooltip, boolean isCreative) {
    // Note we ensure the capabilities are not null, as the first call to addInformation happens before capability injection
    if (Capabilities.GAS_HANDLER_CAPABILITY == null || Capabilities.INFUSION_HANDLER_CAPABILITY == null || Capabilities.PIGMENT_HANDLER_CAPABILITY == null || Capabilities.SLURRY_HANDLER_CAPABILITY == null || CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY == null) {
        return;
    }
    FluidStack fluidStack = StorageUtils.getStoredFluidFromNBT(stack);
    GasStack gasStack = StorageUtils.getStoredGasFromNBT(stack);
    InfusionStack infusionStack = StorageUtils.getStoredInfusionFromNBT(stack);
    PigmentStack pigmentStack = StorageUtils.getStoredPigmentFromNBT(stack);
    SlurryStack slurryStack = StorageUtils.getStoredSlurryFromNBT(stack);
    if (fluidStack.isEmpty() && gasStack.isEmpty() && infusionStack.isEmpty() && pigmentStack.isEmpty() && slurryStack.isEmpty()) {
        tooltip.add(MekanismLang.EMPTY.translate());
        return;
    }
    ILangEntry type;
    Object contents;
    long amount;
    if (!fluidStack.isEmpty()) {
        contents = fluidStack;
        amount = fluidStack.getAmount();
        type = MekanismLang.LIQUID;
    } else {
        ChemicalStack<?> chemicalStack;
        if (!gasStack.isEmpty()) {
            chemicalStack = gasStack;
            type = MekanismLang.GAS;
        } else if (!infusionStack.isEmpty()) {
            chemicalStack = infusionStack;
            type = MekanismLang.INFUSE_TYPE;
        } else if (!pigmentStack.isEmpty()) {
            chemicalStack = pigmentStack;
            type = MekanismLang.PIGMENT;
        } else if (!slurryStack.isEmpty()) {
            chemicalStack = slurryStack;
            type = MekanismLang.SLURRY;
        } else {
            throw new IllegalStateException("Unknown chemical");
        }
        contents = chemicalStack;
        amount = chemicalStack.getAmount();
    }
    if (isCreative) {
        tooltip.add(type.translateColored(EnumColor.YELLOW, EnumColor.ORANGE, MekanismLang.GENERIC_STORED.translate(contents, EnumColor.GRAY, MekanismLang.INFINITE)));
    } else {
        tooltip.add(type.translateColored(EnumColor.YELLOW, EnumColor.ORANGE, MekanismLang.GENERIC_STORED_MB.translate(contents, EnumColor.GRAY, TextUtils.format(amount))));
    }
}
Also used : PigmentStack(mekanism.api.chemical.pigment.PigmentStack) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) FluidStack(net.minecraftforge.fluids.FluidStack) GasStack(mekanism.api.chemical.gas.GasStack) SlurryStack(mekanism.api.chemical.slurry.SlurryStack) ILangEntry(mekanism.api.text.ILangEntry)

Example 5 with ILangEntry

use of mekanism.api.text.ILangEntry in project Mekanism by mekanism.

the class UnitDisplayUtils method getDisplayBase.

public static ITextComponent getDisplayBase(double value, Unit unit, int decimalPlaces, boolean isShort, boolean spaceBetweenSymbol) {
    ILangEntry label = unit.getLabel();
    String spaceStr = spaceBetweenSymbol ? " " : "";
    if (value == 0) {
        return isShort ? TextComponentUtil.getString(value + spaceStr + unit.getSymbol()) : TextComponentUtil.build(value, label);
    }
    boolean negative = value < 0;
    if (negative) {
        value = Math.abs(value);
    }
    for (int i = 0; i < EnumUtils.MEASUREMENT_UNITS.length; i++) {
        MeasurementUnit lowerMeasure = EnumUtils.MEASUREMENT_UNITS[i];
        String symbolStr = spaceStr + lowerMeasure.symbol;
        if (lowerMeasure.below(value) && lowerMeasure.ordinal() == 0) {
            if (isShort) {
                return TextComponentUtil.getString(roundDecimals(negative, lowerMeasure.process(value), decimalPlaces) + symbolStr + unit.getSymbol());
            }
            return TextComponentUtil.build(roundDecimals(negative, lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.name, label);
        }
        if (lowerMeasure.ordinal() + 1 >= EnumUtils.MEASUREMENT_UNITS.length) {
            if (isShort) {
                return TextComponentUtil.getString(roundDecimals(negative, lowerMeasure.process(value), decimalPlaces) + symbolStr + unit.getSymbol());
            }
            return TextComponentUtil.build(roundDecimals(negative, lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.name, label);
        }
        if (i + 1 < EnumUtils.MEASUREMENT_UNITS.length) {
            MeasurementUnit upperMeasure = EnumUtils.MEASUREMENT_UNITS[i + 1];
            if ((lowerMeasure.above(value) && upperMeasure.below(value)) || lowerMeasure.value == value) {
                if (isShort) {
                    return TextComponentUtil.getString(roundDecimals(negative, lowerMeasure.process(value), decimalPlaces) + symbolStr + unit.getSymbol());
                }
                return TextComponentUtil.build(roundDecimals(negative, lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.name, label);
            }
        }
    }
    if (isShort) {
        return TextComponentUtil.getString(roundDecimals(negative, value, decimalPlaces) + spaceStr + unit.getSymbol());
    }
    return TextComponentUtil.build(roundDecimals(negative, value, decimalPlaces) + " ", label);
}
Also used : ILangEntry(mekanism.api.text.ILangEntry)

Aggregations

ILangEntry (mekanism.api.text.ILangEntry)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GuiInnerScreen (mekanism.client.gui.element.GuiInnerScreen)2 GuiVerticalPowerBar (mekanism.client.gui.element.bar.GuiVerticalPowerBar)2 GuiEnergyTab (mekanism.client.gui.element.tab.GuiEnergyTab)2 BooleanSupplier (java.util.function.BooleanSupplier)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 GasStack (mekanism.api.chemical.gas.GasStack)1 InfusionStack (mekanism.api.chemical.infuse.InfusionStack)1 PigmentStack (mekanism.api.chemical.pigment.PigmentStack)1 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)1 IModuleConfigItem (mekanism.api.gear.config.IModuleConfigItem)1 ModuleBooleanData (mekanism.api.gear.config.ModuleBooleanData)1 ModuleConfigItemCreator (mekanism.api.gear.config.ModuleConfigItemCreator)1 FloatingLong (mekanism.api.math.FloatingLong)1 GuiDigitalSwitch (mekanism.client.gui.element.GuiDigitalSwitch)1 TranslationButton (mekanism.client.gui.element.button.TranslationButton)1 GuiSlot (mekanism.client.gui.element.slot.GuiSlot)1