Search in sources :

Example 6 with TextComponent

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

the class RenderOverlay method renderEntity.

private static TooltipComponent renderEntity(WorldClient world, EntityPlayerSP player, Entity entity, boolean shouldCalculate) {
    TooltipComponent component = new TooltipComponent();
    if (ConfigBoolean.SHOW_DROPPED_ITEMS.value && entity instanceof EntityItem) {
        component.setName(new TextComponent(L10n.getItemText(InfoUtil.getItemName(((EntityItem) entity).getItem()) + TextFormatting.RESET, String.valueOf(((EntityItem) entity).getItem().getCount()))));
        component.add(new DescriptionComponent(((EntityItem) entity).getItem()), TooltipComponent.Priority.LOW);
        component.setModName(new TextComponent(InfoUtil.getModName(((EntityItem) entity).getItem().getItem())));
        component.setIconRenderer(new IconRenderer(((EntityItem) entity).getItem()));
        for (IWorldRenderer renderer : TUMATApi.getRegisteredComponents()) {
            if (renderer.shouldBeActive()) {
                renderer.renderEntityItem(world, player, (EntityItem) entity, ((EntityItem) entity).getItem(), component, shouldCalculate);
            }
        }
    } else if (ConfigBoolean.SHOW_ENTITIES.value && entity instanceof EntityLivingBase) {
        component.setName(new TextComponent(InfoUtil.getEntityName(entity)));
        component.add(new TextComponent(TextFormatting.RED.toString() + ((EntityLivingBase) entity).getHealth() + "/" + ((EntityLivingBase) entity).getMaxHealth()), TooltipComponent.Priority.HIGH);
        component.setModName(new TextComponent(InfoUtil.getModName(entity)));
        ResourceLocation res = EntityList.getKey(entity);
        if (res != null) {
            ItemStack spawnEgg = new ItemStack(Items.SPAWN_EGG);
            ItemMonsterPlacer.applyEntityIdToItemStack(spawnEgg, res);
            component.setIconRenderer(new IconRenderer(spawnEgg));
        }
        for (IWorldRenderer renderer : TUMATApi.getRegisteredComponents()) {
            if (renderer.shouldBeActive()) {
                renderer.renderLivingEntity(world, player, (EntityLivingBase) entity, component, shouldCalculate);
            }
        }
    } else if (ConfigBoolean.SHOW_ENTITIES.value) {
        component.setName(new TextComponent(InfoUtil.getEntityName(entity)));
        component.setModName(new TextComponent(InfoUtil.getModName(entity)));
        for (IWorldRenderer renderer : TUMATApi.getRegisteredComponents()) {
            if (renderer.shouldBeActive()) {
                renderer.renderEntity(world, player, entity, component, shouldCalculate);
            }
        }
    }
    return component;
}
Also used : TextComponent(de.canitzp.tumat.api.components.TextComponent) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLivingBase(net.minecraft.entity.EntityLivingBase) TooltipComponent(de.canitzp.tumat.api.TooltipComponent) IWorldRenderer(de.canitzp.tumat.api.IWorldRenderer) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) DescriptionComponent(de.canitzp.tumat.api.components.DescriptionComponent)

Example 7 with TextComponent

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

the class RenderOverlay method renderBlock.

private static TooltipComponent renderBlock(WorldClient world, EntityPlayerSP player, BlockPos pos, EnumFacing side, boolean shouldCalculate) {
    TooltipComponent component = new TooltipComponent();
    if (!world.isAirBlock(pos)) {
        IBlockState state = world.getBlockState(pos);
        component.setName(TextComponent.createWithSensitiveName(world, player, savedTrace, pos, state));
        component.add(new DescriptionComponent(InfoUtil.newStackFromBlock(world, pos, state, player, savedTrace)), TooltipComponent.Priority.LOW);
        component.setModName(new TextComponent(InfoUtil.getModName(state.getBlock())));
        for (IWorldRenderer renderer : TUMATApi.getRegisteredComponents()) {
            if (renderer.shouldBeActive()) {
                renderer.renderBlock(world, player, pos, side, component, shouldCalculate);
                TileEntity tile = world.getTileEntity(pos);
                if (ConfigBoolean.SHOW_TILES.value && tile != null) {
                    try {
                        renderer.renderTileEntity(world, player, tile, side, component, shouldCalculate);
                    } catch (Exception e) {
                        component.add(new DescriptionComponent(Lists.newArrayList("An error occured", "while getting tile data!")), TooltipComponent.Priority.HIGH);
                        if (world.getTotalWorldTime() % 150 == 0) {
                            TUMAT.logger.error("An error occured while getting tile data from: " + state.getBlock().getUnlocalizedName() + " at: " + pos, e);
                        }
                    }
                }
                component.setIconRenderer(renderer.getIconRenderObject(world, player, pos, side, savedTrace, shouldCalculate));
            }
        }
    } else {
        return null;
    }
    return component;
}
Also used : TextComponent(de.canitzp.tumat.api.components.TextComponent) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) TooltipComponent(de.canitzp.tumat.api.TooltipComponent) IWorldRenderer(de.canitzp.tumat.api.IWorldRenderer) DescriptionComponent(de.canitzp.tumat.api.components.DescriptionComponent)

Example 8 with TextComponent

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

the class RenderOverlay method renderMiss.

private static TooltipComponent renderMiss(WorldClient world, EntityPlayerSP player, RayTraceResult trace, boolean shouldCalculate) {
    TooltipComponent component = new TooltipComponent();
    if (!world.isAirBlock(trace.getBlockPos())) {
        IBlockState state = world.getBlockState(trace.getBlockPos());
        if (state.getBlock() instanceof BlockLiquid || state.getBlock() instanceof BlockFluidBase) {
            component.setName(new TextComponent(state.getBlock().getLocalizedName()));
            component.setModName(new TextComponent(InfoUtil.getModName(state.getBlock())));
            IconRenderer renderer;
            if (bucketCache.containsKey(state.getBlock().getRegistryName())) {
                component.setIconRenderer(bucketCache.get(state.getBlock().getRegistryName()));
            } else {
                Fluid fluid = FluidRegistry.lookupFluidForBlock(state.getBlock());
                if (fluid != null) {
                    renderer = new IconRenderer(FluidUtil.getFilledBucket(new FluidStack(fluid, 1000)));
                    bucketCache.put(state.getBlock().getRegistryName(), renderer);
                    component.setIconRenderer(renderer);
                }
            }
        }
        for (IWorldRenderer renderer : TUMATApi.getRegisteredComponents()) {
            if (renderer.shouldBeActive()) {
                renderer.renderMiss(world, player, trace, component, shouldCalculate);
            }
        }
    }
    return component;
}
Also used : TextComponent(de.canitzp.tumat.api.components.TextComponent) IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) TooltipComponent(de.canitzp.tumat.api.TooltipComponent) IWorldRenderer(de.canitzp.tumat.api.IWorldRenderer)

Example 9 with TextComponent

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

the class TUMATEvents method gameOverlayRenderEvent.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void gameOverlayRenderEvent(RenderGameOverlayEvent.Post event) {
    if (ConfigBoolean.SHOULD_TUMAT_RENDER.value && event.getType().equals(RenderGameOverlayEvent.ElementType.HOTBAR)) {
        Minecraft mc = Minecraft.getMinecraft();
        if (mc.currentScreen == null || TUMATApi.getAllowedGuis().contains(mc.currentScreen.getClass())) {
            try {
                if (TUMAT.DEBUG) {
                    String tumat = TextFormatting.AQUA.toString() + "T" + TextFormatting.GREEN.toString() + "U" + TextFormatting.RED.toString() + "M" + TextFormatting.YELLOW.toString() + "A" + TextFormatting.AQUA.toString() + "T" + TextFormatting.RESET.toString();
                    String buildText = tumat + " build " + TUMAT.BUILD_DATE;
                    GlStateManager.pushMatrix();
                    GlStateManager.scale(0.4F, 0.4F, 0.4F);
                    GlStateManager.color(1.0F, 1.0F, 1.0F, 0.5F);
                    Minecraft.getMinecraft().fontRenderer.drawString(buildText, 2, 2, 0x80FFFFFF);
                    GlStateManager.popMatrix();
                }
                RenderOverlay.render(mc.world, mc.player, mc.fontRenderer, event.getPartialTicks(), mc.world.getTotalWorldTime() % 3 == 0);
            } catch (Exception e) {
                InfoUtil.drawCenteredString(mc.fontRenderer, L10n.ERROR_TEXT, GuiTUMAT.getXFromPercantage(), GuiTUMAT.getYFromPercantage(), 0xFFFFFF);
                RenderOverlay.renderComponents(mc.fontRenderer, new TooltipComponent().setName(new TextComponent(L10n.ERROR_TEXT)).add(new DescriptionComponent(Lists.newArrayList("")), TooltipComponent.Priority.HIGH));
                if (mc.world.getTotalWorldTime() % 100 == 0) {
                    TUMAT.logger.error("An Error occurred while rendering the tooltip.", e);
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : TextComponent(de.canitzp.tumat.api.components.TextComponent) TooltipComponent(de.canitzp.tumat.api.TooltipComponent) Minecraft(net.minecraft.client.Minecraft) DescriptionComponent(de.canitzp.tumat.api.components.DescriptionComponent) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 10 with TextComponent

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

the class StorageDrawers method renderTileEntity.

@Override
public TooltipComponent renderTileEntity(WorldClient world, EntityPlayerSP player, TileEntity tileEntity, EnumFacing side, TooltipComponent component, boolean shouldCalculate) {
    if (player.isSneaking() && tileEntity instanceof TileEntityDrawers) {
        if (tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)) {
            IItemHandler handler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
            if (handler != null) {
                List<String> lines = new ArrayList<>();
                for (int i = 1; i < handler.getSlots(); i++) {
                    ItemStack stack = handler.getStackInSlot(i);
                    if (!stack.isEmpty()) {
                        lines.add(L10n.getStorageDrawersContent(i, InfoUtil.getItemName(stack)));
                    } else {
                        lines.add(L10n.getStorageDrawersContent(i, TextFormatting.WHITE + L10n.EMPTY));
                    }
                }
                component.add(new DescriptionComponent(lines), TooltipComponent.Priority.HIGH);
            }
        } else {
            component.add(new TextComponent(L10n.SNEAKFORMORE).setScale(0.8F).setFormat(TextFormatting.GRAY), TooltipComponent.Priority.HIGH);
        }
    }
    return component;
}
Also used : TextComponent(de.canitzp.tumat.api.components.TextComponent) IItemHandler(net.minecraftforge.items.IItemHandler) TileEntityDrawers(com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers) ArrayList(java.util.ArrayList) 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