use of hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint in project AstralSorcery by HellFirePvP.
the class ScreenJournalPerkTree method drawPerkTree.
private void drawPerkTree(MatrixStack renderStack, float partialTicks) {
PlayerEntity player = Minecraft.getInstance().player;
PlayerProgress progress = ResearchHelper.getClientProgress();
PlayerPerkData perkData = progress.getPerkData();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
TexturesAS.TEX_GUI_LINE_CONNECTION.bindTexture();
RenderingUtils.draw(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX, buf -> {
for (Tuple<AbstractPerk, AbstractPerk> perkConnection : PerkTree.PERK_TREE.getConnections()) {
if (!perkConnection.getA().isVisible(progress, player) || !perkConnection.getB().isVisible(progress, player)) {
continue;
}
AllocationStatus status;
int alloc = 0;
if (perkData.hasPerkAllocation(perkConnection.getA(), PerkAllocationType.UNLOCKED)) {
alloc++;
}
if (perkData.hasPerkAllocation(perkConnection.getB(), PerkAllocationType.UNLOCKED)) {
alloc++;
}
if (alloc == 2) {
status = AllocationStatus.ALLOCATED;
} else if (alloc == 1 && progress.getPerkData().hasFreeAllocationPoint(player, LogicalSide.CLIENT)) {
status = AllocationStatus.UNLOCKABLE;
} else {
status = AllocationStatus.UNALLOCATED;
}
Point.Float offsetOne = perkConnection.getA().getPoint().getOffset();
Point.Float offsetTwo = perkConnection.getB().getPoint().getOffset();
drawConnection(buf, renderStack, status, offsetOne, offsetTwo, ClientScheduler.getClientTick() + (int) offsetOne.x + (int) offsetOne.y + (int) offsetTwo.x + (int) offsetTwo.y);
}
});
RenderSystem.disableBlend();
drawBuffer.beginDrawingPerks();
List<Runnable> renderDynamic = Lists.newArrayList();
for (PerkTreePoint<?> perkPoint : PerkTree.PERK_TREE.getPerkPoints(LogicalSide.CLIENT)) {
AbstractPerk perk = perkPoint.getPerk();
if (!perk.isVisible(progress, player)) {
continue;
}
Point.Float offset = perkPoint.getOffset();
Rectangle.Float perkRect = drawPerk(drawBuffer, renderStack, perkPoint, partialTicks, ClientScheduler.getClientTick() + (int) offset.x + (int) offset.y, perkData.isPerkSealed(perk), renderDynamic);
if (perkRect != null) {
this.thisFramePerks.put(perk, perkRect);
}
}
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
drawBuffer.draw();
RenderSystem.disableBlend();
renderDynamic.forEach(Runnable::run);
this.unlockEffects.keySet().removeIf(perk -> !drawPerkUnlock(perk, renderStack, this.unlockEffects.get(perk)));
this.breakEffects.keySet().removeIf(perk -> !drawPerkSealBreak(perk, renderStack, this.breakEffects.get(perk), partialTicks));
}
use of hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint in project AstralSorcery by HellFirePvP.
the class KeyTreeConnector method mayUnlockPerk.
@Override
public boolean mayUnlockPerk(PlayerProgress progress, PlayerEntity player) {
if (!progress.getPerkData().hasFreeAllocationPoint(player, getSide(player)) || !canSee(player, progress))
return false;
PlayerPerkData perkData = progress.getPerkData();
LogicalSide side = getSide(player);
boolean hasAllAdjacent = true;
for (AbstractPerk otherPerks : PerkTree.PERK_TREE.getConnectedPerks(side, this)) {
if (!perkData.hasPerkAllocation(otherPerks, PerkAllocationType.UNLOCKED)) {
hasAllAdjacent = false;
break;
}
}
if (!hasAllAdjacent) {
return PerkTree.PERK_TREE.getPerkPoints(getSide(player)).stream().map(PerkTreePoint::getPerk).filter(perk -> perk instanceof KeyTreeConnector).anyMatch(perk -> perkData.hasPerkAllocation(perk, PerkAllocationType.UNLOCKED));
} else {
return true;
}
}
use of hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint in project AstralSorcery by HellFirePvP.
the class PreparedPerkTreeData method create.
static PreparedPerkTreeData create(Collection<LoadedPerkData> perks) {
PreparedPerkTreeData treeData = new PreparedPerkTreeData();
perks.stream().map(LoadedPerkData::getPerk).forEach(perk -> {
if (perk instanceof RootPerk) {
treeData.rootPerks.put(((RootPerk) perk).getConstellation(), (RootPerk) perk);
}
PerkTreePoint<? extends AbstractPerk> offsetPoint = perk.getPoint();
if (treeData.treePoints.contains(offsetPoint)) {
throw new IllegalArgumentException("Tried to register perk-point at already placed position: " + offsetPoint.getOffset().toString());
}
treeData.treePoints.add((PerkTreePoint<AbstractPerk>) offsetPoint);
});
perks.forEach(perkData -> {
for (ResourceLocation connection : perkData.getConnections()) {
AbstractPerk perkTo = treeData.getPerk(perk -> connection.equals(perk.getRegistryName())).orElseThrow(() -> new JsonParseException("Cannot connect to unknown perk: " + connection));
treeData.getConnector(perkTo).ifPresent(connector -> {
connector.connect(perkData.getPerk());
});
}
});
treeData.version = treeData.computeTreeHash();
return treeData;
}
use of hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint in project AstralSorcery by HellFirePvP.
the class PreparedPerkTreeData method computeTreeHash.
private long computeTreeHash() {
long[] perkHash = new long[this.treePoints.size()];
for (int i = 0; i < this.treePoints.size(); i++) {
PerkTreePoint<? extends AbstractPerk> treePoint = this.treePoints.get(i);
perkHash[i] = ((long) treePoint.getPerk().hashCode()) << 32 ^ treePoint.getOffset().hashCode();
}
long hash = 1L;
for (long element : perkHash) {
long elementHash = element ^ (element >>> 32);
hash = 31 * hash + elementHash;
}
return hash;
}
use of hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint in project AstralSorcery by HellFirePvP.
the class ClientProxy method initialize.
@Override
public void initialize() {
this.clientScheduler = new ClientScheduler();
if (!AstralSorcery.isDoingDataGeneration()) {
IReloadableResourceManager resMgr = (IReloadableResourceManager) Minecraft.getInstance().getResourceManager();
resMgr.addReloadListener(AssetLibrary.INSTANCE);
resMgr.addReloadListener(AssetPreLoader.INSTANCE);
resMgr.addReloadListener(ColorizationHelper.onReload());
resMgr.addReloadListener((stage, resourceManager, preparationsProfiler, reloadProfiler, backgroundExecutor, gameExecutor) -> stage.markCompleteAwaitingOthers(Unit.INSTANCE).thenRunAsync(() -> {
if (!SelectiveReloadStateHandler.INSTANCE.get().test(VanillaResourceType.LANGUAGES)) {
return;
}
PerkTree.PERK_TREE.getPerkPoints(LogicalSide.CLIENT).stream().map(PerkTreePoint::getPerk).forEach(AbstractPerk::clearClientTextCaches);
}));
}
this.clientConfig = new ClientConfig();
super.initialize();
this.addTomeBookmarks();
RandomWordGenerator.init();
this.clientConfig.buildConfiguration();
}
Aggregations