Search in sources :

Example 11 with TextComponent

use of de.canitzp.tumat.api.components.TextComponent in project TUMAT by canitzp.

the class Vanilla method renderBlock.

@Override
public TooltipComponent renderBlock(WorldClient world, EntityPlayerSP player, BlockPos pos, EnumFacing side, TooltipComponent component, boolean shouldCalculate) {
    IBlockState state = world.getBlockState(pos);
    // Plants:
    if (state.getBlock() instanceof IPlantable) {
        IBlockState plant = ((IPlantable) state.getBlock()).getPlant(world, pos);
        if (plant != null) {
            if (ConfigBoolean.SHOW_PLANT_GROWTH_STATUS.value && plant.getBlock() instanceof BlockCrops) {
                try {
                    PropertyInteger prop = (PropertyInteger) getAgeProperty.invoke(plant.getBlock());
                    int plantStatus = state.getValue(prop);
                    float growStatus = Math.round((plantStatus / (prop.getAllowedValues().size() - 1 * 1.0F) * 100F) * 100.00F) / 100.00F;
                    ColoredText.createOneLine(component, L10n.getVanillaGrowRate(String.valueOf(growStatus)), ColoredText.Colors.BROWN_PLANT);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (plant.getBlock() instanceof BlockDoublePlant && InfoUtil.hasProperty(plant, BlockDoublePlant.HALF)) {
                BlockDoublePlant.EnumBlockHalf half = plant.getValue(BlockDoublePlant.HALF);
                if (half == BlockDoublePlant.EnumBlockHalf.UPPER) {
                    IBlockState down = world.getBlockState(pos.down());
                    component.setName(new TextComponent(InfoUtil.getBlockName(down)));
                }
            }
        }
    }
    if (ConfigBoolean.SHOW_REDSTONE_STRENGTH.value) {
        int power = state.getWeakPower(world, pos, side);
        if (power > 0 || state.getBlock() instanceof BlockRedstoneWire) {
            ColoredText.createOneLine(component, L10n.getVanillaRedstoneStrength(power), ColoredText.Colors.RED_REDSTONE);
        }
        if (state.getBlock() instanceof BlockRedstoneRepeater) {
            ColoredText.createOneLine(component, L10n.getVanillaRedstoneDelay(state.getValue(BlockRedstoneRepeater.DELAY)), ColoredText.Colors.RED_REDSTONE);
            if (state.getValue(BlockRedstoneRepeater.LOCKED)) {
                TextComponent.createOneLine(component, L10n.REDSTONE_LOCKED, TextFormatting.GRAY);
            }
        }
    }
    if (ConfigBoolean.SHOW_LIGHT_LEVEL.value) {
        boolean isBlockLightSource = state.getLightValue(world, pos) != 0;
        if (!isBlockLightSource && !world.getBlockState(pos.up()).isFullCube() && !world.getBlockState(pos.up()).isFullBlock()) {
            int lightLevel = world.getLightFor(EnumSkyBlock.BLOCK, pos.up());
            TextFormatting canMobsSpawn = world.getWorldTime() % 24000 >= 13000 && lightLevel <= 7 && state.getBlock().canCreatureSpawn(state, world, pos, EntityLiving.SpawnPlacementType.ON_GROUND) ? TextFormatting.RED : TextFormatting.YELLOW;
            TextComponent.createOneLine(component, L10n.getVanillaLight(lightLevel), canMobsSpawn);
        }
        if (isBlockLightSource) {
            int lightValue = state.getLightValue(world, pos);
            TextComponent.createOneLine(component, L10n.getVanillaLightSource(lightValue), TextFormatting.YELLOW);
        }
    }
    return component;
}
Also used : TextComponent(de.canitzp.tumat.api.components.TextComponent) IBlockState(net.minecraft.block.state.IBlockState) BlockCrops(net.minecraft.block.BlockCrops) PropertyInteger(net.minecraft.block.properties.PropertyInteger) IPlantable(net.minecraftforge.common.IPlantable) BlockDoublePlant(net.minecraft.block.BlockDoublePlant) BlockRedstoneRepeater(net.minecraft.block.BlockRedstoneRepeater) TextFormatting(net.minecraft.util.text.TextFormatting) BlockRedstoneWire(net.minecraft.block.BlockRedstoneWire)

Example 12 with TextComponent

use of de.canitzp.tumat.api.components.TextComponent in project TUMAT by canitzp.

the class CommonCapabilities method renderTileEntity.

@Override
public TooltipComponent renderTileEntity(WorldClient world, EntityPlayerSP player, TileEntity tile, EnumFacing side, TooltipComponent component, boolean shouldCalculate) {
    // Temperature
    if (ConfigBoolean.SHOW_TEMPERATURE_COMMONCAPABILITIES.value && tile.hasCapability(TemperatureConfig.CAPABILITY, side)) {
        ITemperature temp = tile.getCapability(TemperatureConfig.CAPABILITY, side);
        if (temp != null) {
            float max = Math.round(temp.getMaximumTemperature() * 10F) / 10F;
            component.add(new TextComponent(L10n.getCommonCapsTemp(String.valueOf((Math.round(temp.getTemperature() * 10F) / 10F)), max > 10000 ? "<10000" : String.valueOf(max))).setColor(0x00EA723F), TooltipComponent.Priority.HIGH);
        }
    }
    // Worker
    if (ConfigBoolean.SHOW_WORK_COMMONCAPABILITIES.value && tile.hasCapability(WorkerConfig.CAPABILITY, side)) {
        IWorker worker = tile.getCapability(WorkerConfig.CAPABILITY, side);
        if (worker != null) {
            component.add(new TextComponent(worker.canWork() && worker.hasWork() ? L10n.COMMONCAPS_WORK_ON : L10n.COMMONCAPS_WORK_OFF).setColor(0x00965A40), TooltipComponent.Priority.HIGH);
        }
    }
    return component;
}
Also used : TextComponent(de.canitzp.tumat.api.components.TextComponent) ITemperature(org.cyclops.commoncapabilities.api.capability.temperature.ITemperature) IWorker(org.cyclops.commoncapabilities.api.capability.work.IWorker)

Example 13 with TextComponent

use of de.canitzp.tumat.api.components.TextComponent in project TUMAT by canitzp.

the class IndustrialCraft2 method renderTileEntity.

@Override
public TooltipComponent renderTileEntity(WorldClient world, EntityPlayerSP player, TileEntity tileEntity, EnumFacing side, TooltipComponent component, boolean shouldCalculate) {
    if (tileEntity instanceof TileEntityBlock) {
        InfoUtil.syncTileEntity(tileEntity, shouldCalculate, "components");
        if (((TileEntityBlock) tileEntity).hasComponent(Energy.class)) {
            Energy energy = ((TileEntityBlock) tileEntity).getComponent(Energy.class);
            List<String> desc = new ArrayList<>();
            if (ConfigBoolean.SHOW_EU.value) {
                if (!(tileEntity instanceof IEnergyStorage)) {
                    int stored = (int) energy.getEnergy();
                    int cap = (int) energy.getCapacity();
                    if (cap > 0) {
                        if (cap < stored) {
                            cap = stored;
                        }
                        component.add(new EnergyComponent(stored, cap, "EU", TextFormatting.YELLOW), TooltipComponent.Priority.HIGH);
                    }
                }
                if (!energy.getSourceDirs().isEmpty()) {
                    desc.add(Localization.translate("ic2.item.tooltip.PowerTier", energy.getSourceTier()));
                } else if (!energy.getSinkDirs().isEmpty()) {
                    desc.add(Localization.translate("ic2.item.tooltip.PowerTier", energy.getSinkTier()));
                }
            }
            if (tileEntity instanceof TileEntityTransformer) {
                desc.add(String.format("%s %.0f %s %s %.0f %s", Localization.translate("ic2.item.tooltip.Low"), EnergyNet.instance.getPowerFromTier(energy.getSinkTier()), Localization.translate("ic2.generic.text.EUt"), Localization.translate("ic2.item.tooltip.High"), EnergyNet.instance.getPowerFromTier(energy.getSourceTier() + 1), Localization.translate("ic2.generic.text.EUt")));
            }
            component.clear(TooltipComponent.Priority.LOW);
            component.add(new DescriptionComponent(desc), TooltipComponent.Priority.LOW);
        }
    }
    if (tileEntity instanceof TileEntityCable) {
        InfoUtil.syncTileEntity(tileEntity, shouldCalculate, "cableType", "insulation");
        NBTTagCompound nbt = new NBTTagCompound();
        tileEntity.writeToNBT(nbt);
        if (!nbt.hasNoTags()) {
            try {
                CableType cableType = CableType.values[nbt.getByte("cableType") & 255];
                int insulation = nbt.getByte("insulation") & 255;
                ItemStack cable = ItemCable.getCable(cableType, insulation);
                component.setName(new TextComponent(InfoUtil.getItemName(cable)));
                component.clear(TooltipComponent.Priority.LOW);
                component.add(new DescriptionComponent(cable), TooltipComponent.Priority.LOW);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return component;
}
Also used : TextComponent(de.canitzp.tumat.api.components.TextComponent) TileEntityCable(ic2.core.block.wiring.TileEntityCable) TileEntityTransformer(ic2.core.block.wiring.TileEntityTransformer) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EnergyComponent(de.canitzp.tumat.api.components.EnergyComponent) Energy(ic2.core.block.comp.Energy) CableType(ic2.core.block.wiring.CableType) IEnergyStorage(ic2.api.tile.IEnergyStorage) TileEntityBlock(ic2.core.block.TileEntityBlock) ItemStack(net.minecraft.item.ItemStack) DescriptionComponent(de.canitzp.tumat.api.components.DescriptionComponent)

Aggregations

TextComponent (de.canitzp.tumat.api.components.TextComponent)13 IBlockState (net.minecraft.block.state.IBlockState)6 DescriptionComponent (de.canitzp.tumat.api.components.DescriptionComponent)5 ItemStack (net.minecraft.item.ItemStack)5 TooltipComponent (de.canitzp.tumat.api.TooltipComponent)4 IWorldRenderer (de.canitzp.tumat.api.IWorldRenderer)3 ArrayList (java.util.ArrayList)2 TileEntityDrawers (com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers)1 EnergyComponent (de.canitzp.tumat.api.components.EnergyComponent)1 TileEntityCompost (de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost)1 TileEntityDisplayStand (de.ellpeck.actuallyadditions.mod.tile.TileEntityDisplayStand)1 TileEntitySmileyCloud (de.ellpeck.actuallyadditions.mod.tile.TileEntitySmileyCloud)1 IEnergyStorage (ic2.api.tile.IEnergyStorage)1 BlockTileEntity (ic2.core.block.BlockTileEntity)1 TileEntityBlock (ic2.core.block.TileEntityBlock)1 Energy (ic2.core.block.comp.Energy)1 CableType (ic2.core.block.wiring.CableType)1 TileEntityCable (ic2.core.block.wiring.TileEntityCable)1 TileEntityTransformer (ic2.core.block.wiring.TileEntityTransformer)1 MetaTeBlock (ic2.core.ref.MetaTeBlock)1