Search in sources :

Example 1 with IHUDConfig

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

the class GuiHUDSettings method initGui.

@Override
@SneakyThrows(IOException.class)
public void initGui() {
    super.initGui();
    if (!player.inventory.getStackInSlot(slot).isEmpty()) {
        IHUDConfig config = new HUDConfig(player.inventory.getStackInSlot(slot));
        buttonList.add(new GuiCheckBox(0, guiLeft + 30, guiTop + 10, 12, 12, config.isChassisHUD()));
        buttonList.add(new GuiCheckBox(1, guiLeft + 30, guiTop + 30, 12, 12, config.isHUDCrafting()));
        buttonList.add(new GuiCheckBox(2, guiLeft + 30, guiTop + 50, 12, 12, config.isHUDInvSysCon()));
        buttonList.add(new GuiCheckBox(3, guiLeft + 30, guiTop + 70, 12, 12, config.isHUDPowerLevel()));
        buttonList.add(new GuiCheckBox(4, guiLeft + 30, guiTop + 90, 12, 12, config.isHUDProvider()));
        buttonList.add(new GuiCheckBox(5, guiLeft + 30, guiTop + 110, 12, 12, config.isHUDSatellite()));
    } else {
        closeGui();
    }
}
Also used : IHUDConfig(logisticspipes.interfaces.IHUDConfig) HUDConfig(logisticspipes.hud.HUDConfig) IHUDConfig(logisticspipes.interfaces.IHUDConfig) GuiCheckBox(logisticspipes.utils.gui.GuiCheckBox) SneakyThrows(lombok.SneakyThrows)

Example 2 with IHUDConfig

use of logisticspipes.interfaces.IHUDConfig 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 3 with IHUDConfig

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

the class HUDSettingsPacket method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    final ItemStack equipment = player.inventory.getStackInSlot(slot);
    if (equipment.getItem() != LPItems.hudGlasses)
        return;
    IHUDConfig config = new HUDConfig(equipment);
    switch(buttonId) {
        case 0:
            config.setChassisHUD(state);
            if (config.isChassisHUD()) {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.chassie.enabled"));
            } else {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.chassie.disabled"));
            }
            break;
        case 1:
            config.setHUDCrafting(state);
            if (config.isHUDCrafting()) {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.crafting.enabled"));
            } else {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.crafting.disabled"));
            }
            break;
        case 2:
            config.setHUDInvSysCon(state);
            if (config.isHUDInvSysCon()) {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.invsyscon.enabled"));
            } else {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.invsyscon.disabled"));
            }
            break;
        case 3:
            config.setHUDPowerJunction(state);
            if (config.isHUDPowerLevel()) {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.powerjunction.enabled"));
            } else {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.powerjunction.disabled"));
            }
            break;
        case 4:
            config.setHUDProvider(state);
            if (config.isHUDProvider()) {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.provider.enabled"));
            } else {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.provider.disabled"));
            }
            break;
        case 5:
            config.setHUDSatellite(state);
            if (config.isHUDSatellite()) {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.satellite.enabled"));
            } else {
                player.sendMessage(new TextComponentTranslation("lp.hud.config.satellite.disabled"));
            }
            break;
    }
    if (player.inventoryContainer != null) {
        player.inventoryContainer.detectAndSendChanges();
    }
}
Also used : IHUDConfig(logisticspipes.interfaces.IHUDConfig) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) HUDConfig(logisticspipes.hud.HUDConfig) IHUDConfig(logisticspipes.interfaces.IHUDConfig) ItemStack(net.minecraft.item.ItemStack)

Aggregations

HUDConfig (logisticspipes.hud.HUDConfig)3 IHUDConfig (logisticspipes.interfaces.IHUDConfig)3 ItemStack (net.minecraft.item.ItemStack)2 IHeadUpDisplayBlockRendererProvider (logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider)1 IHeadUpDisplayRendererProvider (logisticspipes.interfaces.IHeadUpDisplayRendererProvider)1 LaserData (logisticspipes.routing.LaserData)1 GuiCheckBox (logisticspipes.utils.gui.GuiCheckBox)1 ItemStackRenderer (logisticspipes.utils.item.ItemStackRenderer)1 SneakyThrows (lombok.SneakyThrows)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 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1