Search in sources :

Example 6 with EntityDamageSourceIndirect

use of net.minecraft.util.EntityDamageSourceIndirect in project SpongeCommon by SpongePowered.

the class MixinDamageSource method onSetExplosionSource.

@Inject(method = "causeExplosionDamage(Lnet/minecraft/world/Explosion;)Lnet/minecraft/util/DamageSource;", at = @At("HEAD"), cancellable = true)
private static void onSetExplosionSource(Explosion explosionIn, CallbackInfoReturnable<net.minecraft.util.DamageSource> cir) {
    if (explosionIn != null && explosionIn.exploder != null && explosionIn.world != null) {
        if (explosionIn.getExplosivePlacedBy() == null) {
            // check creator
            Entity spongeEntity = (Entity) explosionIn.exploder;
            Optional<UUID> creatorUuid = spongeEntity.getCreator();
            if (creatorUuid.isPresent()) {
                EntityPlayer player = explosionIn.world.getPlayerEntityByUUID(creatorUuid.get());
                if (player != null) {
                    EntityDamageSourceIndirect damageSource = new EntityDamageSourceIndirect("explosion.player", explosionIn.exploder, player);
                    damageSource.setDifficultyScaled().setExplosion();
                    cir.setReturnValue(damageSource);
                }
            }
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) EntityDamageSourceIndirect(net.minecraft.util.EntityDamageSourceIndirect) EntityPlayer(net.minecraft.entity.player.EntityPlayer) UUID(java.util.UUID) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 7 with EntityDamageSourceIndirect

use of net.minecraft.util.EntityDamageSourceIndirect in project takumicraft by TNTModders.

the class TakumiExplosion method doExplosionA.

/**
 * Does the first part of the explosion (destroy blocks)
 */
@Override
public void doExplosionA() {
    Set<BlockPos> set = Sets.newHashSet();
    int i = 16;
    for (int j = 0; j < 16; ++j) {
        for (int k = 0; k < 16; ++k) {
            for (int l = 0; l < 16; ++l) {
                if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
                    double d0 = j / 15.0F * 2.0F - 1.0F;
                    double d1 = k / 15.0F * 2.0F - 1.0F;
                    double d2 = l / 15.0F * 2.0F - 1.0F;
                    double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
                    d0 = d0 / d3;
                    d1 = d1 / d3;
                    d2 = d2 / d3;
                    float f = this.size * (0.7F + this.world.rand.nextFloat() * 0.6F);
                    double d4 = this.x;
                    double d6 = this.y;
                    double d8 = this.z;
                    for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
                        BlockPos blockpos = new BlockPos(d4, d6, d8);
                        IBlockState iblockstate = this.world.getBlockState(blockpos);
                        if (iblockstate.getMaterial() != Material.AIR) {
                            float f2 = this.exploder != null ? this.exploder.getExplosionResistance(this, this.world, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(world, blockpos, null, this);
                            f -= (f2 + 0.3F) * 0.3F;
                        }
                        if (f > 0.0F && (this.exploder == null || this.exploder.canExplosionDestroyBlock(this, this.world, blockpos, iblockstate, f))) {
                            set.add(blockpos);
                        }
                        d4 += d0 * 0.30000001192092896D;
                        d6 += d1 * 0.30000001192092896D;
                        d8 += d2 * 0.30000001192092896D;
                    }
                }
            }
        }
    }
    this.affectedBlockPositions.addAll(set);
    float f3 = this.size * 2.0F;
    int k1 = MathHelper.floor(this.x - f3 - 1.0D);
    int l1 = MathHelper.floor(this.x + f3 + 1.0D);
    int i2 = MathHelper.floor(this.y - f3 - 1.0D);
    int i1 = MathHelper.floor(this.y + f3 + 1.0D);
    int j2 = MathHelper.floor(this.z - f3 - 1.0D);
    int j1 = MathHelper.floor(this.z + f3 + 1.0D);
    List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB(k1, i2, j2, l1, i1, j1));
    ForgeEventFactory.onExplosionDetonate(this.world, this, list, f3);
    Vec3d vec3d = new Vec3d(this.x, this.y, this.z);
    for (Entity entity : list) {
        if (!entity.isImmuneToExplosions()) {
            double d12 = entity.getDistance(this.x, this.y, this.z) / f3;
            if (d12 <= 1.0D) {
                double d5 = entity.posX - this.x;
                double d7 = entity.posY + entity.getEyeHeight() - this.y;
                double d9 = entity.posZ - this.z;
                double d13 = MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
                if (d13 != 0.0D) {
                    d5 = d5 / d13;
                    d7 = d7 / d13;
                    d9 = d9 / d13;
                    double d14 = this.world.getBlockDensity(vec3d, entity.getEntityBoundingBox());
                    double d10 = (1.0D - d12) * d14;
                    if (exploder instanceof EntityArrow) {
                        entity.attackEntityFrom(new EntityDamageSourceIndirect("explosion", ((EntityArrow) this.exploder).shootingEntity, this.exploder).setExplosion(), (int) ((d10 * d10 + d10) / 2.0D * 7.0D * f3 + 1.0D));
                    } else {
                        entity.attackEntityFrom(new EntityDamageSource("explosion", this.exploder).setExplosion(), (int) ((d10 * d10 + d10) / 2.0D * 7.0D * f3 + 1.0D));
                    }
                    d10 = d10 * this.amp;
                    double d11 = d10;
                    if (entity instanceof EntityLivingBase) {
                        d11 = EnchantmentProtection.getBlastDamageReduction((EntityLivingBase) entity, d10);
                    }
                    entity.motionX += d5 * d11;
                    entity.motionY += d7 * d11;
                    entity.motionZ += d9 * d11;
                    if (entity instanceof EntityPlayer) {
                        EntityPlayer entityplayer = (EntityPlayer) entity;
                        if (!entityplayer.isSpectator() && (!entityplayer.isCreative() || !entityplayer.capabilities.isFlying)) {
                            this.playerKnockbackMap.put(entityplayer, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
                        }
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityDamageSourceIndirect(net.minecraft.util.EntityDamageSourceIndirect) IBlockState(net.minecraft.block.state.IBlockState) Vec3d(net.minecraft.util.math.Vec3d) EntityDamageSource(net.minecraft.util.EntityDamageSource) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

EntityDamageSourceIndirect (net.minecraft.util.EntityDamageSourceIndirect)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 EntityDamageSource (net.minecraft.util.EntityDamageSource)3 IBlockState (net.minecraft.block.state.IBlockState)2 Entity (net.minecraft.entity.Entity)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityArrow (net.minecraft.entity.projectile.EntityArrow)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 BlockPos (net.minecraft.util.math.BlockPos)2 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1