Search in sources :

Example 26 with ScaledResolution

use of net.minecraft.client.gui.ScaledResolution in project Witchworks by Um-Mitternacht.

the class BrewHUD method renderOverlay.

@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Post event) {
    if (!BREW_HUD.hide && event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
        Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(Minecraft.getMinecraft().player);
        if (optional.isPresent()) {
            ScaledResolution res = event.getResolution();
            int x = res.getScaledWidth() - BREW_HUD.x;
            int yOffset = BREW_HUD.y;
            Minecraft mc = Minecraft.getMinecraft();
            Set<IBrew> client = optional.get().getClient();
            if (client == null)
                return;
            Iterator<IBrew> renders = client.iterator();
            GlStateManager.pushMatrix();
            while (renders.hasNext()) {
                renders.next().renderHUD(x, yOffset, mc);
                yOffset += 22;
            }
            GlStateManager.popMatrix();
        }
    }
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) IBrewStorage(com.witchworks.common.core.capability.potion.IBrewStorage) Minecraft(net.minecraft.client.Minecraft) IBrew(com.witchworks.api.item.IBrew) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 27 with ScaledResolution

use of net.minecraft.client.gui.ScaledResolution in project Guide-API by TeamAmeriFrance.

the class EventHandler method renderOverlay.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Pre event) {
    if (event.getType() != RenderGameOverlayEvent.ElementType.CROSSHAIRS)
        return;
    RayTraceResult rayTrace = Minecraft.getMinecraft().objectMouseOver;
    if (rayTrace == null || rayTrace.typeOfHit != RayTraceResult.Type.BLOCK)
        return;
    EntityPlayer player = Minecraft.getMinecraft().player;
    World world = Minecraft.getMinecraft().world;
    ItemStack held = ItemStack.EMPTY;
    Book book = null;
    for (EnumHand hand : EnumHand.values()) {
        ItemStack heldStack = player.getHeldItem(hand);
        if (heldStack.getItem() instanceof IGuideItem) {
            held = heldStack;
            book = ((IGuideItem) heldStack.getItem()).getBook(heldStack);
            break;
        }
    }
    if (book == null)
        return;
    IBlockState state = world.getBlockState(rayTrace.getBlockPos());
    String linkedEntry = null;
    if (state.getBlock() instanceof IGuideLinked) {
        IGuideLinked linked = (IGuideLinked) state.getBlock();
        ResourceLocation entryKey = linked.getLinkedEntry(world, rayTrace.getBlockPos(), player, held);
        if (entryKey != null) {
            for (CategoryAbstract category : book.getCategoryList()) {
                if (category.entries.containsKey(entryKey)) {
                    linkedEntry = category.getEntry(entryKey).getLocalizedName();
                    break;
                }
            }
        }
    }
    if (!Strings.isNullOrEmpty(linkedEntry)) {
        FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
        ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
        int drawX = scaledResolution.getScaledWidth() / 2 + 10;
        int drawY = scaledResolution.getScaledHeight() / 2 - 8;
        Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(held, drawX, drawY);
        drawY -= 2;
        drawX += 20;
        fontRenderer.drawStringWithShadow(TextFormatting.WHITE + linkedEntry, drawX, drawY, 0);
        fontRenderer.drawStringWithShadow(TextFormatting.WHITE.toString() + TextFormatting.ITALIC.toString() + TextHelper.localize("text.linked.open"), drawX, drawY + 12, 0);
    }
    if (state.getBlock() instanceof IInfoRenderer.Block) {
        IInfoRenderer infoRenderer = ((IInfoRenderer.Block) state.getBlock()).getInfoRenderer(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
        if (book == ((IInfoRenderer.Block) state.getBlock()).getBook() && infoRenderer != null)
            infoRenderer.drawInformation(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
    }
    Multimap<Class<? extends Block>, IInfoRenderer> bookRenderers = GuideAPI.getInfoRenderers().get(book);
    if (bookRenderers == null)
        return;
    Collection<IInfoRenderer> renderers = bookRenderers.get(state.getBlock().getClass());
    for (IInfoRenderer renderer : renderers) renderer.drawInformation(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
}
Also used : IGuideLinked(amerifrance.guideapi.api.IGuideLinked) IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) IInfoRenderer(amerifrance.guideapi.api.IInfoRenderer) ScaledResolution(net.minecraft.client.gui.ScaledResolution) CategoryAbstract(amerifrance.guideapi.api.impl.abstraction.CategoryAbstract) Book(amerifrance.guideapi.api.impl.Book) EnumHand(net.minecraft.util.EnumHand) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) IGuideItem(amerifrance.guideapi.api.IGuideItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 28 with ScaledResolution

use of net.minecraft.client.gui.ScaledResolution in project Guide-API by TeamAmeriFrance.

the class InfoRendererImage method drawInformation.

@Override
public void drawInformation(Book book, World world, BlockPos pos, IBlockState state, RayTraceResult rayTrace, EntityPlayer player) {
    ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());
    Minecraft.getMinecraft().renderEngine.bindTexture(image);
    Gui.drawModalRectWithCustomSizedTexture(resolution.getScaledWidth() / 2 + 20, resolution.getScaledHeight() / 2 - imageHeight / 2, imageX, imageY, imageWidth, imageHeight, imageWidth, imageHeight);
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution)

Example 29 with ScaledResolution

use of net.minecraft.client.gui.ScaledResolution in project malmo by Microsoft.

the class ScreenHelper method onRenderTick.

@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent ev) {
    purgeExpiredFragments(null);
    if (Minecraft.getMinecraft().currentScreen != null && !(Minecraft.getMinecraft().currentScreen instanceof GuiMainMenu))
        return;
    if (// Don't obscure MC debug info with our debug info
    Minecraft.getMinecraft().gameSettings.showDebugInfo)
        return;
    ScaledResolution res = new ScaledResolution(Minecraft.getMinecraft());
    int width = res.getScaledWidth();
    int height = res.getScaledHeight();
    float rx = (float) width / 1000f;
    float ry = (float) height / 1000f;
    synchronized (this.fragments) {
        for (TextCategory cat : TextCategory.values()) {
            TextCategoryAttributes atts = this.attributes.get(cat);
            if (atts != null && (!atts.flashing || ((System.currentTimeMillis() / 500) % 3 != 0)) && shouldDisplay(atts.displayLevel)) {
                int x = Math.round(rx * (float) atts.xOrg);
                int y = Math.round(ry * (float) atts.yOrg);
                ArrayList<TextFragment> frags = this.fragments.get(cat);
                if (frags != null && !frags.isEmpty()) {
                    for (TextFragment frag : frags) {
                        drawText(frag.text, x, y, atts.colour);
                        y += 10;
                    }
                }
            }
        }
    }
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) GuiMainMenu(net.minecraft.client.gui.GuiMainMenu) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ScaledResolution (net.minecraft.client.gui.ScaledResolution)29 Minecraft (net.minecraft.client.Minecraft)15 ItemStack (net.minecraft.item.ItemStack)8 GuiAnimatedStat (pneumaticCraft.client.gui.widget.GuiAnimatedStat)5 Rectangle (java.awt.Rectangle)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 SideOnly (cpw.mods.fml.relauncher.SideOnly)3 FontRenderer (net.minecraft.client.gui.FontRenderer)3 Tessellator (net.minecraft.client.renderer.Tessellator)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 IGuiAnimatedStat (pneumaticCraft.api.client.IGuiAnimatedStat)3 ArrayList (java.util.ArrayList)2 AMVector2 (am2.api.math.AMVector2)1 IBoundItem (am2.items.IBoundItem)1 ItemSpellBook (am2.items.ItemSpellBook)1 IGuideItem (amerifrance.guideapi.api.IGuideItem)1 IGuideLinked (amerifrance.guideapi.api.IGuideLinked)1 IInfoRenderer (amerifrance.guideapi.api.IInfoRenderer)1 Book (amerifrance.guideapi.api.impl.Book)1 CategoryAbstract (amerifrance.guideapi.api.impl.abstraction.CategoryAbstract)1