Search in sources :

Example 1 with SolarStrikeEntity

use of com.finderfeed.solarforge.SolarAbilities.SolarStrikeEntity in project SolarCraftRepository by FINDERFEED.

the class SolarStrikeAbility method cast.

@Override
public void cast(ServerPlayer entity, ServerLevel world) {
    super.cast(entity, world);
    if (allowed) {
        Vec3 vec = entity.getLookAngle().multiply(200, 200, 200);
        ClipContext ctx = new ClipContext(entity.position().add(0, 1.5, 0), entity.position().add(0, 1.5, 0).add(vec), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity);
        BlockHitResult result = world.clip(ctx);
        if (result.getType() == HitResult.Type.BLOCK) {
            BlockPos pos = result.getBlockPos();
            if (world.canSeeSky(pos.above())) {
                SolarStrikeEntity entityBolt = new SolarStrikeEntity(SolarForge.SOLAR_STRIKE_ENTITY_REG.get(), world);
                entityBolt.setPos(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);
                world.addFreshEntity(entityBolt);
            } else {
                if (!entity.isCreative()) {
                    refund(entity);
                }
            }
        }
    }
}
Also used : ClipContext(net.minecraft.world.level.ClipContext) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) SolarStrikeEntity(com.finderfeed.solarforge.SolarAbilities.SolarStrikeEntity)

Aggregations

SolarStrikeEntity (com.finderfeed.solarforge.SolarAbilities.SolarStrikeEntity)1 BlockPos (net.minecraft.core.BlockPos)1 ClipContext (net.minecraft.world.level.ClipContext)1 BlockHitResult (net.minecraft.world.phys.BlockHitResult)1 Vec3 (net.minecraft.world.phys.Vec3)1