Search in sources :

Example 1 with PlayerAngledConstellationInformation

use of hellfirepvp.astralsorcery.client.screen.telescope.PlayerAngledConstellationInformation in project AstralSorcery by HellFirePvP.

the class ScreenHandTelescope method drawTelescopeCell.

private void drawTelescopeCell(MatrixStack renderStack, float pTicks) {
    boolean canSeeSky = this.canObserverSeeSky(Minecraft.getInstance().player.getPosition(), 1);
    float pitch = Minecraft.getInstance().player.getPitch(pTicks);
    float angleOpacity = 0F;
    if (pitch < -60F) {
        angleOpacity = 1F;
    } else if (pitch < -10F) {
        angleOpacity = (Math.abs(pitch) - 10F) / 50F;
        if (DayTimeHelper.isNight(Minecraft.getInstance().world)) {
            angleOpacity *= angleOpacity;
        }
    }
    float brMultiplier = angleOpacity;
    RenderSystem.enableBlend();
    Blending.DEFAULT.apply();
    RenderSystem.disableAlphaTest();
    this.setBlitOffset(-10);
    this.drawSkyBackground(renderStack, pTicks, canSeeSky, angleOpacity);
    if (!this.isInitialized()) {
        this.setBlitOffset(0);
        RenderSystem.enableAlphaTest();
        Blending.DEFAULT.apply();
        RenderSystem.disableBlend();
        return;
    }
    WorldContext ctx = SkyHandler.getContext(Minecraft.getInstance().world, LogicalSide.CLIENT);
    if (ctx != null && canSeeSky) {
        Random gen = ctx.getDayRandom();
        double guiFactor = Minecraft.getInstance().getMainWindow().getGuiScaleFactor();
        float playerYaw = Minecraft.getInstance().player.rotationYaw % 360F;
        if (playerYaw < 0) {
            playerYaw += 360F;
        }
        if (playerYaw >= 180F) {
            playerYaw -= 360F;
        }
        float playerPitch = Minecraft.getInstance().player.rotationPitch;
        this.setBlitOffset(-9);
        float starSize = 5F;
        TexturesAS.TEX_STAR_1.bindTexture();
        RenderingUtils.draw(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX, buf -> {
            for (Point.Float pos : this.usedStars) {
                float brightness = 0.4F + (RenderingConstellationUtils.stdFlicker(ClientScheduler.getClientTick(), pTicks, 10 + gen.nextInt(20))) * 0.5F;
                brightness = this.multiplyStarBrightness(pTicks, brightness);
                brightness *= brMultiplier;
                RenderingGuiUtils.rect(buf, renderStack, pos.x + this.getGuiLeft(), pos.y + this.getGuiTop(), getGuiZLevel(), starSize, starSize).color(brightness, brightness, brightness, brightness).draw();
            }
        });
        this.setBlitOffset(-7);
        for (DrawArea areas : this.getVisibleDrawAreas()) {
            for (IConstellation cst : areas.getDisplayMap().keySet()) {
                ConstellationDisplayInformation info = areas.getDisplayMap().get(cst);
                info.getFrameDrawInformation().clear();
                if (!(info instanceof PlayerAngledConstellationInformation)) {
                    continue;
                }
                PlayerAngledConstellationInformation cstInfo = (PlayerAngledConstellationInformation) info;
                float diffYaw = playerYaw - cstInfo.getYaw();
                float diffPitch = playerPitch - cstInfo.getPitch();
                float maxDistance = 35F;
                if ((Math.abs(diffYaw) <= maxDistance || Math.abs(playerYaw + 360F) <= maxDistance) && Math.abs(diffPitch) <= maxDistance) {
                    float rainBr = 1F - Minecraft.getInstance().world.getRainStrength(pTicks);
                    int wPart = MathHelper.floor(this.getGuiWidth() * 0.1F);
                    int hPart = MathHelper.floor(this.getGuiHeight() * 0.1F);
                    float xFactor = diffYaw / 8F;
                    float yFactor = diffPitch / 8F;
                    GL11.glEnable(GL11.GL_SCISSOR_TEST);
                    GL11.glScissor(MathHelper.floor((this.getGuiLeft() + 5) * guiFactor), MathHelper.floor((this.getGuiTop() + 5) * guiFactor), MathHelper.floor((this.getGuiWidth() - 10) * guiFactor), MathHelper.floor((this.getGuiHeight() - 10) * guiFactor));
                    Map<StarLocation, Rectangle.Float> cstRenderInfo = RenderingConstellationUtils.renderConstellationIntoGUI(cst.getTierRenderColor(), cst, renderStack, this.getGuiLeft() + wPart + MathHelper.floor((xFactor / guiFactor) * this.getGuiWidth()), this.getGuiTop() + hPart + MathHelper.floor((yFactor / guiFactor) * this.getGuiHeight()), this.getGuiZLevel(), this.getGuiWidth() - MathHelper.floor(wPart * 1.5F), this.getGuiHeight() - MathHelper.floor(hPart * 1.5F), 2F, () -> (0.3F + 0.7F * RenderingConstellationUtils.conCFlicker(ClientScheduler.getClientTick(), pTicks, 5 + gen.nextInt(15))) * rainBr * brMultiplier, ResearchHelper.getClientProgress().hasConstellationDiscovered(cst), true);
                    GL11.glDisable(GL11.GL_SCISSOR_TEST);
                    info.getFrameDrawInformation().putAll(cstRenderInfo);
                }
            }
        }
        this.setBlitOffset(-5);
        this.renderDrawnLines(renderStack, gen, pTicks);
    }
    this.setBlitOffset(0);
    RenderSystem.enableAlphaTest();
    Blending.DEFAULT.apply();
    RenderSystem.disableBlend();
}
Also used : PlayerAngledConstellationInformation(hellfirepvp.astralsorcery.client.screen.telescope.PlayerAngledConstellationInformation) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation) StarLocation(hellfirepvp.astralsorcery.common.constellation.star.StarLocation) WorldContext(hellfirepvp.astralsorcery.common.constellation.world.WorldContext)

Example 2 with PlayerAngledConstellationInformation

use of hellfirepvp.astralsorcery.client.screen.telescope.PlayerAngledConstellationInformation in project AstralSorcery by HellFirePvP.

the class ScreenHandTelescope method fillConstellations.

@Override
protected void fillConstellations(WorldContext ctx, List<DrawArea> drawAreas) {
    Random gen = ctx.getDayRandom();
    Set<IConstellation> used = new HashSet<>();
    for (DrawArea area : drawAreas) {
        Collection<IConstellation> available = Lists.newArrayList(ctx.getActiveCelestialsHandler().getActiveConstellations());
        available.removeIf(c -> !(c instanceof IMajorConstellation) || used.contains(c) || !c.canDiscover(Minecraft.getInstance().player, ResearchHelper.getClientProgress()));
        IConstellation cst = MiscUtils.getRandomEntry(available, gen);
        if (cst instanceof IMajorConstellation) {
            used.add(cst);
            float yaw = (gen.nextFloat() * 360F) - 180F;
            float pitch = -90F + gen.nextFloat() * 25F;
            area.addConstellationToArea(cst, new PlayerAngledConstellationInformation(DEFAULT_CONSTELLATION_SIZE, yaw, pitch));
        }
    }
    int offsetX = 6, offsetY = 6;
    int width = guiWidth - 6, height = guiHeight - 6;
    for (int i = 0; i < randomStars; i++) {
        usedStars.add(new Point.Float(offsetX + gen.nextFloat() * width, offsetY + gen.nextFloat() * height));
    }
}
Also used : IMajorConstellation(hellfirepvp.astralsorcery.common.constellation.IMajorConstellation) PlayerAngledConstellationInformation(hellfirepvp.astralsorcery.client.screen.telescope.PlayerAngledConstellationInformation) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation)

Example 3 with PlayerAngledConstellationInformation

use of hellfirepvp.astralsorcery.client.screen.telescope.PlayerAngledConstellationInformation in project AstralSorcery by HellFirePvP.

the class ScreenObservatory method fillConstellations.

@Override
protected void fillConstellations(WorldContext ctx, List<DrawArea> drawAreas) {
    DrawArea area = drawAreas.get(0);
    Random gen = ctx.getDayRandom();
    Map<IConstellation, Point.Float> placed = new HashMap<>();
    for (IConstellation cst : ctx.getActiveCelestialsHandler().getActiveConstellations()) {
        Point.Float foundPoint;
        do {
            foundPoint = tryEmptyPlace(placed.values(), gen);
        } while (foundPoint == null);
        area.addConstellationToArea(cst, new PlayerAngledConstellationInformation(DEFAULT_CONSTELLATION_SIZE, foundPoint.y, foundPoint.x));
        placed.put(cst, foundPoint);
    }
    for (int i = 0; i < randomStars; i++) {
        usedStars.add(new Point.Float(FRAME_TEXTURE_SIZE + gen.nextFloat() * this.getGuiWidth(), FRAME_TEXTURE_SIZE + gen.nextFloat() * this.getGuiHeight()));
    }
}
Also used : FullScreenDrawArea(hellfirepvp.astralsorcery.client.screen.telescope.FullScreenDrawArea) PlayerAngledConstellationInformation(hellfirepvp.astralsorcery.client.screen.telescope.PlayerAngledConstellationInformation) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation)

Example 4 with PlayerAngledConstellationInformation

use of hellfirepvp.astralsorcery.client.screen.telescope.PlayerAngledConstellationInformation in project AstralSorcery by HellFirePvP.

the class ScreenObservatory method drawObservatoryScreen.

private void drawObservatoryScreen(MatrixStack renderStack, float pTicks) {
    boolean canSeeSky = this.canObserverSeeSky(this.getTile().getPos(), 2);
    double guiFactor = Minecraft.getInstance().getMainWindow().getGuiScaleFactor();
    float pitch = Minecraft.getInstance().player.getPitch(pTicks);
    float angleOpacity = 0F;
    if (pitch < -30F) {
        angleOpacity = 1F;
    } else if (pitch <= -9F) {
        angleOpacity = 0.2F + 0.8F * ((Math.abs(pitch) - 10F) / 20F);
        angleOpacity = MathHelper.sqrt(angleOpacity);
    }
    float brMultiplier = angleOpacity;
    RenderSystem.disableAlphaTest();
    RenderSystem.enableBlend();
    Blending.DEFAULT.apply();
    this.setBlitOffset(-10);
    this.drawSkyBackground(renderStack, pTicks, canSeeSky, angleOpacity);
    if (!this.isInitialized()) {
        this.setBlitOffset(0);
        Blending.DEFAULT.apply();
        RenderSystem.disableBlend();
        RenderSystem.enableAlphaTest();
        return;
    }
    float playerYaw = Minecraft.getInstance().player.rotationYaw % 360F;
    if (playerYaw < 0) {
        playerYaw += 360F;
    }
    if (playerYaw >= 180F) {
        playerYaw -= 360F;
    }
    float playerPitch = Minecraft.getInstance().player.rotationPitch;
    float rainBr = 1F - Minecraft.getInstance().world.getRainStrength(pTicks);
    WorldContext ctx = SkyHandler.getContext(Minecraft.getInstance().world, LogicalSide.CLIENT);
    if (ctx != null && canSeeSky) {
        Random gen = ctx.getDayRandom();
        this.setBlitOffset(-9);
        TexturesAS.TEX_STAR_1.bindTexture();
        RenderingUtils.draw(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX, buf -> {
            for (Point.Float star : usedStars) {
                float size = 3 + gen.nextFloat() * 3F;
                float brightness = 0.4F + (RenderingConstellationUtils.stdFlicker(ClientScheduler.getClientTick(), pTicks, 10 + gen.nextInt(20))) * 0.5F;
                brightness = this.multiplyStarBrightness(pTicks, brightness);
                brightness *= brMultiplier;
                RenderingGuiUtils.rect(buf, renderStack, this).at(FRAME_TEXTURE_SIZE + star.x, FRAME_TEXTURE_SIZE + star.y).dim(size, size).color(brightness, brightness, brightness, brightness).draw();
            }
        });
        this.setBlitOffset(-7);
        for (DrawArea area : this.getVisibleDrawAreas()) {
            for (IConstellation cst : area.getDisplayMap().keySet()) {
                ConstellationDisplayInformation info = area.getDisplayMap().get(cst);
                info.getFrameDrawInformation().clear();
                if (!(info instanceof PlayerAngledConstellationInformation)) {
                    continue;
                }
                PlayerAngledConstellationInformation cstInfo = (PlayerAngledConstellationInformation) info;
                float size = cstInfo.getRenderSize();
                float diffYaw = playerYaw - cstInfo.getYaw();
                float diffPitch = playerPitch - cstInfo.getPitch();
                if ((Math.abs(diffYaw) <= size || Math.abs(diffYaw += 360F) <= size) && Math.abs(diffPitch) <= size) {
                    int wPart = MathHelper.floor(this.getGuiWidth() * 0.1F);
                    int hPart = MathHelper.floor(this.getGuiHeight() * 0.1F);
                    float xFactor = diffYaw / 8F;
                    float yFactor = diffPitch / 8F;
                    Map<StarLocation, Rectangle.Float> cstRenderInfo = RenderingConstellationUtils.renderConstellationIntoGUI(cst, renderStack, this.getGuiLeft() + wPart + MathHelper.floor((xFactor / guiFactor) * this.getGuiWidth()), this.getGuiTop() + hPart + MathHelper.floor((yFactor / guiFactor) * this.getGuiHeight()), this.getGuiZLevel(), MathHelper.floor(this.getGuiHeight() * 0.6F), MathHelper.floor(this.getGuiHeight() * 0.6F), 2F, () -> (0.2F + 0.7F * RenderingConstellationUtils.conCFlicker(ClientScheduler.getClientTick(), pTicks, 5 + gen.nextInt(15)) * rainBr) * brMultiplier, ResearchHelper.getClientProgress().hasConstellationDiscovered(cst), true);
                    cstInfo.getFrameDrawInformation().putAll(cstRenderInfo);
                }
            }
        }
        this.setBlitOffset(-5);
        this.renderDrawnLines(renderStack, gen, pTicks);
    }
    this.setBlitOffset(0);
    Blending.DEFAULT.apply();
    RenderSystem.disableBlend();
    RenderSystem.enableAlphaTest();
}
Also used : PlayerAngledConstellationInformation(hellfirepvp.astralsorcery.client.screen.telescope.PlayerAngledConstellationInformation) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation) StarLocation(hellfirepvp.astralsorcery.common.constellation.star.StarLocation) FullScreenDrawArea(hellfirepvp.astralsorcery.client.screen.telescope.FullScreenDrawArea) WorldContext(hellfirepvp.astralsorcery.common.constellation.world.WorldContext)

Aggregations

PlayerAngledConstellationInformation (hellfirepvp.astralsorcery.client.screen.telescope.PlayerAngledConstellationInformation)4 IConstellation (hellfirepvp.astralsorcery.common.constellation.IConstellation)4 FullScreenDrawArea (hellfirepvp.astralsorcery.client.screen.telescope.FullScreenDrawArea)2 StarLocation (hellfirepvp.astralsorcery.common.constellation.star.StarLocation)2 WorldContext (hellfirepvp.astralsorcery.common.constellation.world.WorldContext)2 IMajorConstellation (hellfirepvp.astralsorcery.common.constellation.IMajorConstellation)1