Search in sources :

Example 1 with BlockRedstoneRepeater

use of net.minecraft.block.BlockRedstoneRepeater 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)

Aggregations

TextComponent (de.canitzp.tumat.api.components.TextComponent)1 BlockCrops (net.minecraft.block.BlockCrops)1 BlockDoublePlant (net.minecraft.block.BlockDoublePlant)1 BlockRedstoneRepeater (net.minecraft.block.BlockRedstoneRepeater)1 BlockRedstoneWire (net.minecraft.block.BlockRedstoneWire)1 PropertyInteger (net.minecraft.block.properties.PropertyInteger)1 IBlockState (net.minecraft.block.state.IBlockState)1 TextFormatting (net.minecraft.util.text.TextFormatting)1 IPlantable (net.minecraftforge.common.IPlantable)1