Java Code Examples for net.minecraft.client.renderer.RenderHelper#enableGUIStandardItemLighting()

The following examples show how to use net.minecraft.client.renderer.RenderHelper#enableGUIStandardItemLighting() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SurfaceHelper.java    From ForgeHax with MIT License 6 votes vote down vote up
public static void drawItemWithOverlay(ItemStack item, double x, double y, double scale) {
  GlStateManager.pushMatrix();
  RenderHelper.enableGUIStandardItemLighting();
  GlStateManager.disableLighting();
  GlStateManager.enableRescaleNormal();
  GlStateManager.enableColorMaterial();
  GlStateManager.enableLighting();
  MC.getRenderItem().zLevel = 100.f;
  renderItemAndEffectIntoGUI(getLocalPlayer(), item, x, y, 16.D);
  renderItemOverlayIntoGUI(MC.fontRenderer, item, x, y, null, scale);
  MC.getRenderItem().zLevel = 0.f;
  GlStateManager.popMatrix();
  GlStateManager.disableLighting();
  GlStateManager.enableDepth();
  GlStateManager.color(1.f, 1.f, 1.f, 1.f);
}
 
Example 2
Source File: BaseComponent.java    From OpenModsLib with MIT License 6 votes vote down vote up
protected void drawItemStack(@Nonnull ItemStack stack, int x, int y, String overlayText) {
	if (stack.isEmpty()) return;

	RenderHelper.enableGUIStandardItemLighting();
	final RenderItem itemRenderer = parent.getItemRenderer();
	GlStateManager.translate(0.0F, 0.0F, 32.0F);
	this.zLevel = 200.0F;
	itemRenderer.zLevel = 200.0F;

	FontRenderer font = null;
	font = stack.getItem().getFontRenderer(stack);
	if (font == null) font = parent.getFontRenderer();

	itemRenderer.renderItemAndEffectIntoGUI(stack, x, y);
	itemRenderer.renderItemOverlayIntoGUI(font, stack, x, y, overlayText);
	this.zLevel = 0.0F;
	itemRenderer.zLevel = 0.0F;
	RenderHelper.disableStandardItemLighting();
}
 
Example 3
Source File: PuzzleTESR.java    From YouTubeModdingTutorial with MIT License 6 votes vote down vote up
private void renderSlot(TilePuzzle te) {
    ItemStack stack = te.getItem();
    if (stack.isEmpty()) {
        return;
    }

    RenderHelper.enableGUIStandardItemLighting();
    float factor = 4.0f;
    float f3 = 0.0075F;
    GlStateManager.translate(-0.5F, 0.5F, -0.15F);
    GlStateManager.scale(f3 * factor, -f3 * factor, 0.0001f);

    RenderItem itemRender = Minecraft.getMinecraft().getRenderItem();
    itemRender.renderItemAndEffectIntoGUI(stack, 8, 8);

    RenderHelper.enableStandardItemLighting();
}
 
Example 4
Source File: GuiAutoChisel.java    From Chisel-2 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
	super.drawGuiContainerForegroundLayer(mouseX, mouseY);

	int x = (this.width - this.xSize) / 2;
	int y = (this.height - this.ySize) / 2;

	for (Slot slot : (List<Slot>) inventorySlots.inventorySlots) {
		if (!slot.getHasStack() && mouseInside(slot, mouseX - x, mouseY - y)) {
			if (slot.slotNumber < autochisel.getSizeInventory()) {
				String tt = autochisel.getSlotTooltipUnloc(slot.slotNumber);
				if (!Strings.isNullOrEmpty(tt)) {
					this.func_146283_a(Lists.newArrayList(StatCollector.translateToLocal(tt)), mouseX - x, mouseY - y);
				}
			}
		}
	}
	RenderHelper.enableGUIStandardItemLighting();
}
 
Example 5
Source File: GuiButtonSpecial.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks){
    if(thisVisible) super.drawButton(mc, mouseX, mouseY, partialTicks);

    if(visible) {
        if(renderedStacks != null) {
            int middleX = this.x + width / 2;
            int startX = middleX - renderedStacks.length * 9 + 1;
            GL11.glEnable(GL12.GL_RESCALE_NORMAL);
            RenderHelper.enableGUIStandardItemLighting();
            for(int i = 0; i < renderedStacks.length; i++) {
                itemRenderer.renderItemAndEffectIntoGUI(renderedStacks[i], startX + i * 18, this.y + 2);
            }
            RenderHelper.disableStandardItemLighting();
            GL11.glDisable(GL12.GL_RESCALE_NORMAL);
        }
        if(resLoc != null) {
            mc.getTextureManager().bindTexture(resLoc);
            drawModalRectWithCustomSizedTexture(this.x + width / 2 - 8, this.y + 2, 0, 0, 16, 16, 16, 16);
        }
        if(enabled && !thisVisible && mouseX >= this.x && mouseY >= this.y && mouseX < this.x + width && mouseY < this.y + height) {
            Gui.drawRect(this.x, this.y, this.x + width, this.y + height, invisibleHoverColor);
        }
    }
}
 
Example 6
Source File: BlockAndItemWikiTab.java    From IGW-mod with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void renderForeground(GuiWiki gui, int mouseX, int mouseY){
    if(!drawingStack.isEmpty()) {
        GlStateManager.enableLighting();
        RenderHelper.enableGUIStandardItemLighting();
        if(drawingStack.getItem() instanceof ItemBlock) {
            gui.renderRotatingBlockIntoGUI(gui, drawingStack, 55, 58, 2.8F);
        } else {
            GL11.glPushMatrix();
            GL11.glTranslated(49, 20, 0);
            GL11.glScaled(2.2, 2.2, 2.2);
            Minecraft.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI(drawingStack, 0, 0);
            GL11.glPopMatrix();
        }
    }
}
 
Example 7
Source File: ItemChiselRenderer.java    From Chisel with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void renderItem(ItemRenderType type, ItemStack stack, Object... data)
{
    RenderHelper.enableGUIStandardItemLighting();

    renderItem.renderItemIntoGUI(Minecraft.getMinecraft().fontRenderer, Minecraft.getMinecraft().renderEngine, stack, 0, 0);

    if(stack.stackTagCompound == null) return;

    ItemStack chiselTarget = ItemStack.loadItemStackFromNBT(stack.stackTagCompound.getCompoundTag("chiselTarget"));
    if(chiselTarget == null) return;

    GL11.glPushMatrix();
    GL11.glScalef(0.65f, 0.65f, 0.65f);
    GL11.glTranslatef(-8f, -8f, 0.0f);

    renderItem.renderItemIntoGUI(Minecraft.getMinecraft().fontRenderer, Minecraft.getMinecraft().renderEngine, chiselTarget, 8, 8);

    GL11.glPopMatrix();
}
 
Example 8
Source File: OptionUtilities.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void drawIcons() {
    int x = buttonX();
    LayoutManager.drawIcon(x + 4, 4, new Rectangle4i(120, 24, 12, 12));
    x += 24;
    LayoutManager.drawIcon(x + 4, 4, new Rectangle4i(120, 12, 12, 12));
    x += 24;
    LayoutManager.drawIcon(x + 4, 4, new Rectangle4i(168, 24, 12, 12));
    x += 24;
    LayoutManager.drawIcon(x + 4, 4, new Rectangle4i(144, 12, 12, 12));
    x += 24;
    LayoutManager.drawIcon(x + 4, 4, new Rectangle4i(180, 24, 12, 12));
    x += 24;
    LayoutManager.drawIcon(x + 4, 4, new Rectangle4i(132, 12, 12, 12));
    x += 24;
    RenderHelper.enableGUIStandardItemLighting();
    GlStateManager.enableRescaleNormal();
    ItemStack sword = new ItemStack(Items.DIAMOND_SWORD);
    sword.addEnchantment(Enchantment.getEnchantmentByLocation("sharpness"), 1);
    GuiHelper.drawItem(x + 2, 2, sword);
    x += 24;
    GuiHelper.drawItem(x + 2, 2, new ItemStack(Items.POTIONITEM));
    x += 24;
    GuiHelper.drawItem(x + 2, 2, new ItemStack(Blocks.STONE));
    x += 24;
}
 
Example 9
Source File: GuiButtonSpecial.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void drawButton(Minecraft mc, int x, int y){
    if(thisVisible) super.drawButton(mc, x, y);

    if(visible) {
        if(renderedStacks != null) {
            int middleX = xPosition + width / 2;
            int startX = middleX - renderedStacks.length * 9 + 1;
            GL11.glEnable(GL12.GL_RESCALE_NORMAL);
            RenderHelper.enableGUIStandardItemLighting();
            for(int i = 0; i < renderedStacks.length; i++) {
                itemRenderer.renderItemAndEffectIntoGUI(FMLClientHandler.instance().getClient().fontRenderer, FMLClientHandler.instance().getClient().renderEngine, renderedStacks[i], startX + i * 18, yPosition + 2);
            }
            RenderHelper.disableStandardItemLighting();
            GL11.glDisable(GL12.GL_RESCALE_NORMAL);
        }
        if(resLoc != null) {
            mc.getTextureManager().bindTexture(resLoc);
            func_146110_a(xPosition + width / 2 - 8, yPosition + 2, 0, 0, 16, 16, 16, 16);
        }
        if(enabled && !thisVisible && x >= xPosition && y >= yPosition && x < xPosition + width && y < yPosition + height) {
            Gui.drawRect(xPosition, yPosition, xPosition + width, yPosition + height, invisibleHoverColor);
        }
    }
}
 
Example 10
Source File: MixinGuiInGame.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "renderTooltip", at = @At("HEAD"), cancellable = true)
private void renderTooltip(ScaledResolution sr, float partialTicks, CallbackInfo callbackInfo) {
    final HUD hud = (HUD) LiquidBounce.moduleManager.getModule(HUD.class);

    if(Minecraft.getMinecraft().getRenderViewEntity() instanceof EntityPlayer && hud.getState() && hud.blackHotbarValue.get()) {
        EntityPlayer entityPlayer = (EntityPlayer) Minecraft.getMinecraft().getRenderViewEntity();

        int middleScreen = sr.getScaledWidth() / 2;

        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GuiIngame.drawRect(middleScreen - 91, sr.getScaledHeight() - 24, middleScreen + 90, sr.getScaledHeight(), Integer.MIN_VALUE);
        GuiIngame.drawRect(middleScreen - 91 - 1 + entityPlayer.inventory.currentItem * 20 + 1, sr.getScaledHeight() - 24, middleScreen - 91 - 1 + entityPlayer.inventory.currentItem * 20 + 22, sr.getScaledHeight() - 22 - 1 + 24, Integer.MAX_VALUE);

        GlStateManager.enableRescaleNormal();
        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
        RenderHelper.enableGUIStandardItemLighting();

        for(int j = 0; j < 9; ++j) {
            int k = sr.getScaledWidth() / 2 - 90 + j * 20 + 2;
            int l = sr.getScaledHeight() - 16 - 3;
            this.renderHotbarItem(j, k, l, partialTicks, entityPlayer);
        }

        RenderHelper.disableStandardItemLighting();
        GlStateManager.disableRescaleNormal();
        GlStateManager.disableBlend();

        LiquidBounce.eventManager.callEvent(new Render2DEvent(partialTicks));
        AWTFontRenderer.Companion.garbageCollectionTick();
        callbackInfo.cancel();
    }
}
 
Example 11
Source File: MixinGuiInGame.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "renderTooltip", at = @At("HEAD"), cancellable = true)
private void renderTooltip(ScaledResolution sr, float partialTicks, CallbackInfo callbackInfo) {
    final HUD hud = (HUD) LiquidBounce.moduleManager.getModule(HUD.class);

    if (Minecraft.getMinecraft().getRenderViewEntity() instanceof EntityPlayer && hud.getState() && hud.blackHotbarValue.get()) {
        EntityPlayer entityPlayer = (EntityPlayer) Minecraft.getMinecraft().getRenderViewEntity();

        int middleScreen = sr.getScaledWidth() / 2;

        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GuiIngame.drawRect(middleScreen - 91, sr.getScaledHeight() - 24, middleScreen + 90, sr.getScaledHeight(), Integer.MIN_VALUE);
        GuiIngame.drawRect(middleScreen - 91 - 1 + entityPlayer.inventory.currentItem * 20 + 1, sr.getScaledHeight() - 24, middleScreen - 91 - 1 + entityPlayer.inventory.currentItem * 20 + 22, sr.getScaledHeight() - 22 - 1 + 24, Integer.MAX_VALUE);

        GlStateManager.enableRescaleNormal();
        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
        RenderHelper.enableGUIStandardItemLighting();

        for (int j = 0; j < 9; ++j) {
            int k = sr.getScaledWidth() / 2 - 90 + j * 20 + 2;
            int l = sr.getScaledHeight() - 16 - 3;
            this.renderHotbarItem(j, k, l, partialTicks, entityPlayer);
        }

        RenderHelper.disableStandardItemLighting();
        GlStateManager.disableRescaleNormal();
        GlStateManager.disableBlend();

        LiquidBounce.eventManager.callEvent(new Render2DEvent(partialTicks));
        AWTFontRenderer.Companion.garbageCollectionTick();
        callbackInfo.cancel();
    }
}
 
Example 12
Source File: BaseComponent.java    From OpenModsLib with MIT License 5 votes vote down vote up
protected void drawItemStack(@Nonnull ItemStack stack, int x, int y) {
	if (stack.isEmpty()) return;

	RenderHelper.enableGUIStandardItemLighting();
	final RenderItem itemRenderer = parent.getItemRenderer();
	GlStateManager.translate(0.0F, 0.0F, 32.0F);
	this.zLevel = 200.0F;
	itemRenderer.zLevel = 200.0F;

	itemRenderer.renderItemAndEffectIntoGUI(stack, x, y);
	this.zLevel = 0.0F;
	itemRenderer.zLevel = 0.0F;
	RenderHelper.disableStandardItemLighting();
}
 
Example 13
Source File: RenderListener.java    From SkyblockAddons with MIT License 5 votes vote down vote up
private void renderItem(ItemStack item, float x, float y) {
    GlStateManager.enableRescaleNormal();
    RenderHelper.enableGUIStandardItemLighting();
    GlStateManager.enableDepth();

    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, 0);
    Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(item, 0, 0);
    GlStateManager.popMatrix();

    GlStateManager.disableDepth();
    RenderHelper.disableStandardItemLighting();
    GlStateManager.disableRescaleNormal();
}
 
Example 14
Source File: ModularUIGui.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void drawSlotContents(Slot slot) {
    GlStateManager.enableDepth();
    RenderHelper.enableGUIStandardItemLighting();
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    drawSlot(slot);
    GlStateManager.enableDepth();
    GlStateManager.enableBlend();
    GlStateManager.disableLighting();
}
 
Example 15
Source File: SurfaceHelper.java    From ForgeHax with MIT License 5 votes vote down vote up
public static void drawItem(ItemStack item, double x, double y) {
  GlStateManager.pushMatrix();
  RenderHelper.enableGUIStandardItemLighting();
  GlStateManager.disableLighting();
  GlStateManager.enableRescaleNormal();
  GlStateManager.enableColorMaterial();
  GlStateManager.enableLighting();
  MC.getRenderItem().zLevel = 100.f;
  renderItemAndEffectIntoGUI(getLocalPlayer(), item, x, y, 16.D);
  MC.getRenderItem().zLevel = 0.f;
  GlStateManager.popMatrix();
  GlStateManager.disableLighting();
  GlStateManager.enableDepth();
  GlStateManager.color(1.f, 1.f, 1.f, 1.f);
}
 
Example 16
Source File: ShowArmor.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
private void drawItemStack(ItemStack itemStack, int x, int y) {
    if (itemStack == null) {
        return;
    }
    RenderHelper.enableGUIStandardItemLighting();
    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    RenderItem.getInstance().renderItemAndEffectIntoGUI(Wrapper.INSTANCE.mc().fontRenderer, Wrapper.INSTANCE.mc().renderEngine, itemStack, x - 8, y);
    RenderItem.getInstance().renderItemOverlayIntoGUI(Wrapper.INSTANCE.mc().fontRenderer, Wrapper.INSTANCE.mc().renderEngine, itemStack, x - 8, y);
    GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    RenderHelper.disableStandardItemLighting();
}
 
Example 17
Source File: ModularUIGui.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    this.hoveredSlot = null;
    drawDefaultBackground();

    GlStateManager.disableRescaleNormal();
    RenderHelper.disableStandardItemLighting();
    GlStateManager.disableLighting();
    GlStateManager.disableDepth();

    drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);

    RenderHelper.enableGUIStandardItemLighting();
    GlStateManager.pushMatrix();
    GlStateManager.translate(guiLeft, guiTop, 0.0F);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.enableRescaleNormal();

    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

    for (int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i) {
        Slot slot = this.inventorySlots.inventorySlots.get(i);
        if (slot.isEnabled()) {
            this.drawSlotContents(slot);
        }
        if (isPointInRegion(slot.xPos, slot.yPos, 16, 16, mouseX, mouseY) && slot.isEnabled()) {
            renderSlotOverlay(slot);
            setHoveredSlot(slot);
        }
    }

    RenderHelper.disableStandardItemLighting();
    GlStateManager.popMatrix();

    drawGuiContainerForegroundLayer(mouseX, mouseY);

    GlStateManager.pushMatrix();
    GlStateManager.translate(guiLeft, guiTop, 0.0F);
    RenderHelper.enableGUIStandardItemLighting();

    MinecraftForge.EVENT_BUS.post(new GuiContainerEvent.DrawForeground(this, mouseX, mouseY));

    GlStateManager.enableDepth();
    renderItemStackOnMouse(mouseX, mouseY);
    renderReturningItemStack();

    GlStateManager.popMatrix();
    GlStateManager.enableLighting();
    RenderHelper.enableStandardItemLighting();

    renderHoveredToolTip(mouseX, mouseY);
}
 
Example 18
Source File: GuiEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Draw the template stacks from a "lockable inventory" for otherwise empty slots
 * @param inv
 */
protected void drawTemplateStacks(ItemStackHandlerLockable inv)
{
    // Draw a faint version of the template item for empty locked slots
    RenderHelper.enableGUIStandardItemLighting();
    GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
    GlStateManager.enableRescaleNormal();
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0f, 240.0f);
    this.zLevel = 100.0F;
    this.itemRender.zLevel = 100.0F;
    int invSize = inv.getSlots();

    for (int slotNum = 0; slotNum < invSize; slotNum++)
    {
        Slot slot = this.inventorySlots.getSlot(slotNum);

        if (inv.isSlotLocked(slotNum) && inv.getStackInSlot(slotNum).isEmpty())
        {
            ItemStack stack = inv.getTemplateStackInSlot(slotNum);

            if (stack.isEmpty() == false)
            {
                int x = this.guiLeft + slot.xPos;
                int y = this.guiTop + slot.yPos;
                GlStateManager.enableLighting();
                GlStateManager.enableDepth();
                GlStateManager.enableBlend();
                OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
                GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
                this.itemRender.renderItemAndEffectIntoGUI(stack, x, y);
            }
        }
    }

    this.itemRender.zLevel = 0.0F;
    this.zLevel = 0.0F;
    GlStateManager.disableBlend();
    GlStateManager.enableLighting();
    GlStateManager.enableDepth();
    RenderHelper.enableStandardItemLighting();
}
 
Example 19
Source File: OnlineCraft.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void drawScreen(int x, int y, float partialTicks) {
    craftButton.enabled = stacks[9] != null;
    super.drawScreen(x, y, partialTicks);
    GL11.glPushMatrix();
    RenderHelper.enableGUIStandardItemLighting();
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.getTextureManager(), stacks[i + j * 3], this.guiLeft + 41 + i * 18, this.guiTop + 17 + j * 18);
            itemRender.renderItemOverlayIntoGUI(this.fontRendererObj, this.mc.getTextureManager(), stacks[i + j * 3], this.guiLeft + 41 + i * 18, this.guiTop + 17 + j * 18, "");
        }
    }
    if (stacks[9] != null) {
        itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.getTextureManager(), stacks[9], this.guiLeft + 135, this.guiTop + 21);
        itemRender.renderItemOverlayIntoGUI(this.fontRendererObj, this.mc.getTextureManager(), stacks[9], this.guiLeft + 135, this.guiTop + 21, stacks[9].stackSize > 1 ? String.valueOf(stacks[9].stackSize) : "");
    }
    RenderHelper.enableStandardItemLighting();
    GL11.glPopMatrix();
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    ItemStack itemStack = null;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (this.guiLeft + 40 + i * 18 <= x && this.guiTop + 16 + j * 18 <= y && this.guiLeft + 40 + i * 18 + 18 > x && this.guiTop + 16 + j * 18 + 18 > y) {
                GL11.glColorMask(true, true, true, false);
                this.drawGradientRect(this.guiLeft + 40 + i * 18 + 1, this.guiTop + 16 + j * 18 + 1, this.guiLeft + 40 + i * 18 + 16 + 1, this.guiTop + 16 + j * 18 + 16 + 1, -2130706433, -2130706433);
                GL11.glColorMask(true, true, true, true);
                itemStack = stacks[i + j * 3];
            }
        }
    }
    craftButton.drawButton(mc, x, y);
    if (itemStack != null && Wrapper.INSTANCE.player().inventory.getItemStack() == null) {
        this.renderToolTip(itemStack, x, y);
    }
    ItemStack itemstack = Wrapper.INSTANCE.player().inventory.getItemStack();
    if (itemstack != null) {
        String s = "";
        if (itemstack.stackSize > 1) {
            s = "" + itemstack.stackSize;
        }
        GL11.glPushMatrix();
        RenderHelper.enableGUIStandardItemLighting();
        this.drawItemStack(itemstack, x - 8, y - 8, s);
        GL11.glPopMatrix();
    }
}
 
Example 20
Source File: ShulkerPreviewModule.java    From seppuku with GNU General Public License v3.0 4 votes vote down vote up
@Listener
public void onRenderTooltip(EventRenderTooltip event) {
    if (event.getItemStack() == null)
        return;

    final Minecraft mc = Minecraft.getMinecraft();

    if (event.getItemStack().getItem() instanceof ItemShulkerBox) {
        ItemStack shulker = event.getItemStack();
        NBTTagCompound tagCompound = shulker.getTagCompound();
        if (tagCompound != null && tagCompound.hasKey("BlockEntityTag", 10)) {
            NBTTagCompound blockEntityTag = tagCompound.getCompoundTag("BlockEntityTag");
            if (blockEntityTag.hasKey("Items", 9)) {
                event.setCanceled(true); // cancel rendering the old tooltip

                NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(27, ItemStack.EMPTY);
                ItemStackHelper.loadAllItems(blockEntityTag, nonnulllist); // load the itemstacks from the tag to the list

                // store mouse/event coords
                int x = event.getX();
                int y = event.getY();

                // translate to mouse x, y
                GlStateManager.translate(x + 10, y - 5, 0);

                GlStateManager.disableLighting();
                GlStateManager.disableDepth();
                // background
                RenderUtil.drawRect(-3, -mc.fontRenderer.FONT_HEIGHT - 4, 9 * 16 + 3, 3 * 16 + 3, 0x99101010);
                RenderUtil.drawRect(-2, -mc.fontRenderer.FONT_HEIGHT - 3, 9 * 16 + 2, 3 * 16 + 2, 0xFF202020);
                RenderUtil.drawRect(0, 0, 9 * 16, 3 * 16, 0xFF101010);

                // text
                mc.fontRenderer.drawStringWithShadow(shulker.getDisplayName(), 0, -mc.fontRenderer.FONT_HEIGHT - 1, 0xFFFFFFFF);

                GlStateManager.enableDepth();
                mc.getRenderItem().zLevel = 150.0F;
                RenderHelper.enableGUIStandardItemLighting();

                // loop through items in shulker inventory
                for (int i = 0; i < nonnulllist.size(); i++) {
                    ItemStack itemStack = nonnulllist.get(i);
                    int offsetX = (i % 9) * 16;
                    int offsetY = (i / 9) * 16;
                    mc.getRenderItem().renderItemAndEffectIntoGUI(itemStack, offsetX, offsetY);
                    mc.getRenderItem().renderItemOverlayIntoGUI(mc.fontRenderer, itemStack, offsetX, offsetY, null);
                }

                RenderHelper.disableStandardItemLighting();
                mc.getRenderItem().zLevel = 0.0F;
                GlStateManager.enableLighting();

                // reverse the translate
                GlStateManager.translate(-(x + 10), -(y - 5), 0);
            }
        }

        if(this.middleClick.getValue()) {
            if (Mouse.isButtonDown(2)) {
                if (!this.clicked) {
                    final BlockShulkerBox shulkerBox = (BlockShulkerBox) Block.getBlockFromItem(shulker.getItem());
                    if (shulkerBox != null) {
                        final NBTTagCompound tag = shulker.getTagCompound();
                        if (tag != null && tag.hasKey("BlockEntityTag", 10)) {
                            final NBTTagCompound entityTag = tag.getCompoundTag("BlockEntityTag");

                            final TileEntityShulkerBox te = new TileEntityShulkerBox();
                            te.setWorld(mc.world);
                            te.readFromNBT(entityTag);
                            mc.displayGuiScreen(new GuiShulkerBox(mc.player.inventory, te));
                        }
                    }
                }
                this.clicked = true;
            } else {
                this.clicked = false;
            }
        }
    }
}