Search in sources :

Example 1 with TooltipComponent

use of de.canitzp.tumat.api.TooltipComponent 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 2 with TooltipComponent

use of de.canitzp.tumat.api.TooltipComponent 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 3 with TooltipComponent

use of de.canitzp.tumat.api.TooltipComponent in project TUMAT by canitzp.

the class RenderOverlay method renderComponents.

public static void renderComponents(FontRenderer fontRenderer, TooltipComponent component) {
    if (component != null) {
        TooltipComponent.Finished finished = component.close();
        int x = GuiTUMAT.getXFromPercantage();
        int y = GuiTUMAT.getYFromPercantage() + getBossBarOffset();
        int lines = 0;
        boolean renderIcon = ConfigBoolean.RENDER_ICONS.value && component.getIconRenderer() != null && component.getIconRenderer().shouldRender();
        if (ConfigBoolean.SHOW_BACKGROUND.value) {
            renderBackground(x, y, finished.getLength(), finished.getHeight(), renderIcon);
        }
        GlStateManager.pushMatrix();
        for (IComponentRender render : finished.getComponents()) {
            if (render != null) {
                GlStateManager.scale(ConfigFloat.SCALE.value, ConfigFloat.SCALE.value, ConfigFloat.SCALE.value);
                render.render(fontRenderer, x, y, 0xFFFFFF);
                int lineY = render.getLines(fontRenderer) * render.getHeightPerLine(fontRenderer);
                lines += lineY;
                y += lineY;
            }
        }
        if (renderIcon) {
            component.getIconRenderer().render(x - finished.getLength() / 2 - 22, GuiTUMAT.getYFromPercantage() + (lines / 2 - 10));
        }
        GlStateManager.popMatrix();
    }
}
Also used : IComponentRender(de.canitzp.tumat.api.IComponentRender) TooltipComponent(de.canitzp.tumat.api.TooltipComponent)

Example 4 with TooltipComponent

use of de.canitzp.tumat.api.TooltipComponent 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 5 with TooltipComponent

use of de.canitzp.tumat.api.TooltipComponent 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)

Aggregations

TooltipComponent (de.canitzp.tumat.api.TooltipComponent)5 TextComponent (de.canitzp.tumat.api.components.TextComponent)4 IWorldRenderer (de.canitzp.tumat.api.IWorldRenderer)3 DescriptionComponent (de.canitzp.tumat.api.components.DescriptionComponent)3 IBlockState (net.minecraft.block.state.IBlockState)2 IComponentRender (de.canitzp.tumat.api.IComponentRender)1 BlockLiquid (net.minecraft.block.BlockLiquid)1 Minecraft (net.minecraft.client.Minecraft)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1