Search in sources :

Example 1 with ItemStackRenderer

use of logisticspipes.utils.item.ItemStackRenderer in project LogisticsPipes by RS485.

the class LogisticsHUDRenderer method renderWorldRelative.

@SideOnly(Side.CLIENT)
public void renderWorldRelative(long renderTicks, float partialTick) {
    if (!displayRenderer()) {
        return;
    }
    Minecraft mc = FMLClientHandler.instance().getClient();
    EntityPlayer player = mc.player;
    if (list.size() == 0 || Math.hypot(lastXPos - player.posX, Math.hypot(lastYPos - player.posY, lastZPos - player.posZ)) > 0.5 || (renderTicks % 10 == 0 && (lastXPos != player.posX || lastYPos != player.posY || lastZPos != player.posZ)) || renderTicks % 600 == 0) {
        refreshList(player.posX, player.posY, player.posZ);
        lastXPos = player.posX;
        lastYPos = player.posY;
        lastZPos = player.posZ;
    }
    boolean cursorHandled = false;
    displayCross = false;
    IHUDConfig config;
    if (debugHUD == null) {
        config = new HUDConfig(mc.player.inventory.armorInventory.get(3));
    } else {
        config = new IHUDConfig() {

            @Override
            public boolean isHUDSatellite() {
                return false;
            }

            @Override
            public boolean isHUDProvider() {
                return false;
            }

            @Override
            public boolean isHUDPowerLevel() {
                return false;
            }

            @Override
            public boolean isHUDInvSysCon() {
                return false;
            }

            @Override
            public boolean isHUDCrafting() {
                return false;
            }

            @Override
            public boolean isChassisHUD() {
                return false;
            }

            @Override
            public void setChassisHUD(boolean state) {
            }

            @Override
            public void setHUDCrafting(boolean state) {
            }

            @Override
            public void setHUDInvSysCon(boolean state) {
            }

            @Override
            public void setHUDPowerJunction(boolean state) {
            }

            @Override
            public void setHUDProvider(boolean state) {
            }

            @Override
            public void setHUDSatellite(boolean state) {
            }
        };
    }
    IHeadUpDisplayRendererProvider thisIsLast = null;
    List<IHeadUpDisplayRendererProvider> toUse = list;
    if (debugHUD != null) {
        toUse = debugHUD.getHUDs();
    }
    for (IHeadUpDisplayRendererProvider renderer : toUse) {
        if (renderer.getRenderer() == null) {
            continue;
        }
        if (renderer.getRenderer().display(config)) {
            GL11.glPushMatrix();
            if (!cursorHandled) {
                double x = renderer.getX() + 0.5 - player.posX;
                double y = renderer.getY() + 0.5 - player.posY;
                double z = renderer.getZ() + 0.5 - player.posZ;
                if (Math.hypot(x, Math.hypot(y, z)) < 0.75 || (renderer instanceof IHeadUpDisplayBlockRendererProvider && (((IHeadUpDisplayBlockRendererProvider) renderer).isHUDInvalid() || !((IHeadUpDisplayBlockRendererProvider) renderer).isHUDExistent()))) {
                    refreshList(player.posX, player.posY, player.posZ);
                    GL11.glPopMatrix();
                    break;
                }
                int[] pos = getCursor(renderer);
                if (pos.length == 2) {
                    if (renderer.getRenderer().cursorOnWindow(pos[0], pos[1])) {
                        renderer.getRenderer().handleCursor(pos[0], pos[1]);
                        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
                            // if(FMLClientHandler.instance().getClient().player.isSneaking()) {
                            thisIsLast = renderer;
                            displayCross = true;
                        }
                        cursorHandled = true;
                    }
                }
            }
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            if (thisIsLast != renderer) {
                displayOneView(renderer, config, partialTick, false);
            }
            GL11.glPopMatrix();
        }
    }
    if (thisIsLast != null) {
        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        displayOneView(thisIsLast, config, partialTick, true);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glPopMatrix();
    }
    GL11.glPushMatrix();
    RayTraceResult box = mc.objectMouseOver;
    if (box != null && box.typeOfHit == RayTraceResult.Type.BLOCK) {
        if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
            progress = Math.min(progress + (2 * Math.max(1, (int) Math.floor((System.currentTimeMillis() - last) / 50.0D))), 100);
        } else {
            progress = Math.max(progress - (2 * Math.max(1, (int) Math.floor((System.currentTimeMillis() - last) / 50.0D))), 0);
        }
        if (progress != 0) {
            List<String> textData = SimpleServiceLocator.neiProxy.getInfoForPosition(player.world, player, box);
            if (!textData.isEmpty()) {
                double xCoord = box.getBlockPos().getX() + 0.5D;
                double yCoord = box.getBlockPos().getY() + 0.5D;
                double zCoord = box.getBlockPos().getZ() + 0.5D;
                double x = xCoord - player.prevPosX - ((player.posX - player.prevPosX) * partialTick);
                double y = yCoord - player.prevPosY - ((player.posY - player.prevPosY) * partialTick);
                double z = zCoord - player.prevPosZ - ((player.posZ - player.prevPosZ) * partialTick);
                GL11.glDisable(GL11.GL_DEPTH_TEST);
                GL11.glTranslatef((float) x, (float) y, (float) z);
                GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
                GL11.glRotatef(getAngle(z, x) + 110F, 0.0F, 0.0F, 1.0F);
                GL11.glRotatef((-1) * getAngle(Math.hypot(x + 0.8, z + 0.8), y + 0.5) + 180, 1.0F, 0.0F, 0.0F);
                double dProgress = progress / 100D;
                GL11.glTranslated(0.4D * dProgress + 0.6D, -0.2D * dProgress - 0.6D, -0.0D);
                GL11.glScalef(0.01F, 0.01F, 1F);
                int heigth = Math.max(32, 10 * textData.size() + 15);
                int width = 0;
                for (String s : textData) {
                    width = Math.max(width, mc.fontRenderer.getStringWidth(s) + 22);
                }
                width = Math.max(32, width + 15);
                GL11.glColor4b((byte) 127, (byte) 127, (byte) 127, (byte) 96);
                GuiGraphics.drawGuiBackGround(mc, (int) ((-0.5 * (width - 32)) * dProgress) - 16, (int) ((-0.5 * (heigth - 32)) * dProgress) - 16, (int) ((0.5 * (width - 32)) * dProgress) + 16, (int) ((0.5 * (heigth - 32)) * dProgress) + 16, 0, false);
                GL11.glColor4b((byte) 127, (byte) 127, (byte) 127, (byte) 127);
                if (progress == 100) {
                    GL11.glTranslated((int) ((-0.5 * (width - 32)) * dProgress) - 16, (int) ((-0.5 * (heigth - 32)) * dProgress) - 16, -0.0001D);
                    for (int i = 0; i < textData.size(); i++) {
                        mc.fontRenderer.drawString(textData.get(i), 28, 8 + i * 10, 0x000000);
                    }
                    ItemStack stack = SimpleServiceLocator.neiProxy.getItemForPosition(player.world, player, box);
                    if (!stack.isEmpty()) {
                        float scaleX = 1.5F * 0.8F;
                        float scaleY = 1.5F * 0.8F;
                        float scaleZ = -0.0001F;
                        GL11.glScalef(scaleX, scaleY, scaleZ);
                        ItemStackRenderer itemStackRenderer = new ItemStackRenderer(5, 6, 0.0F, true, true);
                        itemStackRenderer.setItemstack(stack).setDisplayAmount(DisplayAmount.NEVER);
                        itemStackRenderer.setScaleX(scaleX).setScaleY(scaleY).setScaleZ(scaleZ);
                        itemStackRenderer.renderInGui();
                    }
                }
                GL11.glEnable(GL11.GL_DEPTH_TEST);
            }
        }
    } else if (!Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
        progress = 0;
    }
    GL11.glPopMatrix();
    // Render Laser
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    // GL11.glEnable(GL11.GL_LIGHTING);
    for (LaserData data : lasers) {
        GL11.glPushMatrix();
        double x = data.getPosX() + 0.5 - player.prevPosX - ((player.posX - player.prevPosX) * partialTick);
        double y = data.getPosY() + 0.5 - player.prevPosY - ((player.posY - player.prevPosY) * partialTick);
        double z = data.getPosZ() + 0.5 - player.prevPosZ - ((player.posZ - player.prevPosZ) * partialTick);
        GL11.glTranslatef((float) x, (float) y, (float) z);
        switch(data.getDir()) {
            case NORTH:
                GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
                break;
            case SOUTH:
                GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
                break;
            case EAST:
                break;
            case WEST:
                GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
                break;
            case UP:
                GL11.glRotatef(90.0F, 0.0F, 0.0F, 1.0F);
                break;
            case DOWN:
                GL11.glRotatef(-90.0F, 0.0F, 0.0F, 1.0F);
                break;
            default:
                break;
        }
        GL11.glScalef(0.01F, 0.01F, 0.01F);
        Tessellator tessellator = Tessellator.getInstance();
        for (float i = 0; i < 6 * data.getLength(); i++) {
            setColor(i, data.getConnectionType());
            float shift = 100f * i / 6f;
            float start = 0.0f;
            if (data.isStartPipe() && i == 0) {
                start = -6.0f;
            }
            BufferBuilder buffer = tessellator.getBuffer();
            buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
            buffer.pos(19.7f + shift, 3.0f, -3.0f);
            buffer.pos(3.0f + shift + start, 3.0f, -3.0f);
            buffer.pos(3.0f + shift + start, 3.0f, 3.0f);
            buffer.pos(19.7f + shift, 3.0f, 3.0f);
            tessellator.draw();
            buffer = tessellator.getBuffer();
            buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
            buffer.pos(19.7f + shift, -3.0f, 3.0f);
            buffer.pos(3.0f + shift + start, -3.0f, 3.0f);
            buffer.pos(3.0f + shift + start, -3.0f, -3.0f);
            buffer.pos(19.7f + shift, -3.0f, -3.0f);
            tessellator.draw();
            buffer = tessellator.getBuffer();
            buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
            buffer.pos(19.7f + shift, 3.0f, 3.0f);
            buffer.pos(3.0f + shift + start, 3.0f, 3.0f);
            buffer.pos(3.0f + shift + start, -3.0f, 3.0f);
            buffer.pos(19.7f + shift, -3.0f, 3.0f);
            tessellator.draw();
            buffer = tessellator.getBuffer();
            buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
            buffer.pos(19.7f + shift, -3.0f, -3.0f);
            buffer.pos(3.0f + shift + start, -3.0f, -3.0f);
            buffer.pos(3.0f + shift + start, 3.0f, -3.0f);
            buffer.pos(19.7f + shift, 3.0f, -3.0f);
            tessellator.draw();
        }
        if (data.isStartPipe()) {
            setColor(0, data.getConnectionType());
            BufferBuilder buffer = tessellator.getBuffer();
            buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
            buffer.pos(-3.0f, 3.0f, 3.0f);
            buffer.pos(-3.0f, 3.0f, -3.0f);
            buffer.pos(-3.0f, -3.0f, -3.0f);
            buffer.pos(-3.0f, -3.0f, 3.0f);
            tessellator.draw();
        }
        if (data.isFinalPipe()) {
            setColor(6 * data.getLength() - 1, data.getConnectionType());
            BufferBuilder buffer = tessellator.getBuffer();
            buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
            buffer.pos(100.0f * data.getLength() + 3f, 3.0f, -3.0f);
            buffer.pos(100.0f * data.getLength() + 3f, 3.0f, 3.0f);
            buffer.pos(100.0f * data.getLength() + 3f, -3.0f, 3.0f);
            buffer.pos(100.0f * data.getLength() + 3f, -3.0f, -3.0f);
            tessellator.draw();
        }
        GL11.glPopMatrix();
    }
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    last = System.currentTimeMillis();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) RayTraceResult(net.minecraft.util.math.RayTraceResult) IHeadUpDisplayBlockRendererProvider(logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider) Minecraft(net.minecraft.client.Minecraft) IHUDConfig(logisticspipes.interfaces.IHUDConfig) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) HUDConfig(logisticspipes.hud.HUDConfig) IHUDConfig(logisticspipes.interfaces.IHUDConfig) EntityPlayer(net.minecraft.entity.player.EntityPlayer) LaserData(logisticspipes.routing.LaserData) ItemStack(net.minecraft.item.ItemStack) ItemStackRenderer(logisticspipes.utils.item.ItemStackRenderer) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with ItemStackRenderer

use of logisticspipes.utils.item.ItemStackRenderer in project LogisticsPipes by RS485.

the class HUDProvider method renderHeadUpDisplay.

@Override
public void renderHeadUpDisplay(double distance, boolean day, boolean shifted, Minecraft mc, IHUDConfig config) {
    if (day) {
        GL11.glColor4b((byte) 64, (byte) 64, (byte) 64, (byte) 64);
    } else {
        GL11.glColor4b((byte) 127, (byte) 127, (byte) 127, (byte) 64);
    }
    GuiGraphics.drawGuiBackGround(mc, -50, -55, 50, 55, 0, false);
    if (day) {
        GL11.glColor4b((byte) 64, (byte) 64, (byte) 64, (byte) 127);
    } else {
        GL11.glColor4b((byte) 127, (byte) 127, (byte) 127, (byte) 127);
    }
    GL11.glTranslatef(0.0F, 0.0F, -0.01F);
    super.renderHeadUpDisplay(distance, day, shifted, mc, config);
    GL11.glTranslatef(0.0F, 0.0F, -0.005F);
    float scaleX = 1.125F;
    float scaleY = 1.125F;
    float scaleZ = -0.0001F;
    GL11.glScalef(scaleX, scaleY, scaleZ);
    ItemStackRenderer itemStackRenderer = new ItemStackRenderer(0, 0, 0.0F, shifted, true);
    itemStackRenderer.setDisplayAmount(DisplayAmount.ALWAYS);
    itemStackRenderer.setScaleX(scaleX).setScaleY(scaleY).setScaleZ(scaleZ);
    ItemStackRenderer.renderItemIdentifierStackListIntoGui(pipe.getDisplayList(), null, page, -36, -37, 4, 12, 18, 18, itemStackRenderer);
    ItemStackRenderer.renderItemIdentifierStackListIntoGui(pipe.itemListOrderer, null, pageB, -36, 23, 4, 4, 18, 18, itemStackRenderer);
    GL11.glScalef(0.875F, 0.875F, -1F);
    String message = String.format("(%d/%d)", page + 1, getMaxPage());
    mc.fontRenderer.drawString(message, 9, -50, 0);
    message = String.format("(%d/%d)", pageB + 1, getMaxPageOrderer());
    mc.fontRenderer.drawString(message, 9, 23, 0);
}
Also used : ItemStackRenderer(logisticspipes.utils.item.ItemStackRenderer)

Aggregations

ItemStackRenderer (logisticspipes.utils.item.ItemStackRenderer)2 HUDConfig (logisticspipes.hud.HUDConfig)1 IHUDConfig (logisticspipes.interfaces.IHUDConfig)1 IHeadUpDisplayBlockRendererProvider (logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider)1 IHeadUpDisplayRendererProvider (logisticspipes.interfaces.IHeadUpDisplayRendererProvider)1 LaserData (logisticspipes.routing.LaserData)1 Minecraft (net.minecraft.client.Minecraft)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1