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();
}
}
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();
}
}
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);
}
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);
}
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;
}
}
Aggregations