Search in sources :

Example 1 with Type

use of net.minecraft.world.phys.HitResult.Type in project Cyclic by Lothrazar.

the class ItemEvents method onProjectileImpactEvent.

@SubscribeEvent
public void onProjectileImpactEvent(ProjectileImpactEvent event) {
    Projectile arrow = event.getProjectile();
    if (arrow == null || event.getRayTraceResult() == null) {
        return;
    }
    Level world = arrow.level;
    Type hit = event.getRayTraceResult().getType();
    // getShooter
    Entity shooter = arrow.getOwner();
    if (shooter instanceof Player) {
        Player ply = (Player) shooter;
        // ply.isSprinting()
        ItemStack find = CharmUtil.getIfEnabled(ply, ItemRegistry.QUIVER_DMG.get());
        if (!find.isEmpty() && arrow instanceof AbstractArrow) {
            // ModCyclic.LOGGER.info("before " + event.getArrow().getDamage());
            AbstractArrow arroww = (AbstractArrow) arrow;
            double boost = arroww.getBaseDamage() / 2;
            arroww.setBaseDamage(arroww.getBaseDamage() + boost);
            UtilItemStack.damageItem(ply, find);
        }
        find = CharmUtil.getIfEnabled(ply, ItemRegistry.QUIVER_LIT.get());
        if (!find.isEmpty() && world.random.nextDouble() < 0.25) {
            if (hit == HitResult.Type.ENTITY && ((EntityHitResult) event.getRayTraceResult()).getEntity() instanceof LivingEntity) {
                LivingEntity target = (LivingEntity) ((EntityHitResult) event.getRayTraceResult()).getEntity();
                target.setGlowingTag(true);
                // ModCyclic.LOGGER.info(event.getEntity() + " eeeee" + event.getArrow().getDamage());
                BlockPos p = target.blockPosition();
                // lightning?
                LightningBolt lightningboltentity = EntityType.LIGHTNING_BOLT.create(world);
                lightningboltentity.moveTo(p.getX(), p.getY(), p.getZ());
                world.addFreshEntity(lightningboltentity);
                UtilItemStack.damageItem(ply, find);
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) LivingEntity(net.minecraft.world.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) UtilEntity(com.lothrazar.cyclic.util.UtilEntity) Entity(net.minecraft.world.entity.Entity) LightningBolt(net.minecraft.world.entity.LightningBolt) BuilderActionType(com.lothrazar.cyclic.item.builder.BuilderActionType) Type(net.minecraft.world.phys.HitResult.Type) EntityType(net.minecraft.world.entity.EntityType) MobSpawnType(net.minecraft.world.entity.MobSpawnType) Player(net.minecraft.world.entity.player.Player) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) UtilItemStack(com.lothrazar.cyclic.util.UtilItemStack) ItemStack(net.minecraft.world.item.ItemStack) AbstractArrow(net.minecraft.world.entity.projectile.AbstractArrow) EntityHitResult(net.minecraft.world.phys.EntityHitResult) Projectile(net.minecraft.world.entity.projectile.Projectile) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

BuilderActionType (com.lothrazar.cyclic.item.builder.BuilderActionType)1 UtilEntity (com.lothrazar.cyclic.util.UtilEntity)1 UtilItemStack (com.lothrazar.cyclic.util.UtilItemStack)1 BlockPos (net.minecraft.core.BlockPos)1 Entity (net.minecraft.world.entity.Entity)1 EntityType (net.minecraft.world.entity.EntityType)1 LightningBolt (net.minecraft.world.entity.LightningBolt)1 LivingEntity (net.minecraft.world.entity.LivingEntity)1 MobSpawnType (net.minecraft.world.entity.MobSpawnType)1 ItemEntity (net.minecraft.world.entity.item.ItemEntity)1 Player (net.minecraft.world.entity.player.Player)1 AbstractArrow (net.minecraft.world.entity.projectile.AbstractArrow)1 Projectile (net.minecraft.world.entity.projectile.Projectile)1 ItemStack (net.minecraft.world.item.ItemStack)1 Level (net.minecraft.world.level.Level)1 EntityHitResult (net.minecraft.world.phys.EntityHitResult)1 Type (net.minecraft.world.phys.HitResult.Type)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1