use of hellfirepvp.astralsorcery.common.util.PartialEffectExecutor in project AstralSorcery by HellFirePvP.
the class TileLens method doColorEffects.
private void doColorEffects() {
World world = this.getWorld();
if (!world.isRemote() && !this.occupiedConnections.isEmpty()) {
this.occupiedConnections.clear();
markForUpdate();
preventNetworkSync();
}
if (accumulatedStarlight <= 0) {
return;
}
float effectMultiplier = accumulatedStarlight * 1.4F;
accumulatedStarlight = 0;
List<BlockPos> linked = getLinkedPositions();
if (linked.isEmpty()) {
return;
}
Vector3 thisVec = new Vector3(this).add(0.5, 0.5, 0.5);
for (BlockPos linkedTo : linked) {
PartialEffectExecutor exec = new PartialEffectExecutor((1F / ((float) linked.size())) * effectMultiplier, rand);
Vector3 to = new Vector3(linkedTo).add(0.5, 0.5, 0.5);
RaytraceAssist rta = new RaytraceAssist(thisVec, to).includeEndPoint();
if (colorType.getType().doBlockInteraction()) {
if (!rta.isClear(world) && rta.positionHit() != null) {
BlockPos posHit = rta.positionHit();
BlockState stateHit = world.getBlockState(posHit);
colorType.blockInBeam(world, posHit, stateHit, exec);
if (!world.isRemote()) {
this.occupiedConnections.add(posHit);
}
} else {
if (!world.isRemote()) {
this.occupiedConnections.add(linkedTo);
}
}
}
if (colorType.getType().doEntityInteraction()) {
exec.reset();
rta.setCollectEntities(0.5);
rta.isClear(world);
List<Entity> found = rta.collectedEntities(world);
found.forEach(e -> colorType.entityInBeam(world, thisVec, to, e, exec));
}
}
}
use of hellfirepvp.astralsorcery.common.util.PartialEffectExecutor in project AstralSorcery by HellFirePvP.
the class StarlightReceiverRitualPedestal method doRitualEffect.
private void doRitualEffect(World world) {
ConstellationEffectProperties properties = this.effect.createProperties(this.getMirrorCount());
if (this.channelingTrait != null) {
this.channelingTrait.affectConstellationEffect(properties);
}
properties.multiplySize(CrystalCalculations.getRitualEffectRangeFactor(this, this.attributes));
float maxDrain = 12;
maxDrain *= CrystalCalculations.getRitualCostReductionFactor(this, this.attributes);
maxDrain /= Math.max(1F, ((float) (this.getMirrorCount() - 1)) * 0.33F);
float ritualStrength = ((float) collectedStarlight) / maxDrain;
BlockPos to = getLocationPos();
if (this.ritualLinkPos != null) {
to = this.ritualLinkPos;
}
if (this.effect instanceof ConstellationEffectStatus && this.collectedStarlight > 0) {
this.collectedStarlight = 0;
if (this.effect.getConfig().enabled.get() && ((ConstellationEffectStatus) this.effect).runStatusEffect(world, to, this.getMirrorCount(), properties, this.channelingTrait)) {
markDirty(world);
}
return;
}
float max = 10F * properties.getEffectAmplifier();
float stretch = 10F / properties.getPotency();
float executeTimes = (float) Math.atan(ritualStrength / stretch) * max;
if (properties.isCorrupted()) {
executeTimes *= Math.max(rand.nextDouble() * 1.4, 0.1);
}
PartialEffectExecutor exec = new PartialEffectExecutor(executeTimes, rand);
while (exec.canExecute()) {
exec.markExecution();
if (this.effect.getConfig().enabled.get()) {
boolean didEffectExecute;
if (this.effect.needsChunkToBeLoaded()) {
didEffectExecute = MiscUtils.executeWithChunk(world, to, to, (pos) -> {
return this.effect.playEffect(world, pos, properties, this.channelingTrait);
}, false);
} else {
didEffectExecute = this.effect.playEffect(world, to, properties, this.channelingTrait);
}
if (didEffectExecute) {
markDirty(world);
}
}
}
this.collectedStarlight = 0F;
}
Aggregations