Search in sources :

Example 1 with MeteoriteProjectile

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

the class MeteoriteAbility 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())) {
                MeteoriteProjectile proj = new MeteoriteProjectile(entity, world);
                Vector3f posVect = new Vector3f((float) entity.position().x - (float) entity.getLookAngle().x * 20, (float) entity.position().y + 64, (float) entity.position().z - (float) entity.getLookAngle().z * 20);
                proj.setPos(posVect.x(), posVect.y(), posVect.z());
                Vec3 velocity = new Vec3(pos.offset(0.5, 0, 0.5).getX() - posVect.x(), pos.offset(0.5, 0, 0.5).getY() - posVect.y(), pos.offset(0.5, 0, 0.5).getZ() - posVect.z());
                proj.setDeltaMovement(velocity.normalize());
                world.addFreshEntity(proj);
            } else {
                if (!entity.isCreative()) {
                    refund(entity);
                }
            }
        }
    }
}
Also used : MeteoriteProjectile(com.finderfeed.solarforge.SolarAbilities.meteorite.MeteoriteProjectile) ClipContext(net.minecraft.world.level.ClipContext) Vec3(net.minecraft.world.phys.Vec3) Vector3f(com.mojang.math.Vector3f) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Example 2 with MeteoriteProjectile

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

the class SolarAbilities method meteorStrike.

// 5
public static void meteorStrike(ServerLevel world, Player entity) {
    if (entity.getPersistentData().getBoolean("solar_forge_can_player_use_meteorite")) {
        if (!entity.isCreative()) {
            double mana = CapabilitySolarMana.getSolarMana(entity).orElseThrow(RuntimeException::new).getMana();
            CapabilitySolarMana.getSolarMana(entity).orElseThrow(RuntimeException::new).setMana(mana - 500);
        }
        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())) {
                MeteoriteProjectile proj = new MeteoriteProjectile(entity, world);
                Vector3f posVect = new Vector3f((float) entity.position().x - (float) entity.getLookAngle().x * 20, (float) entity.position().y + 64, (float) entity.position().z - (float) entity.getLookAngle().z * 20);
                proj.setPos(posVect.x(), posVect.y(), posVect.z());
                Vec3 velocity = new Vec3(pos.offset(0.5, 0, 0.5).getX() - posVect.x(), pos.offset(0.5, 0, 0.5).getY() - posVect.y(), pos.offset(0.5, 0, 0.5).getZ() - posVect.z());
                proj.setDeltaMovement(velocity.normalize());
                world.addFreshEntity(proj);
            }
        }
    }
}
Also used : MeteoriteProjectile(com.finderfeed.solarforge.SolarAbilities.meteorite.MeteoriteProjectile) ClipContext(net.minecraft.world.level.ClipContext) Vec3(net.minecraft.world.phys.Vec3) Vector3f(com.mojang.math.Vector3f) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Aggregations

MeteoriteProjectile (com.finderfeed.solarforge.SolarAbilities.meteorite.MeteoriteProjectile)2 Vector3f (com.mojang.math.Vector3f)2 BlockPos (net.minecraft.core.BlockPos)2 ClipContext (net.minecraft.world.level.ClipContext)2 BlockHitResult (net.minecraft.world.phys.BlockHitResult)2 Vec3 (net.minecraft.world.phys.Vec3)2