Search in sources :

Example 1 with DescriptionComponent

use of de.canitzp.tumat.api.components.DescriptionComponent 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 DescriptionComponent

use of de.canitzp.tumat.api.components.DescriptionComponent 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 DescriptionComponent

use of de.canitzp.tumat.api.components.DescriptionComponent 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 4 with DescriptionComponent

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

Example 5 with DescriptionComponent

use of de.canitzp.tumat.api.components.DescriptionComponent 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

DescriptionComponent (de.canitzp.tumat.api.components.DescriptionComponent)5 TextComponent (de.canitzp.tumat.api.components.TextComponent)5 TooltipComponent (de.canitzp.tumat.api.TooltipComponent)3 ItemStack (net.minecraft.item.ItemStack)3 IWorldRenderer (de.canitzp.tumat.api.IWorldRenderer)2 ArrayList (java.util.ArrayList)2 TileEntityDrawers (com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers)1 EnergyComponent (de.canitzp.tumat.api.components.EnergyComponent)1 IEnergyStorage (ic2.api.tile.IEnergyStorage)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 IBlockState (net.minecraft.block.state.IBlockState)1 Minecraft (net.minecraft.client.Minecraft)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1