Search in sources :

Example 6 with EnumHand

use of net.minecraft.util.EnumHand in project ImmersiveEngineering by BluSunrize.

the class ApiUtils method consumePlayerIngredient.

public static void consumePlayerIngredient(EntityPlayer player, IngredientStack ingredient) {
    int amount = ingredient.inputSize;
    ItemStack itemstack;
    for (EnumHand hand : EnumHand.values()) {
        itemstack = player.getHeldItem(hand);
        if (ingredient.matchesItemStackIgnoringSize(itemstack)) {
            int taken = Math.min(amount, itemstack.stackSize);
            amount -= taken;
            itemstack.stackSize -= taken;
            if (itemstack.stackSize <= 0)
                player.setHeldItem(hand, null);
            if (amount <= 0)
                return;
        }
    }
    for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
        itemstack = player.inventory.getStackInSlot(i);
        if (ingredient.matchesItemStackIgnoringSize(itemstack)) {
            int taken = Math.min(amount, itemstack.stackSize);
            amount -= taken;
            itemstack.stackSize -= taken;
            if (itemstack.stackSize <= 0)
                player.inventory.setInventorySlotContents(i, null);
            if (amount <= 0)
                return;
        }
    }
}
Also used : EnumHand(net.minecraft.util.EnumHand) ItemStack(net.minecraft.item.ItemStack)

Example 7 with EnumHand

use of net.minecraft.util.EnumHand in project ImmersiveEngineering by BluSunrize.

the class ClientEventHandler method onRenderWorldLastEvent.

@SubscribeEvent
public void onRenderWorldLastEvent(RenderWorldLastEvent event) {
    //Overlay renderer for the sample drill
    boolean chunkBorders = false;
    for (EnumHand hand : EnumHand.values()) if (OreDictionary.itemMatches(new ItemStack(IEContent.blockMetalDevice1, 1, BlockTypes_MetalDevice1.SAMPLE_DRILL.getMeta()), ClientUtils.mc().thePlayer.getHeldItem(hand), true)) {
        chunkBorders = true;
        break;
    }
    if (!chunkBorders && ClientUtils.mc().objectMouseOver != null && ClientUtils.mc().objectMouseOver.typeOfHit == Type.BLOCK && ClientUtils.mc().objectMouseOver.getBlockPos() != null && ClientUtils.mc().theWorld.getTileEntity(ClientUtils.mc().objectMouseOver.getBlockPos()) instanceof TileEntitySampleDrill)
        chunkBorders = true;
    if (chunkBorders) {
        EntityPlayer player = ClientUtils.mc().thePlayer;
        double px = TileEntityRendererDispatcher.staticPlayerX;
        double py = TileEntityRendererDispatcher.staticPlayerY;
        double pz = TileEntityRendererDispatcher.staticPlayerZ;
        int chunkX = (int) player.posX >> 4 << 4;
        int chunkZ = (int) player.posZ >> 4 << 4;
        int y = Math.min((int) player.posY - 2, player.getEntityWorld().getChunkFromBlockCoords(new BlockPos(player.posX, 0, player.posZ)).getLowestHeight());
        float h = (float) Math.max(32, player.posY - y + 4);
        Tessellator tessellator = Tessellator.getInstance();
        VertexBuffer vertexbuffer = tessellator.getBuffer();
        GlStateManager.disableTexture2D();
        GlStateManager.enableBlend();
        GlStateManager.disableCull();
        GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
        GlStateManager.shadeModel(GL11.GL_SMOOTH);
        float r = Lib.COLOUR_F_ImmersiveOrange[0];
        float g = Lib.COLOUR_F_ImmersiveOrange[1];
        float b = Lib.COLOUR_F_ImmersiveOrange[2];
        vertexbuffer.setTranslation(chunkX - px, y + 2 - py, chunkZ - pz);
        GlStateManager.glLineWidth(5f);
        vertexbuffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
        vertexbuffer.pos(0, 0, 0).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(0, h, 0).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(16, 0, 0).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(16, h, 0).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(16, 0, 16).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(16, h, 16).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(0, 0, 16).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(0, h, 16).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(0, 2, 0).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(16, 2, 0).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(0, 2, 0).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(0, 2, 16).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(0, 2, 16).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(16, 2, 16).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(16, 2, 0).color(r, g, b, .375f).endVertex();
        vertexbuffer.pos(16, 2, 16).color(r, g, b, .375f).endVertex();
        tessellator.draw();
        vertexbuffer.setTranslation(0, 0, 0);
        GlStateManager.shadeModel(GL11.GL_FLAT);
        GlStateManager.enableCull();
        GlStateManager.disableBlend();
        GlStateManager.enableTexture2D();
    }
}
Also used : EnumHand(net.minecraft.util.EnumHand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) TileEntitySampleDrill(blusunrize.immersiveengineering.common.blocks.metal.TileEntitySampleDrill) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 8 with EnumHand

use of net.minecraft.util.EnumHand in project ImmersiveEngineering by BluSunrize.

the class ClientEventHandler method onRenderOverlayPost.

@SubscribeEvent()
public void onRenderOverlayPost(RenderGameOverlayEvent.Post event) {
    if (ClientUtils.mc().thePlayer != null && event.getType() == RenderGameOverlayEvent.ElementType.TEXT) {
        EntityPlayer player = ClientUtils.mc().thePlayer;
        for (EnumHand hand : EnumHand.values()) if (player.getHeldItem(hand) != null) {
            ItemStack equipped = player.getHeldItem(hand);
            if (OreDictionary.itemMatches(new ItemStack(IEContent.itemTool, 1, 2), equipped, false) || equipped.getItem() instanceof IWireCoil) {
                if (ItemNBTHelper.hasKey(equipped, "linkingPos")) {
                    int[] link = ItemNBTHelper.getIntArray(equipped, "linkingPos");
                    if (link != null && link.length > 3) {
                        String s = I18n.format(Lib.DESC_INFO + "attachedTo", link[1], link[2], link[3]);
                        int col = WireType.ELECTRUM.getColour(null);
                        if (equipped.getItem() instanceof IWireCoil) {
                            RayTraceResult rtr = ClientUtils.mc().objectMouseOver;
                            double d = rtr != null && rtr.getBlockPos() != null ? rtr.getBlockPos().distanceSq(link[1], link[2], link[3]) : player.getDistanceSq(link[1], link[2], link[3]);
                            int max = ((IWireCoil) equipped.getItem()).getWireType(equipped).getMaxLength();
                            if (d > max * max)
                                col = 0xdd3333;
                        }
                        ClientUtils.font().drawString(s, event.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, event.getResolution().getScaledHeight() - GuiIngameForge.left_height - 20, col, true);
                    }
                }
            } else if (OreDictionary.itemMatches(equipped, new ItemStack(IEContent.itemFluorescentTube), false)) {
                String s = I18n.format("desc.ImmersiveEngineering.info.colour", "#" + ItemFluorescentTube.hexColorString(equipped));
                ClientUtils.font().drawString(s, event.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, event.getResolution().getScaledHeight() - GuiIngameForge.left_height - 20, ItemFluorescentTube.getRGBInt(equipped), true);
            } else if (equipped.getItem() instanceof ItemRevolver && equipped.getItemDamage() != 2) {
                ClientUtils.bindTexture("immersiveengineering:textures/gui/revolver.png");
                ItemStack[] bullets = ((ItemRevolver) equipped.getItem()).getBullets(equipped);
                int bulletAmount = bullets.length;
                EnumHandSide side = hand == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite();
                float dx = side == EnumHandSide.RIGHT ? event.getResolution().getScaledWidth() - 32 - 48 : 48;
                float dy = event.getResolution().getScaledHeight() - 64;
                GlStateManager.pushMatrix();
                GlStateManager.enableBlend();
                GlStateManager.translate(dx, dy, 0);
                GlStateManager.scale(.5f, .5f, 1);
                GlStateManager.color(1, 1, 1, 1);
                ClientUtils.drawTexturedRect(0, 1, 74, 74, 0 / 256f, 74 / 256f, 51 / 256f, 125 / 256f);
                if (bulletAmount >= 18)
                    ClientUtils.drawTexturedRect(47, 1, 103, 74, 74 / 256f, 177 / 256f, 51 / 256f, 125 / 256f);
                else if (bulletAmount > 8)
                    ClientUtils.drawTexturedRect(57, 1, 79, 39, 57 / 256f, 136 / 256f, 12 / 256f, 51 / 256f);
                RenderItem ir = ClientUtils.mc().getRenderItem();
                int[][] slots = ContainerRevolver.slotPositions[bulletAmount >= 18 ? 2 : bulletAmount > 8 ? 1 : 0];
                for (int i = 0; i < bulletAmount; i++) {
                    if (bullets[i] != null) {
                        int x = 0;
                        int y = 0;
                        if (i == 0) {
                            x = 29;
                            y = 3;
                        } else if (i - 1 < slots.length) {
                            x = slots[i - 1][0];
                            y = slots[i - 1][1];
                        } else {
                            int ii = i - (slots.length + 1);
                            x = ii == 0 ? 48 : ii == 1 ? 29 : ii == 3 ? 2 : 10;
                            y = ii == 1 ? 57 : ii == 3 ? 30 : ii == 4 ? 11 : 49;
                        }
                        ir.renderItemIntoGUI(bullets[i], x, y);
                    }
                }
                RenderHelper.disableStandardItemLighting();
                GlStateManager.disableBlend();
                GlStateManager.popMatrix();
            } else if (equipped.getItem() instanceof ItemRailgun) {
                int duration = 72000 - player.getItemInUseCount();
                int chargeTime = ((ItemRailgun) equipped.getItem()).getChargeTime(equipped);
                int chargeLevel = duration < 72000 ? Math.min(99, (int) (duration / (float) chargeTime * 100)) : 0;
                float scale = 2f;
                GlStateManager.pushMatrix();
                GlStateManager.translate(event.getResolution().getScaledWidth() - 80, event.getResolution().getScaledHeight() - 30, 0);
                GlStateManager.scale(scale, scale, 1);
                ClientProxy.nixieFont.drawString((chargeLevel < 10 ? "0" : "") + chargeLevel, 0, 0, Lib.colour_nixieTubeText, false);
                GlStateManager.scale(1 / scale, 1 / scale, 1);
                GlStateManager.popMatrix();
            } else if ((equipped.getItem() instanceof ItemDrill && equipped.getItemDamage() == 0) || equipped.getItem() instanceof ItemChemthrower) {
                boolean drill = equipped.getItem() instanceof ItemDrill;
                ClientUtils.bindTexture("immersiveengineering:textures/gui/hudElements.png");
                GL11.glColor4f(1, 1, 1, 1);
                float dx = event.getResolution().getScaledWidth() - 16;
                float dy = event.getResolution().getScaledHeight();
                GL11.glPushMatrix();
                GL11.glTranslated(dx, dy, 0);
                int w = 31;
                int h = 62;
                double uMin = 179 / 256f;
                double uMax = 210 / 256f;
                double vMin = 9 / 256f;
                double vMax = 71 / 256f;
                ClientUtils.drawTexturedRect(-24, -68, w, h, uMin, uMax, vMin, vMax);
                GL11.glTranslated(-23, -37, 0);
                IFluidHandler handler = FluidUtil.getFluidHandler(equipped);
                int capacity = -1;
                if (handler != null) {
                    IFluidTankProperties[] props = handler.getTankProperties();
                    if (props != null && props.length > 0)
                        capacity = props[0].getCapacity();
                }
                if (capacity > -1) {
                    FluidStack fuel = FluidUtil.getFluidContained(equipped);
                    int amount = fuel != null ? fuel.amount : 0;
                    if (!drill && player.isHandActive()) {
                        int use = player.getItemInUseMaxCount();
                        amount -= use * IEConfig.Tools.chemthrower_consumption;
                    }
                    float cap = (float) capacity;
                    float angle = 83 - (166 * amount / cap);
                    GL11.glRotatef(angle, 0, 0, 1);
                    ClientUtils.drawTexturedRect(6, -2, 24, 4, 91 / 256f, 123 / 256f, 80 / 256f, 87 / 256f);
                    GL11.glRotatef(-angle, 0, 0, 1);
                    //					for(int i=0; i<=8; i++)
                    //					{
                    //						float angle = 83-(166/8f)*i;
                    //						GL11.glRotatef(angle, 0, 0, 1);
                    //						ClientUtils.drawTexturedRect(6,-2, 24,4, 91/256f,123/256f, 80/96f,87/96f);
                    //						GL11.glRotatef(-angle, 0, 0, 1);
                    //					}
                    GL11.glTranslated(23, 37, 0);
                    if (drill) {
                        ClientUtils.drawTexturedRect(-54, -73, 66, 72, 108 / 256f, 174 / 256f, 4 / 256f, 76 / 256f);
                        RenderItem ir = ClientUtils.mc().getRenderItem();
                        ItemStack head = ((ItemDrill) equipped.getItem()).getHead(equipped);
                        if (head != null) {
                            ir.renderItemIntoGUI(head, -51, -45);
                            ir.renderItemOverlayIntoGUI(head.getItem().getFontRenderer(head), head, -51, -45, null);
                            RenderHelper.disableStandardItemLighting();
                        }
                    } else {
                        ClientUtils.drawTexturedRect(-41, -73, 53, 72, 8 / 256f, 61 / 256f, 4 / 256f, 76 / 256f);
                        boolean ignite = ItemNBTHelper.getBoolean(equipped, "ignite");
                        ClientUtils.drawTexturedRect(-32, -43, 12, 12, 66 / 256f, 78 / 256f, (ignite ? 21 : 9) / 256f, (ignite ? 33 : 21) / 256f);
                    }
                    GL11.glPopMatrix();
                }
            }
            //				else if(equipped.getItem() instanceof ItemRailgun)
            //				{
            //					float dx = event.getResolution().getScaledWidth()-32-48;
            //					float dy = event.getResolution().getScaledHeight()-40;
            //					ClientUtils.bindTexture("immersiveengineering:textures/gui/hudElements.png");
            //					GL11.glColor4f(1, 1, 1, 1);
            //					GL11.glPushMatrix();
            //					GL11.glEnable(GL11.GL_BLEND);
            //					GL11.glTranslated(dx, dy, 0);
            //
            //					int duration = player.getItemInUseDuration();
            //					int chargeTime = ((ItemRailgun)equipped.getItem()).getChargeTime(equipped);
            //					int chargeLevel = Math.min(99, (int)(duration/(float)chargeTime*100));
            //					//					ClientUtils.drawTexturedRect(0,0, 64,32, 0/256f,64/256f, 96/256f,128/256f);
            //
            //					GL11.glScalef(1.5f,1.5f,1.5f);
            //					int col = Config.getBoolean("nixietubeFont")?Lib.colour_nixieTubeText:0xffffff;
            //					ClientProxy.nixieFont.setDrawTubeFlag(false);
            //					//					ClientProxy.nixieFont.drawString((chargeLevel<10?"0"+chargeLevel:""+chargeLevel), 19,3, col);
            //					ClientProxy.nixieFont.setDrawTubeFlag(true);
            //
            //					GL11.glPopMatrix();
            //				}
            RayTraceResult mop = ClientUtils.mc().objectMouseOver;
            if (mop != null && mop.getBlockPos() != null) {
                TileEntity tileEntity = player.worldObj.getTileEntity(mop.getBlockPos());
                if (OreDictionary.itemMatches(new ItemStack(IEContent.itemTool, 1, 2), equipped, true)) {
                    int col = IEConfig.nixietubeFont ? Lib.colour_nixieTubeText : 0xffffff;
                    String[] text = null;
                    if (tileEntity instanceof IFluxReceiver) {
                        int maxStorage = ((IFluxReceiver) tileEntity).getMaxEnergyStored(mop.sideHit);
                        int storage = ((IFluxReceiver) tileEntity).getEnergyStored(mop.sideHit);
                        if (maxStorage > 0)
                            text = I18n.format(Lib.DESC_INFO + "energyStored", "<br>" + Utils.toScientificNotation(storage, "0##", 100000) + " / " + Utils.toScientificNotation(maxStorage, "0##", 100000)).split("<br>");
                    } else //						}
                    if (mop.entityHit instanceof IFluxReceiver) {
                        int maxStorage = ((IFluxReceiver) mop.entityHit).getMaxEnergyStored(null);
                        int storage = ((IFluxReceiver) mop.entityHit).getEnergyStored(null);
                        if (maxStorage > 0)
                            text = I18n.format(Lib.DESC_INFO + "energyStored", "<br>" + Utils.toScientificNotation(storage, "0##", 100000) + " / " + Utils.toScientificNotation(maxStorage, "0##", 100000)).split("<br>");
                    }
                    if (text != null) {
                        if (player.worldObj.getTotalWorldTime() % 20 == 0) {
                            ImmersiveEngineering.packetHandler.sendToServer(new MessageRequestBlockUpdate(player.dimension, mop.getBlockPos()));
                        }
                        int i = 0;
                        for (String s : text) if (s != null) {
                            int w = ClientProxy.nixieFontOptional.getStringWidth(s);
                            ClientProxy.nixieFontOptional.drawString(s, event.getResolution().getScaledWidth() / 2 - w / 2, event.getResolution().getScaledHeight() / 2 - 4 - text.length * (ClientProxy.nixieFontOptional.FONT_HEIGHT + 2) + (i++) * (ClientProxy.nixieFontOptional.FONT_HEIGHT + 2), col, true);
                        }
                    }
                }
            }
        }
        if (ClientUtils.mc().objectMouseOver != null) {
            boolean hammer = player.getHeldItem(EnumHand.MAIN_HAND) != null && Utils.isHammer(player.getHeldItem(EnumHand.MAIN_HAND));
            RayTraceResult mop = ClientUtils.mc().objectMouseOver;
            if (mop != null && mop.getBlockPos() != null) {
                TileEntity tileEntity = player.worldObj.getTileEntity(mop.getBlockPos());
                if (tileEntity instanceof IBlockOverlayText) {
                    IBlockOverlayText overlayBlock = (IBlockOverlayText) tileEntity;
                    String[] text = overlayBlock.getOverlayText(ClientUtils.mc().thePlayer, mop, hammer);
                    boolean useNixie = overlayBlock.useNixieFont(ClientUtils.mc().thePlayer, mop);
                    if (text != null && text.length > 0) {
                        FontRenderer font = useNixie ? ClientProxy.nixieFontOptional : ClientUtils.font();
                        int col = (useNixie && IEConfig.nixietubeFont) ? Lib.colour_nixieTubeText : 0xffffff;
                        int i = 0;
                        for (String s : text) if (s != null)
                            font.drawString(s, event.getResolution().getScaledWidth() / 2 + 8, event.getResolution().getScaledHeight() / 2 + 8 + (i++) * font.FONT_HEIGHT, col, true);
                    }
                }
            }
        }
    }
}
Also used : IBlockOverlayText(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IBlockOverlayText) FluidStack(net.minecraftforge.fluids.FluidStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) IWireCoil(blusunrize.immersiveengineering.api.energy.wires.IWireCoil) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) EnumHandSide(net.minecraft.util.EnumHandSide) MessageRequestBlockUpdate(blusunrize.immersiveengineering.common.util.network.MessageRequestBlockUpdate) TileEntity(net.minecraft.tileentity.TileEntity) EnumHand(net.minecraft.util.EnumHand) IFluxReceiver(blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver) EntityPlayer(net.minecraft.entity.player.EntityPlayer) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 9 with EnumHand

use of net.minecraft.util.EnumHand in project BetterWithAddons by DaedalusGame.

the class AssortedHandler method onBlockInteract.

@SubscribeEvent
public void onBlockInteract(PlayerInteractEvent event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState blockstate = world.getBlockState(pos);
    EntityPlayer player = event.getEntityPlayer();
    if (blockstate.getBlock() instanceof BlockBanner) {
        EnumHand hand = EnumHand.MAIN_HAND;
        ItemStack stack = player.getHeldItemMainhand();
        BlockBanner bannerblock = (BlockBanner) blockstate.getBlock();
        if (stack.isEmpty() && player.isSneaking() && player.getItemStackFromSlot(EntityEquipmentSlot.HEAD).isEmpty()) {
            ItemStack bannerstack = bannerblock.getItem(world, pos, blockstate);
            player.swingArm(hand);
            world.removeTileEntity(pos);
            world.setBlockToAir(pos);
            player.setItemStackToSlot(EntityEquipmentSlot.HEAD, bannerstack);
            if (!event.getWorld().isRemote) {
                event.setCanceled(true);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumHand(net.minecraft.util.EnumHand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) BlockBanner(net.minecraft.block.BlockBanner) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 10 with EnumHand

use of net.minecraft.util.EnumHand 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)

Aggregations

ItemStack (net.minecraft.item.ItemStack)10 EnumHand (net.minecraft.util.EnumHand)10 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 BlockPos (net.minecraft.util.math.BlockPos)5 World (net.minecraft.world.World)4 IBlockState (net.minecraft.block.state.IBlockState)3 Block (net.minecraft.block.Block)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 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 IFluxReceiver (blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver)1 IWireCoil (blusunrize.immersiveengineering.api.energy.wires.IWireCoil)1 IBlockOverlayText (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IBlockOverlayText)1 TileEntitySampleDrill (blusunrize.immersiveengineering.common.blocks.metal.TileEntitySampleDrill)1