Search in sources :

Example 1 with DrawnConstellation

use of hellfirepvp.astralsorcery.common.constellation.DrawnConstellation in project AstralSorcery by HellFirePvP.

the class ScreenRefractionTable method tick.

@Override
public void tick() {
    super.tick();
    if (this.currentlyDrawnConstellations.size() >= 3) {
        List<DrawnConstellation> copyList = new ArrayList<>(this.currentlyDrawnConstellations);
        PktEngraveGlass engraveGlass = new PktEngraveGlass(this.getTile().getWorld().getDimensionKey(), this.getTile().getPos(), copyList);
        PacketChannel.CHANNEL.sendToServer(engraveGlass);
        this.currentlyDrawnConstellations.clear();
    }
}
Also used : DrawnConstellation(hellfirepvp.astralsorcery.common.constellation.DrawnConstellation) PktEngraveGlass(hellfirepvp.astralsorcery.common.network.play.client.PktEngraveGlass)

Example 2 with DrawnConstellation

use of hellfirepvp.astralsorcery.common.constellation.DrawnConstellation in project AstralSorcery by HellFirePvP.

the class ScreenRefractionTable method renderDrawnConstellations.

private void renderDrawnConstellations(MatrixStack renderStack, int mouseX, int mouseY, List<ITextProperties> tooltip) {
    ItemStack glass = this.getTile().getGlassStack();
    if (glass.isEmpty()) {
        return;
    }
    World world = this.getTile().getWorld();
    float nightPerc = DayTimeHelper.getCurrentDaytimeDistribution(world);
    WorldContext ctx = SkyHandler.getContext(world, LogicalSide.CLIENT);
    if (ctx == null || !this.getTile().doesSeeSky() || nightPerc <= 0.05F) {
        return;
    }
    EngravedStarMap map = ItemInfusedGlass.getEngraving(glass);
    if (map == null) {
        return;
    }
    for (DrawnConstellation cst : map.getDrawnConstellations()) {
        int whDrawn = DrawnConstellation.CONSTELLATION_DRAW_SIZE;
        Point offset = new Point(cst.getPoint());
        offset.translate(guiLeft, guiTop);
        offset.translate(PLACEMENT_GRID.x, PLACEMENT_GRID.y);
        offset.translate(-whDrawn, -whDrawn);
        RenderSystem.enableBlend();
        Blending.DEFAULT.apply();
        RenderingConstellationUtils.renderConstellationIntoGUI(cst.getConstellation(), renderStack, offset.x, offset.y, this.getGuiZLevel(), whDrawn * 2, whDrawn * 2, 1.6F, () -> DayTimeHelper.getCurrentDaytimeDistribution(world) * 0.8F, true, false);
        RenderSystem.disableBlend();
    }
}
Also used : DrawnConstellation(hellfirepvp.astralsorcery.common.constellation.DrawnConstellation) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) WorldContext(hellfirepvp.astralsorcery.common.constellation.world.WorldContext) EngravedStarMap(hellfirepvp.astralsorcery.common.constellation.engraving.EngravedStarMap)

Example 3 with DrawnConstellation

use of hellfirepvp.astralsorcery.common.constellation.DrawnConstellation in project AstralSorcery by HellFirePvP.

the class EngravedStarMap method deserialize.

public static EngravedStarMap deserialize(CompoundNBT tag) {
    Map<ResourceLocation, Float> distributionMap = new HashMap<>();
    ListNBT list = tag.getList("distributions", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < list.size(); i++) {
        CompoundNBT cstTag = list.getCompound(i);
        ResourceLocation constellationKey = new ResourceLocation(cstTag.getString("cst"));
        float percent = cstTag.getFloat("percent");
        if (percent > 0) {
            distributionMap.put(constellationKey, percent);
        }
    }
    List<DrawnConstellation> drawnConstellations = new ArrayList<>();
    ListNBT listDrawn = tag.getList("drawInformation", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < listDrawn.size(); i++) {
        CompoundNBT cstTag = listDrawn.getCompound(i);
        IConstellation cst = ConstellationRegistry.getConstellation(new ResourceLocation(cstTag.getString("cst")));
        Point offset = new Point(cstTag.getInt("x"), cstTag.getInt("y"));
        drawnConstellations.add(new DrawnConstellation(offset, cst));
    }
    return new EngravedStarMap(distributionMap, drawnConstellations);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation) ListNBT(net.minecraft.nbt.ListNBT) DrawnConstellation(hellfirepvp.astralsorcery.common.constellation.DrawnConstellation) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 4 with DrawnConstellation

use of hellfirepvp.astralsorcery.common.constellation.DrawnConstellation in project AstralSorcery by HellFirePvP.

the class EngravedStarMap method buildStarMap.

public static EngravedStarMap buildStarMap(World world, List<DrawnConstellation> constellations) {
    float nightPerc = DayTimeHelper.getCurrentDaytimeDistribution(world);
    Map<DrawnConstellation, List<Rectangle.Double>> cstCoordinates = new HashMap<>();
    for (DrawnConstellation drawnCst : constellations) {
        cstCoordinates.put(drawnCst, createConstellationOffsets(drawnCst));
    }
    Map<ResourceLocation, Float> distributionMap = new HashMap<>();
    for (DrawnConstellation drawn : cstCoordinates.keySet()) {
        List<Rectangle.Double> positions = cstCoordinates.get(drawn);
        Set<Rectangle.Double> foundPositions = new HashSet<>();
        for (DrawnConstellation otherCst : cstCoordinates.keySet()) {
            if (drawn.equals(otherCst) || drawn.getConstellation().equals(otherCst.getConstellation())) {
                continue;
            }
            List<Rectangle.Double> otherPositions = cstCoordinates.get(otherCst);
            for (Rectangle.Double starPos : positions) {
                for (Rectangle.Double otherStarPos : otherPositions) {
                    if (starPos.intersects(otherStarPos)) {
                        foundPositions.add(starPos);
                    }
                }
            }
        }
        IConstellation drawnConstellation = drawn.getConstellation();
        float percent = 0.1F + 0.9F * MathHelper.clamp(((foundPositions.size() * 1.5F) / positions.size()) * nightPerc, 0F, 1F);
        float existingPercent = distributionMap.getOrDefault(drawnConstellation.getRegistryName(), 0.1F);
        if (percent >= existingPercent) {
            distributionMap.put(drawnConstellation.getRegistryName(), percent);
        }
    }
    return new EngravedStarMap(distributionMap, constellations);
}
Also used : IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation) DrawnConstellation(hellfirepvp.astralsorcery.common.constellation.DrawnConstellation) ResourceLocation(net.minecraft.util.ResourceLocation) List(java.util.List)

Example 5 with DrawnConstellation

use of hellfirepvp.astralsorcery.common.constellation.DrawnConstellation in project AstralSorcery by HellFirePvP.

the class ScreenRefractionTable method tryDrop.

private void tryDrop(double mouseX, double mouseY) {
    if (this.dragging != null) {
        if (PLACEMENT_GRID.contains(mouseX - guiLeft, mouseY - guiTop)) {
            Point gridPoint = new Point((int) Math.round(mouseX), (int) Math.round(mouseY));
            gridPoint.translate(-this.guiLeft, -this.guiTop);
            gridPoint.translate(-PLACEMENT_GRID.x, -PLACEMENT_GRID.y);
            this.currentlyDrawnConstellations.add(new DrawnConstellation(gridPoint, dragging));
        }
        this.dragging = null;
    }
}
Also used : DrawnConstellation(hellfirepvp.astralsorcery.common.constellation.DrawnConstellation)

Aggregations

DrawnConstellation (hellfirepvp.astralsorcery.common.constellation.DrawnConstellation)6 IConstellation (hellfirepvp.astralsorcery.common.constellation.IConstellation)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 EngravedStarMap (hellfirepvp.astralsorcery.common.constellation.engraving.EngravedStarMap)1 WorldContext (hellfirepvp.astralsorcery.common.constellation.world.WorldContext)1 PktEngraveGlass (hellfirepvp.astralsorcery.common.network.play.client.PktEngraveGlass)1 List (java.util.List)1 ItemStack (net.minecraft.item.ItemStack)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 ListNBT (net.minecraft.nbt.ListNBT)1 World (net.minecraft.world.World)1