use of hellfirepvp.astralsorcery.common.util.RaytraceAssist in project AstralSorcery by HellFirePvP.
the class ItemBlinkWand method onPlayerStoppedUsing.
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) {
if (worldIn.isRemote() || !(entityLiving instanceof ServerPlayerEntity)) {
return;
}
ServerPlayerEntity player = (ServerPlayerEntity) entityLiving;
BlinkMode mode = getBlinkMode(stack);
if (mode == BlinkMode.TELEPORT) {
Vector3 origin = Vector3.atEntityCorner(player).addY(0.5F);
Vector3 look = new Vector3(player.getLook(1F)).normalize().multiply(40F).add(origin);
List<BlockPos> blockLine = new ArrayList<>();
RaytraceAssist rta = new RaytraceAssist(origin, look);
rta.forEachBlockPos(pos -> {
return MiscUtils.executeWithChunk(player.getEntityWorld(), pos, () -> {
if (BlockUtils.isReplaceable(player.getEntityWorld(), pos) && BlockUtils.isReplaceable(player.getEntityWorld(), pos.up())) {
blockLine.add(pos);
return true;
}
return false;
}, false);
});
if (!blockLine.isEmpty()) {
BlockPos at = Iterables.getLast(blockLine);
if (origin.distance(at) > 5) {
if (AlignmentChargeHandler.INSTANCE.drainCharge(player, LogicalSide.SERVER, COST_PER_BLINK, false)) {
player.setPositionAndUpdate(at.getX() + 0.5, at.getY(), at.getZ() + 0.5);
if (!player.isCreative()) {
player.getCooldownTracker().setCooldown(stack.getItem(), 40);
}
}
}
}
} else if (mode == BlinkMode.LAUNCH) {
float multiplier = 0.8F;
if (!entityLiving.isElytraFlying()) {
multiplier = 2.4F;
}
float strength = 0.2F + Math.min(1F, Math.min(50, stack.getUseDuration() - timeLeft) / 50F) * multiplier;
if (strength > 0.3F) {
float chargeCost = COST_PER_DASH * 0.8F;
if (AlignmentChargeHandler.INSTANCE.drainCharge(player, LogicalSide.SERVER, chargeCost, false)) {
Vector3 motion = new Vector3(player.getLook(1F)).normalize().multiply(strength * 3F);
if (motion.getY() > 0) {
motion.setY(MathHelper.clamp(motion.getY() + (0.2F * strength), 0.2F * strength, Float.MAX_VALUE));
}
player.setMotion(motion.toVector3d());
player.fallDistance = 0F;
if (ItemMantle.getEffect(player, ConstellationsAS.vicio) != null) {
AstralSorcery.getProxy().scheduleClientside(player::startFallFlying, 2);
}
PktShootEntity pkt = new PktShootEntity(player.getEntityId(), motion);
pkt.setEffectLength(strength);
PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(worldIn, player.getPosition(), 64));
if (!player.isElytraFlying()) {
EventHelperDamageCancelling.markInvulnerableToNextDamage(player, DamageSource.FALL);
}
}
}
}
}
use of hellfirepvp.astralsorcery.common.util.RaytraceAssist in project AstralSorcery by HellFirePvP.
the class ItemBlinkWand method playUseParticles.
@OnlyIn(Dist.CLIENT)
private void playUseParticles(ItemStack stack, LivingEntity entity, int useTicks, float usagePercent) {
if (!(entity instanceof PlayerEntity)) {
return;
}
PlayerEntity player = (PlayerEntity) entity;
if (player.getCooldownTracker().hasCooldown(this)) {
return;
}
if (getBlinkMode(stack) == BlinkMode.LAUNCH) {
Vector3 look = new Vector3(entity.getLook(1F)).normalize().multiply(20);
Vector3 pos = Vector3.atEntityCorner(entity).addY(entity.getEyeHeight());
Vector3 motion = look.clone().normalize().multiply(-0.8F + random.nextFloat() * -0.5F);
Vector3 perp = look.clone().perpendicular().normalize();
for (int i = 0; i < Math.round(usagePercent * 6); i++) {
float dst = i == 0 ? random.nextFloat() * 0.4F : 0.2F + random.nextFloat() * 0.4F;
float speed = i == 0 ? 0.005F : 0.5F + random.nextFloat() * 0.5F;
float angleDeg = random.nextFloat() * 360F;
Vector3 angle = perp.clone().rotate(angleDeg, look).normalize();
Vector3 at = pos.clone().add(look.clone().multiply(0.7F + random.nextFloat() * 0.3F)).add(angle.clone().multiply(dst));
Vector3 mot = motion.clone().add(angle.clone().multiply(0.1F + random.nextFloat() * 0.15F)).multiply(speed);
FXFacingParticle p = EffectHelper.of(EffectTemplatesAS.GENERIC_PARTICLE).setOwner(entity.getUniqueID()).spawn(at).setScaleMultiplier(0.3F + random.nextFloat() * 0.3F).setAlphaMultiplier(usagePercent).setMotion(mot).color(VFXColorFunction.constant(ColorsAS.CONSTELLATION_VICIO)).setMaxAge(20 + random.nextInt(15));
if (random.nextBoolean()) {
p.color(VFXColorFunction.WHITE);
}
}
} else if (getBlinkMode(stack) == BlinkMode.TELEPORT) {
Vector3 origin = Vector3.atEntityCorner(entity).addY(0.5F);
Vector3 look = new Vector3(entity.getLook(1F)).normalize().multiply(40F).add(origin);
List<Vector3> line = new ArrayList<>();
RaytraceAssist rta = new RaytraceAssist(origin, look);
boolean clearLine = rta.forEachStep(v -> {
BlockPos pos = v.toBlockPos();
return MiscUtils.executeWithChunk(entity.getEntityWorld(), pos, () -> {
if (BlockUtils.isReplaceable(entity.getEntityWorld(), pos) && BlockUtils.isReplaceable(entity.getEntityWorld(), pos.up())) {
line.add(v);
return true;
}
return false;
}, false);
});
if (!line.isEmpty()) {
Vector3 last = Iterables.getLast(line);
for (Vector3 v : line) {
if (v == last || random.nextInt(300) == 0) {
VFXColorFunction<?> colorFn = VFXColorFunction.constant(ColorsAS.CONSTELLATION_VICIO);
float scale = 0.4F + random.nextFloat() * 0.2F;
float speed = random.nextFloat() * 0.02F;
int age = 20 + random.nextInt(15);
if (random.nextInt(3) == 0) {
colorFn = VFXColorFunction.WHITE;
}
if (v == last) {
scale *= 1.5F;
speed *= 4;
age *= 0.7F;
if (!clearLine) {
colorFn = VFXColorFunction.constant(ColorsAS.CONSTELLATION_AEVITAS);
} else {
colorFn = VFXColorFunction.constant(ColorsAS.CONSTELLATION_EVORSIO);
}
if (random.nextInt(5) == 0) {
colorFn = VFXColorFunction.WHITE;
}
}
EffectHelper.of(EffectTemplatesAS.GENERIC_PARTICLE).setOwner(entity.getUniqueID()).spawn(v).setScaleMultiplier(scale).setAlphaMultiplier(usagePercent).alpha(VFXAlphaFunction.FADE_OUT).setMotion(Vector3.random().normalize().multiply(speed)).color(colorFn).setMaxAge(age);
}
}
}
}
}
use of hellfirepvp.astralsorcery.common.util.RaytraceAssist 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.RaytraceAssist in project AstralSorcery by HellFirePvP.
the class SimpleTransmissionNode method addLink.
private void addLink(World world, BlockPos pos, boolean doRayTest, boolean oldRayState) {
this.nextPos = pos;
this.assistNext = new RaytraceAssist(thisPos, nextPos);
if (doRayTest) {
this.nextReachable = this.ignoreBlockCollision || assistNext.isClear(world);
} else {
this.nextReachable = oldRayState;
}
this.dstToNextSq = pos.distanceSq(Vector3d.copy(thisPos), false);
}
use of hellfirepvp.astralsorcery.common.util.RaytraceAssist in project AstralSorcery by HellFirePvP.
the class ChaliceHelper method findNearbyChalices.
@Nonnull
public static List<BlockPos> findNearbyChalices(World world, BlockPos origin, int distance) {
Vector3 thisVector = new Vector3(origin).add(0.5, 1.5, 0.5);
List<BlockPos> foundChalices = BlockDiscoverer.searchForBlocksAround(world, origin, MathHelper.clamp(distance, 0, 16), (w, pos, state) -> !pos.equals(origin) && state.getBlock() instanceof BlockChalice && !w.isBlockPowered(pos) && !(w.getBlockState(pos.down()).getBlock() instanceof BlockFountain));
foundChalices.removeIf(pos -> {
Vector3 chaliceVector = new Vector3(pos).add(0.5, 1.5, 0.5);
RaytraceAssist assist = new RaytraceAssist(thisVector, chaliceVector);
return !assist.isClear(world);
});
return foundChalices;
}
Aggregations