use of hellfirepvp.astralsorcery.common.util.block.WorldBlockPos in project AstralSorcery by HellFirePvP.
the class CEffectLucerna method runStatusEffect.
@Override
public boolean runStatusEffect(World world, BlockPos pos, int mirrorAmount, ConstellationEffectProperties modified, @Nullable IMinorConstellation possibleTraitEffect) {
if (modified.isCorrupted()) {
if (world instanceof ServerWorld && DayTimeHelper.isNight(world) && rand.nextBoolean()) {
SkyHandler.getInstance().revertWorldTimeTick((ServerWorld) world);
}
return true;
}
WorldBlockPos at = WorldBlockPos.wrapServer(world, pos);
TickTokenMap.SimpleTickToken<Double> token = EventHelperSpawnDeny.spawnDenyRegions.get(at);
if (token != null && Math.abs(token.getValue() - modified.getSize()) < 1E-3) {
int next = token.getRemainingTimeout() + 80;
if (next > 400)
next = 400;
token.setTimeout(next);
rememberedTimeout = next;
} else {
if (token != null) {
token.setTimeout(0);
}
rememberedTimeout = Math.min(400, rememberedTimeout + 80);
EventHelperSpawnDeny.spawnDenyRegions.put(at, new TickTokenMap.SimpleTickToken<>(modified.getSize(), rememberedTimeout));
}
return true;
}
use of hellfirepvp.astralsorcery.common.util.block.WorldBlockPos in project AstralSorcery by HellFirePvP.
the class CEffectArmara method playEffect.
@Override
public boolean playEffect(World world, BlockPos pos, ConstellationEffectProperties properties, @Nullable IMinorConstellation trait) {
int toAdd = 2 + rand.nextInt(5);
WorldBlockPos at = WorldBlockPos.wrapServer(world, pos);
TickTokenMap.SimpleTickToken<Double> token = EventHelperSpawnDeny.spawnDenyRegions.get(at);
if (token != null) {
int next = token.getRemainingTimeout() + toAdd;
if (next > 400)
next = 400;
token.setTimeout(next);
rememberedTimeout = next;
} else {
rememberedTimeout = Math.min(400, rememberedTimeout + toAdd);
EventHelperSpawnDeny.spawnDenyRegions.put(at, new TickTokenMap.SimpleTickToken<>(properties.getSize(), rememberedTimeout));
}
if (!properties.isCorrupted()) {
List<Entity> projectiles = world.getEntitiesWithinAABB(Entity.class, BOX.offset(pos).grow(properties.getSize()));
if (!projectiles.isEmpty()) {
for (Entity e : projectiles) {
if (e.isAlive() && TechnicalEntityRegistry.INSTANCE.canAffect(e)) {
if (e instanceof ProjectileEntity) {
double xRatio = (pos.getX() + 0.5) - e.getPosX();
double zRatio = (pos.getZ() + 0.5) - e.getPosZ();
float f = MathHelper.sqrt(xRatio * xRatio + zRatio * zRatio);
Vector3 motion = new Vector3(e.getMotion());
motion.multiply(new Vector3(0.5, 1, 0.5));
motion.subtract(xRatio / f * 0.4, 0, zRatio / f * 0.4);
((ProjectileEntity) e).shoot(motion.getX(), motion.getY(), motion.getZ(), 1.5F, 0F);
} else if (e instanceof MobEntity) {
((LivingEntity) e).applyKnockback(0.4F, (pos.getX() + 0.5) - e.getPosX(), (pos.getZ() + 0.5) - e.getPosZ());
}
}
}
}
}
int potionAmplifier = CONFIG.potionAmplifier.get();
List<LivingEntity> entities = this.collectEntities(world, pos, properties);
for (LivingEntity entity : entities) {
if (entity.isAlive() && (entity instanceof MobEntity || entity instanceof PlayerEntity)) {
if (properties.isCorrupted()) {
if (entity instanceof PlayerEntity) {
continue;
}
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.SPEED, 100, potionAmplifier + 4));
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.REGENERATION, 100, potionAmplifier + 4));
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.RESISTANCE, 100, potionAmplifier + 2));
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.STRENGTH, 100, potionAmplifier + 4));
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.WATER_BREATHING, 100, potionAmplifier + 4));
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.HASTE, 100, potionAmplifier + 4));
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(EffectsAS.EFFECT_DROP_MODIFIER, 100, 5));
} else {
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.RESISTANCE, 30, Math.min(potionAmplifier, 3), true, true));
if (entity instanceof PlayerEntity) {
EntityUtils.applyPotionEffectAtHalf(entity, new EffectInstance(Effects.ABSORPTION, 30, potionAmplifier, true, false));
}
}
if (entity instanceof PlayerEntity) {
markPlayerAffected((PlayerEntity) entity);
}
}
}
return true;
}
use of hellfirepvp.astralsorcery.common.util.block.WorldBlockPos in project AstralSorcery by HellFirePvP.
the class BlockTransmutationHandler method receiveStarlight.
@Override
public void receiveStarlight(World world, Random rand, BlockPos pos, BlockState state, IWeakConstellation starlightType, double amount) {
BlockTransmutation recipe = RecipeTypesAS.TYPE_BLOCK_TRANSMUTATION.findRecipe(new BlockTransmutationContext(world, pos, state, starlightType));
if (recipe == null) {
// Wait what
return;
}
WorldBlockPos at = WorldBlockPos.wrapServer(world, pos);
ActiveTransmutation activeRecipe = runningTransmutations.get(at);
if (activeRecipe == null || !activeRecipe.recipe.equals(recipe)) {
activeRecipe = new ActiveTransmutation(recipe);
runningTransmutations.put(at, activeRecipe);
}
activeRecipe.acceptStarlight(amount);
PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.BLOCK_TRANSMUTATION_TICK).addData(buf -> ByteBufUtils.writePos(buf, pos));
PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, pos, 24));
if (activeRecipe.isFinished() && activeRecipe.finish(world, pos)) {
runningTransmutations.remove(at);
}
}
Aggregations