Search in sources :

Example 1 with IWorldRenderer

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

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

the class RenderOverlay method render.

public static void render(WorldClient world, EntityPlayerSP player, FontRenderer fontRenderer, float partialTicks, boolean shouldCalculate) {
    boolean calculate = savedTrace == null || shouldCalculate;
    RayTraceResult trace;
    if (calculate) {
        if (ignoredEntities == null) {
            ignoredEntities = new ArrayList<>();
            for (IWorldRenderer worldRenderer : TUMATApi.getRegisteredComponents()) {
                ignoredEntities.addAll(worldRenderer.getInvisibleEntities());
            }
        }
        float distance = 0F;
        NetHandlerPlayClient clientHandler = Minecraft.getMinecraft().getConnection();
        if (clientHandler != null) {
            switch(clientHandler.getPlayerInfo(player.getGameProfile().getId()).getGameType()) {
                case CREATIVE:
                    {
                        distance = ConfigFloat.DISTANCE_CREATIVE.value;
                        break;
                    }
                case SURVIVAL:
                    {
                        distance = ConfigFloat.DISTANCE_SURVIVAL.value;
                        break;
                    }
                case ADVENTURE:
                    {
                        distance = ConfigFloat.DISTANCE_ADVENTURE.value;
                        break;
                    }
                case SPECTATOR:
                    {
                        distance = ConfigFloat.DISTANCE_SPECTATOR.value;
                        break;
                    }
            }
        }
        trace = savedTrace = createRayTraceForDistance(world, player, distance, partialTicks);
    } else {
        trace = savedTrace;
    }
    if (trace != null) {
        switch(trace.typeOfHit) {
            case BLOCK:
                {
                    if (ConfigBoolean.SHOW_BLOCKS.value) {
                        renderComponents(fontRenderer, renderBlock(world, player, trace.getBlockPos(), trace.sideHit, calculate));
                    }
                    break;
                }
            case ENTITY:
                {
                    renderComponents(fontRenderer, renderEntity(world, player, trace.entityHit, calculate));
                    break;
                }
            case MISS:
                {
                    if (ConfigBoolean.SHOW_FLUIDS.value) {
                        renderComponents(fontRenderer, renderMiss(world, player, trace, calculate));
                    }
                    break;
                }
        }
    }
}
Also used : NetHandlerPlayClient(net.minecraft.client.network.NetHandlerPlayClient) RayTraceResult(net.minecraft.util.math.RayTraceResult) IWorldRenderer(de.canitzp.tumat.api.IWorldRenderer)

Example 3 with IWorldRenderer

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

use of de.canitzp.tumat.api.IWorldRenderer 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().getTranslationKey() + " 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 5 with IWorldRenderer

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

the class TUMATEvents method renderGuiContainer.

@SideOnly(Side.CLIENT)
@SuppressWarnings("ConstantConditions")
@SubscribeEvent()
public static void renderGuiContainer(GuiScreenEvent.DrawScreenEvent.Post event) {
    if (ConfigBoolean.SHOW_SLOT_NUMBERS.value && event.getGui() instanceof GuiContainer) {
        if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) {
            FontRenderer renderer = Minecraft.getMinecraft().fontRenderer;
            GuiContainer gui = (GuiContainer) event.getGui();
            int guiLeft = 0;
            int guiTop = 0;
            for (IWorldRenderer rend : TUMATApi.getRegisteredComponents()) {
                int i = rend.getGuiLeftOffset(gui);
                if (i != 0) {
                    guiLeft = i;
                }
                int j = rend.getGuiTopOffset(gui);
                if (j != 0) {
                    guiTop = j;
                }
            }
            if (guiLeft == 0) {
                guiLeft = ((int) ReflectionHelper.getPrivateValue(GuiContainer.class, gui, 4)) - 1;
            }
            if (guiTop == 0) {
                guiTop = ((int) ReflectionHelper.getPrivateValue(GuiContainer.class, gui, 5)) - 1;
            }
            GlStateManager.pushAttrib();
            GlStateManager.pushMatrix();
            GlStateManager.disableBlend();
            RenderHelper.disableStandardItemLighting();
            GlStateManager.scale(0.5F, 0.5F, 0.5F);
            for (Slot slot : gui.inventorySlots.inventorySlots) {
                GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
                renderer.drawString(String.valueOf(slot.getSlotIndex()), 2 * (slot.xPos + guiLeft), 2 * (slot.yPos + guiTop), 0xFFFFFF, false);
            }
            RenderHelper.enableStandardItemLighting();
            GlStateManager.enableBlend();
            GlStateManager.popAttrib();
            GlStateManager.popMatrix();
        }
    }
}
Also used : Slot(net.minecraft.inventory.Slot) IWorldRenderer(de.canitzp.tumat.api.IWorldRenderer) GuiContainer(net.minecraft.client.gui.inventory.GuiContainer) FontRenderer(net.minecraft.client.gui.FontRenderer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

IWorldRenderer (de.canitzp.tumat.api.IWorldRenderer)5 TooltipComponent (de.canitzp.tumat.api.TooltipComponent)3 TextComponent (de.canitzp.tumat.api.components.TextComponent)3 DescriptionComponent (de.canitzp.tumat.api.components.DescriptionComponent)2 IBlockState (net.minecraft.block.state.IBlockState)2 BlockLiquid (net.minecraft.block.BlockLiquid)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 GuiContainer (net.minecraft.client.gui.inventory.GuiContainer)1 NetHandlerPlayClient (net.minecraft.client.network.NetHandlerPlayClient)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 Slot (net.minecraft.inventory.Slot)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1