Search in sources :

Example 1 with IHeadUpDisplayRendererProvider

use of logisticspipes.interfaces.IHeadUpDisplayRendererProvider in project LogisticsPipes by RS485.

the class LogisticsHUDRenderer method renderWorldRelative.

public void renderWorldRelative(long renderTicks, float partialTick) {
    if (!displayRenderer()) {
        return;
    }
    Minecraft mc = FMLClientHandler.instance().getClient();
    EntityPlayer player = mc.thePlayer;
    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.thePlayer.inventory.armorInventory[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 isHUDChassie() {
                return false;
            }

            @Override
            public void setHUDChassie(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().thePlayer.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();
    MovingObjectPosition box = mc.objectMouseOver;
    if (box != null && box.typeOfHit == MovingObjectType.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 = new ArrayList<>();
            if (textData.isEmpty()) {
                textData = SimpleServiceLocator.neiProxy.getInfoForPosition(player.worldObj, player, box);
            }
            if (!textData.isEmpty()) {
                double xCoord = box.blockX + 0.5D;
                double yCoord = box.blockY + 0.5D;
                double zCoord = box.blockZ + 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 item = SimpleServiceLocator.neiProxy.getItemForPosition(player.worldObj, player, box);
                    if (item != null) {
                        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, false, true, true);
                        itemStackRenderer.setItemstack(item).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.instance;
        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;
            }
            tessellator.startDrawingQuads();
            tessellator.addVertex(19.7f + shift, 3.0f, -3.0f);
            tessellator.addVertex(3.0f + shift + start, 3.0f, -3.0f);
            tessellator.addVertex(3.0f + shift + start, 3.0f, 3.0f);
            tessellator.addVertex(19.7f + shift, 3.0f, 3.0f);
            tessellator.draw();
            tessellator.startDrawingQuads();
            tessellator.addVertex(19.7f + shift, -3.0f, 3.0f);
            tessellator.addVertex(3.0f + shift + start, -3.0f, 3.0f);
            tessellator.addVertex(3.0f + shift + start, -3.0f, -3.0f);
            tessellator.addVertex(19.7f + shift, -3.0f, -3.0f);
            tessellator.draw();
            tessellator.startDrawingQuads();
            tessellator.addVertex(19.7f + shift, 3.0f, 3.0f);
            tessellator.addVertex(3.0f + shift + start, 3.0f, 3.0f);
            tessellator.addVertex(3.0f + shift + start, -3.0f, 3.0f);
            tessellator.addVertex(19.7f + shift, -3.0f, 3.0f);
            tessellator.draw();
            tessellator.startDrawingQuads();
            tessellator.addVertex(19.7f + shift, -3.0f, -3.0f);
            tessellator.addVertex(3.0f + shift + start, -3.0f, -3.0f);
            tessellator.addVertex(3.0f + shift + start, 3.0f, -3.0f);
            tessellator.addVertex(19.7f + shift, 3.0f, -3.0f);
            tessellator.draw();
        }
        if (data.isStartPipe()) {
            setColor(0, data.getConnectionType());
            tessellator.startDrawingQuads();
            tessellator.addVertex(-3.0f, 3.0f, 3.0f);
            tessellator.addVertex(-3.0f, 3.0f, -3.0f);
            tessellator.addVertex(-3.0f, -3.0f, -3.0f);
            tessellator.addVertex(-3.0f, -3.0f, 3.0f);
            tessellator.draw();
        }
        if (data.isFinalPipe()) {
            setColor(6 * data.getLength() - 1, data.getConnectionType());
            tessellator.startDrawingQuads();
            tessellator.addVertex(100.0f * data.getLength() + 3f, 3.0f, -3.0f);
            tessellator.addVertex(100.0f * data.getLength() + 3f, 3.0f, 3.0f);
            tessellator.addVertex(100.0f * data.getLength() + 3f, -3.0f, 3.0f);
            tessellator.addVertex(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) ArrayList(java.util.ArrayList) IHeadUpDisplayBlockRendererProvider(logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider) Minecraft(net.minecraft.client.Minecraft) IHUDConfig(logisticspipes.interfaces.IHUDConfig) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) 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)

Example 2 with IHeadUpDisplayRendererProvider

use of logisticspipes.interfaces.IHeadUpDisplayRendererProvider in project LogisticsPipes by RS485.

the class LogisticsHUDRenderer method refreshList.

private void refreshList(double x, double y, double z) {
    ArrayList<Pair<Double, IHeadUpDisplayRendererProvider>> newList = new ArrayList<>();
    for (IRouter router : SimpleServiceLocator.routerManager.getRouters()) {
        if (router == null) {
            continue;
        }
        CoreRoutedPipe pipe = router.getPipe();
        if (!(pipe instanceof IHeadUpDisplayRendererProvider)) {
            continue;
        }
        if (MainProxy.getDimensionForWorld(pipe.getWorld()) == MainProxy.getDimensionForWorld(FMLClientHandler.instance().getClient().theWorld)) {
            double dis = Math.hypot(pipe.getX() - x + 0.5, Math.hypot(pipe.getY() - y + 0.5, pipe.getZ() - z + 0.5));
            if (dis < Configs.LOGISTICS_HUD_RENDER_DISTANCE && dis > 0.75) {
                newList.add(new Pair<>(dis, (IHeadUpDisplayRendererProvider) pipe));
                if (!list.contains(pipe)) {
                    ((IHeadUpDisplayRendererProvider) pipe).startWatching();
                }
            }
        }
    }
    List<IHeadUpDisplayBlockRendererProvider> remove = new ArrayList<>();
    providers.stream().filter(provider -> MainProxy.getDimensionForWorld(provider.getWorld()) == MainProxy.getDimensionForWorld(FMLClientHandler.instance().getClient().theWorld)).forEach(provider -> {
        double dis = Math.hypot(provider.getX() - x + 0.5, Math.hypot(provider.getY() - y + 0.5, provider.getZ() - z + 0.5));
        if (dis < Configs.LOGISTICS_HUD_RENDER_DISTANCE && dis > 0.75 && !provider.isHUDInvalid() && provider.isHUDExistent()) {
            newList.add(new Pair<>(dis, provider));
            if (!list.contains(provider)) {
                provider.startWatching();
            }
        } else if (provider.isHUDInvalid() || !provider.isHUDExistent()) {
            remove.add(provider);
        }
    });
    for (IHeadUpDisplayBlockRendererProvider provider : remove) {
        providers.remove(provider);
    }
    if (newList.size() < 1) {
        clearList(true);
        return;
    }
    Collections.sort(newList, (o1, o2) -> {
        if (o1.getValue1() < o2.getValue1()) {
            return -1;
        } else if (o1.getValue1() > o2.getValue1()) {
            return 1;
        } else {
            return 0;
        }
    });
    for (IHeadUpDisplayRendererProvider part : list) {
        boolean contains = false;
        for (Pair<Double, IHeadUpDisplayRendererProvider> inpart : newList) {
            if (inpart.getValue2().equals(part)) {
                contains = true;
                break;
            }
        }
        if (!contains) {
            part.stopWatching();
        }
    }
    clearList(false);
    for (Pair<Double, IHeadUpDisplayRendererProvider> part : newList) {
        list.addLast(part.getValue2());
    }
}
Also used : IRouter(logisticspipes.routing.IRouter) HUDConfig(logisticspipes.hud.HUDConfig) Keyboard(org.lwjgl.input.Keyboard) MainProxy(logisticspipes.proxy.MainProxy) Vector3d(logisticspipes.utils.math.Vector3d) Configs(logisticspipes.config.Configs) ArrayList(java.util.ArrayList) IHeadUpDisplayBlockRendererProvider(logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider) ItemStack(net.minecraft.item.ItemStack) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Minecraft(net.minecraft.client.Minecraft) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) IHUDArmor(logisticspipes.api.IHUDArmor) FMLClientHandler(cpw.mods.fml.client.FMLClientHandler) GL11(org.lwjgl.opengl.GL11) LinkedList(java.util.LinkedList) EnumSet(java.util.EnumSet) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) ScaledResolution(net.minecraft.client.gui.ScaledResolution) IHUDConfig(logisticspipes.interfaces.IHUDConfig) DisplayAmount(logisticspipes.utils.item.ItemStackRenderer.DisplayAmount) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) LaserData(logisticspipes.routing.LaserData) Tessellator(net.minecraft.client.renderer.Tessellator) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) ResourceLocation(net.minecraft.util.ResourceLocation) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) GuiGraphics(logisticspipes.utils.gui.GuiGraphics) MovingObjectType(net.minecraft.util.MovingObjectPosition.MovingObjectType) Collections(java.util.Collections) ItemStackRenderer(logisticspipes.utils.item.ItemStackRenderer) GuiIngameForge(net.minecraftforge.client.GuiIngameForge) IDebugHUDProvider(logisticspipes.interfaces.IDebugHUDProvider) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) IHeadUpDisplayBlockRendererProvider(logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) IRouter(logisticspipes.routing.IRouter) Pair(logisticspipes.utils.tuples.Pair)

Aggregations

ArrayList (java.util.ArrayList)2 HUDConfig (logisticspipes.hud.HUDConfig)2 IHUDConfig (logisticspipes.interfaces.IHUDConfig)2 IHeadUpDisplayBlockRendererProvider (logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider)2 IHeadUpDisplayRendererProvider (logisticspipes.interfaces.IHeadUpDisplayRendererProvider)2 LaserData (logisticspipes.routing.LaserData)2 ItemStackRenderer (logisticspipes.utils.item.ItemStackRenderer)2 Minecraft (net.minecraft.client.Minecraft)2 Tessellator (net.minecraft.client.renderer.Tessellator)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)2 FMLClientHandler (cpw.mods.fml.client.FMLClientHandler)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 IHUDArmor (logisticspipes.api.IHUDArmor)1 Configs (logisticspipes.config.Configs)1 IDebugHUDProvider (logisticspipes.interfaces.IDebugHUDProvider)1