use of hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect in project AstralSorcery by HellFirePvP.
the class CelestialStrike method play.
public static void play(@Nullable LivingEntity attacker, ServerWorld world, Vector3 at, Vector3 displayPosition) {
double radius = 16D;
List<LivingEntity> livingEntities = world.getEntitiesWithinAABB(LivingEntity.class, EMPTY.grow(radius, radius / 2, radius).offset(at.toBlockPos()), EntityPredicates.IS_ALIVE);
if (attacker != null) {
livingEntities.remove(attacker);
}
DamageSource ds = CommonProxy.DAMAGE_SOURCE_STELLAR;
if (attacker != null) {
ds = DamageSource.causeMobDamage(attacker);
if (attacker instanceof PlayerEntity) {
ds = DamageSource.causePlayerDamage((PlayerEntity) attacker);
}
}
float dmg = 25F;
dmg += SkyCollectionHelper.getSkyNoiseDistribution(world, at.toBlockPos()) * 10F;
for (LivingEntity living : livingEntities) {
if ((living instanceof PlayerEntity) && (living.isSpectator() || ((PlayerEntity) living).isCreative() || (attacker != null && living.isOnSameTeam(attacker)))) {
continue;
}
float dstPerc = (float) (Vector3.atEntityCenter(living).distance(at) / radius);
dstPerc = 1F - MathHelper.clamp(dstPerc, 0F, 1F);
float dmgDealt = dstPerc * dmg;
if (dmgDealt > 0.5) {
DamageUtil.attackEntityFrom(living, ds, dmgDealt);
if (attacker != null) {
int fireAspectLevel = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FIRE_ASPECT, attacker);
if (fireAspectLevel > 0 && !living.isBurning()) {
living.setFire(fireAspectLevel * 4);
}
}
}
}
PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.CELESTIAL_STRIKE).addData(buf -> {
ByteBufUtils.writeVector(buf, displayPosition);
});
PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, at.toBlockPos(), 96));
}
use of hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect in project AstralSorcery by HellFirePvP.
the class IndependentCrystalSource method produceStarlightTick.
@Override
public float produceStarlightTick(ServerWorld world, BlockPos pos) {
if (!doesSeeSky || crystalAttributes == null) {
return 0F;
}
IWeakConstellation cst = getStarlightType();
WorldContext ctx = SkyHandler.getContext(world, LogicalSide.SERVER);
if (ctx == null || cst == null) {
return 0F;
}
if (posDistribution == -1) {
posDistribution = SkyCollectionHelper.getSkyNoiseDistribution(world, pos);
}
if (closestOtherCollector != null && rand.nextInt(40) == 0) {
PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.LIGHTNING).addData(buf -> {
ByteBufUtils.writeVector(buf, new Vector3(pos).add(0.5, 0.5, 0.5));
ByteBufUtils.writeVector(buf, new Vector3(closestOtherCollector).add(0.5, 0.5, 0.5));
buf.writeInt(this.constellation.getConstellationColor().darker().getRGB());
});
PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, pos, 32));
}
Function<Float, Float> distrFunction = getDistributionFunc();
float perc = CrystalCalculations.getCollectorCrystalCollectionRate(this);
perc *= distrFunction.apply(0.3F + (0.7F * DayTimeHelper.getCurrentDaytimeDistribution(world)));
perc *= collectionDstMultiplier;
perc *= 1 + (0.3 * posDistribution);
perc *= 0.4 + 0.6 * ctx.getDistributionHandler().getDistribution(cst);
return perc;
}
use of hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect in project AstralSorcery by HellFirePvP.
the class ItemArchitectWand method attemptPlaceBlocks.
private ActionResult<ItemStack> attemptPlaceBlocks(World world, PlayerEntity player, ItemStack held) {
Map<BlockPos, BlockState> placeStates = getPlayerPlaceableStates(player, held);
if (placeStates.isEmpty()) {
return ActionResult.resultFail(held);
}
Map<BlockState, Tuple<ItemStack, Integer>> availableStacks = MapStream.of(ItemBlockStorage.getInventoryMatching(player, held)).filter(tpl -> placeStates.containsValue(tpl.getA())).collect(Collectors.toMap(Tuple::getA, Tuple::getB));
for (BlockPos placePos : placeStates.keySet()) {
BlockState stateToPlace = placeStates.get(placePos);
Tuple<ItemStack, Integer> availableStack = availableStacks.get(stateToPlace);
if (availableStack == null) {
continue;
}
ItemStack extractable = ItemUtils.copyStackWithSize(availableStack.getA(), 1);
boolean canExtract = player.isCreative();
if (!canExtract) {
if (ItemUtils.consumeFromPlayerInventory(player, held, extractable, true)) {
canExtract = true;
}
}
if (!canExtract) {
continue;
}
if (AlignmentChargeHandler.INSTANCE.drainCharge(player, LogicalSide.SERVER, COST_PER_PLACEMENT, true) && (player.isCreative() || ItemUtils.consumeFromPlayerInventory(player, held, extractable, true)) && MiscUtils.canPlayerPlaceBlockPos(player, stateToPlace, placePos, Direction.UP) && (player.isCreative() || ItemUtils.consumeFromPlayerInventory(player, held, extractable, false)) && AlignmentChargeHandler.INSTANCE.drainCharge(player, LogicalSide.SERVER, COST_PER_PLACEMENT, false) && world.setBlockState(placePos, stateToPlace)) {
PktPlayEffect ev = new PktPlayEffect(PktPlayEffect.Type.BLOCK_EFFECT).addData(buf -> {
ByteBufUtils.writePos(buf, placePos);
ByteBufUtils.writeBlockState(buf, stateToPlace);
});
PacketChannel.CHANNEL.sendToAllAround(ev, PacketChannel.pointFromPos(world, placePos, 32));
}
}
return ActionResult.resultSuccess(held);
}
use of hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect in project AstralSorcery by HellFirePvP.
the class ConstellationEffect method sendConstellationPing.
public static void sendConstellationPing(World world, Vector3 at, IConstellation cst) {
PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.CONSTELLATION_EFFECT_PING).addData(buf -> {
ByteBufUtils.writeVector(buf, at);
ByteBufUtils.writeRegistryEntry(buf, cst);
});
PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, at.toBlockPos(), 32));
}
use of hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect in project AstralSorcery by HellFirePvP.
the class CEffectAevitas method playEffect.
@Override
public boolean playEffect(World world, BlockPos pos, ConstellationEffectProperties properties, @Nullable IMinorConstellation trait) {
boolean changed = false;
CropHelper.GrowablePlant plant = getRandomElementChanced();
if (plant != null) {
changed = MiscUtils.executeWithChunk(world, plant.getPos(), changed, (changedFlag) -> {
if (properties.isCorrupted()) {
if (world instanceof ServerWorld) {
CropHelper.HarvestablePlant harvestablePlant = CropHelper.wrapHarvestablePlant(world, plant.getPos());
if (harvestablePlant != null) {
NonNullList<ItemStack> drops = harvestablePlant.harvestDropsAndReplant((ServerWorld) world, rand, 1);
drops.forEach(drop -> ItemUtils.dropItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, drop));
changedFlag = !drops.isEmpty();
} else if (BlockUtils.breakBlockWithoutPlayer(((ServerWorld) world), plant.getPos())) {
changedFlag = true;
}
} else {
if (world.removeBlock(plant.getPos(), false)) {
changedFlag = true;
}
}
} else {
if (!plant.isValid(world)) {
removeElement(plant.getPos());
changedFlag = true;
} else {
if (plant.tryGrow(world, rand)) {
PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.CROP_GROWTH).addData(buf -> ByteBufUtils.writeVector(buf, new Vector3(plant.getPos())));
PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, plant.getPos(), 16));
changedFlag = true;
}
}
}
return changedFlag;
}, false);
}
if (this.findNewPosition(world, pos, properties).ifRight(attemptedPos -> sendConstellationPing(world, new Vector3(attemptedPos).add(0.5, 0.5, 0.5))).left().isPresent())
changed = true;
if (this.findNewPosition(world, pos, properties).ifRight(attemptedPos -> sendConstellationPing(world, new Vector3(attemptedPos).add(0.5, 0.5, 0.5))).left().isPresent())
changed = true;
int amplifier = CONFIG.potionAmplifier.get();
List<LivingEntity> entities = world.getEntitiesWithinAABB(LivingEntity.class, BOX.offset(pos).grow(properties.getSize()));
for (LivingEntity entity : entities) {
if (entity.isAlive()) {
if (properties.isCorrupted()) {
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(EffectsAS.EFFECT_BLEED, 120, amplifier * 2));
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.WEAKNESS, 120, amplifier * 3));
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.HUNGER, 120, amplifier * 4));
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.MINING_FATIGUE, 120, amplifier * 2));
} else {
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.REGENERATION, 120, amplifier));
}
if (entity instanceof PlayerEntity) {
markPlayerAffected((PlayerEntity) entity);
}
}
}
return changed;
}
Aggregations