Search in sources :

Example 61 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project SpongeCommon by SpongePowered.

the class EntityUtil method getTraceEntities.

private static List<Entity> getTraceEntities(Entity source, double traceDistance, Vec3d dir, Predicate<Entity> filter) {
    AxisAlignedBB boundingBox = source.getEntityBoundingBox();
    AxisAlignedBB traceBox = boundingBox.expand(dir.x, dir.y, dir.z);
    List<Entity> entities = source.world.getEntitiesInAABBexcluding(source, traceBox.grow(1.0F, 1.0F, 1.0F), filter);
    return entities;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) MixinEntity(org.spongepowered.common.mixin.core.entity.MixinEntity) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Entity(net.minecraft.entity.Entity)

Example 62 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project SpongeCommon by SpongePowered.

the class MixinEntity method preSetOnFire.

@Inject(method = "setOnFireFromLava()V", at = @At(value = "FIELD", target = LAVA_DAMAGESOURCE_FIELD, opcode = Opcodes.GETSTATIC))
public // setOnFireFromLava
void preSetOnFire(CallbackInfo callbackInfo) {
    if (!this.world.isRemote) {
        this.originalLava = DamageSource.LAVA;
        AxisAlignedBB bb = this.getEntityBoundingBox().grow(-0.10000000149011612D, -0.4000000059604645D, -0.10000000149011612D);
        Location<World> location = DamageEventHandler.findFirstMatchingBlock((net.minecraft.entity.Entity) (Object) this, bb, block -> block.getMaterial() == Material.LAVA);
        DamageSource.LAVA = new MinecraftBlockDamageSource("lava", location).setFireDamage();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) MinecraftBlockDamageSource(org.spongepowered.common.event.damage.MinecraftBlockDamageSource) World(org.spongepowered.api.world.World) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 63 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project SpongeCommon by SpongePowered.

the class MixinExplosion method doExplosionA.

// TODO fix this whereever it was called from?
// @Override
// public Cause createCause() {
// if (this.createdCause != null) {
// return this.createdCause;
// }
// Object source;
// Object projectileSource = null;
// Object igniter = null;
// if (this.exploder == null) {
// source = getWorld().getBlock(getLocation().getPosition().toInt());
// } else {
// source = this.exploder;
// if (source instanceof Projectile) {
// projectileSource = ((Projectile) this.exploder).getShooter();
// }
// 
// // Don't use the exploder itself as igniter
// igniter = getExplosivePlacedBy();
// if (this.exploder == igniter) {
// igniter = null;
// }
// }
// 
// final Cause.Builder builder = Cause.source(source);
// if (projectileSource != null) {
// if (igniter != null) {
// builder.named(NamedCause.of("ProjectileSource", projectileSource)).named(NamedCause.of("Igniter", igniter));
// } else {
// builder.named(NamedCause.of("ProjectileSource", projectileSource));
// }
// } else if (igniter != null) {
// builder.named(NamedCause.of("Igniter", igniter));
// }
// if (PhaseTracker.ENABLED) {
// final PhaseData phaseData = PhaseTracker.getInstance().getCurrentPhaseData();
// phaseData.state.getPhase().appendExplosionCause(phaseData);
// }
// return this.createdCause = builder.build();
// }
// 
// @Override
// public Cause getCreatedCause() {
// if (this.createdCause == null) {
// createCause();
// }
// return this.createdCause;
// }
/**
 * @author gabizou - September 8th, 2016
 * @reason Rewrites to use our own hooks that will patch with forge perfectly well,
 * and allows for maximal capability.
 */
@Final
@Overwrite
public void doExplosionA() {
    // Sponge Start - If the explosion should not break blocks, don't bother calculating it
    if (this.shouldBreakBlocks) {
        // Sponge End
        Set<BlockPos> set = Sets.<BlockPos>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 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
                        double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
                        double d2 = (double) ((float) 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((net.minecraft.world.Explosion) (Object) this, this.world, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance((Entity) null);
                                f -= (f2 + 0.3F) * 0.3F;
                            }
                            if (f > 0.0F && (this.exploder == null || this.exploder.canExplosionDestroyBlock((net.minecraft.world.Explosion) (Object) 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);
    }
    // Sponge - Finish if statement
    float f3 = this.size * 2.0F;
    int k1 = MathHelper.floor(this.x - (double) f3 - 1.0D);
    int l1 = MathHelper.floor(this.x + (double) f3 + 1.0D);
    int i2 = MathHelper.floor(this.y - (double) f3 - 1.0D);
    int i1 = MathHelper.floor(this.y + (double) f3 + 1.0D);
    int j2 = MathHelper.floor(this.z - (double) f3 - 1.0D);
    int j1 = MathHelper.floor(this.z + (double) f3 + 1.0D);
    // Sponge Start - Check if this explosion should damage entities
    List<Entity> list = this.shouldDamageEntities ? this.world.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1)) : Collections.emptyList();
    // Now we can throw our Detonate Event
    final List<Location<World>> blockPositions = new ArrayList<>(this.affectedBlockPositions.size());
    final List<org.spongepowered.api.entity.Entity> entities = new ArrayList<>(list.size());
    for (BlockPos pos : this.affectedBlockPositions) {
        blockPositions.add(new Location<>((World) this.world, pos.getX(), pos.getY(), pos.getZ()));
    }
    for (Entity entity : list) {
        entities.add((org.spongepowered.api.entity.Entity) entity);
    }
    ExplosionEvent.Detonate detonate = SpongeEventFactory.createExplosionEventDetonate(Sponge.getCauseStackManager().getCurrentCause(), blockPositions, entities, this, (World) this.world);
    SpongeImpl.postEvent(detonate);
    if (detonate.isCancelled()) {
        this.affectedBlockPositions.clear();
        return;
    }
    this.affectedBlockPositions.clear();
    if (this.shouldBreakBlocks) {
        for (Location<World> worldLocation : detonate.getAffectedLocations()) {
            this.affectedBlockPositions.add(((IMixinLocation) (Object) worldLocation).getBlockPos());
        }
    }
    list.clear();
    if (this.shouldDamageEntities) {
        for (org.spongepowered.api.entity.Entity entity : detonate.getEntities()) {
            try {
                list.add(EntityUtil.toNative(entity));
            } catch (Exception e) {
            // Do nothing, a plugin tried to use the wrong entity somehow.
            }
        }
    }
    // Sponge End
    Vec3d vec3d = new Vec3d(this.x, this.y, this.z);
    for (int k2 = 0; k2 < list.size(); ++k2) {
        Entity entity = list.get(k2);
        if (!entity.isImmuneToExplosions()) {
            double d12 = entity.getDistance(this.x, this.y, this.z) / (double) f3;
            if (d12 <= 1.0D) {
                double d5 = entity.posX - this.x;
                double d7 = entity.posY + (double) entity.getEyeHeight() - this.y;
                double d9 = entity.posZ - this.z;
                double d13 = (double) MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
                if (d13 != 0.0D) {
                    d5 = d5 / d13;
                    d7 = d7 / d13;
                    d9 = d9 / d13;
                    double d14 = (double) this.world.getBlockDensity(vec3d, entity.getEntityBoundingBox());
                    double d10 = (1.0D - d12) * d14;
                    entity.attackEntityFrom(DamageSource.causeExplosionDamage((net.minecraft.world.Explosion) (Object) this), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D)));
                    double d11 = 1.0D;
                    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) ExplosionEvent(org.spongepowered.api.event.world.ExplosionEvent) ArrayList(java.util.ArrayList) World(org.spongepowered.api.world.World) BlockPos(net.minecraft.util.math.BlockPos) IBlockState(net.minecraft.block.state.IBlockState) IMixinExplosion(org.spongepowered.common.interfaces.world.IMixinExplosion) Explosion(org.spongepowered.api.world.explosion.Explosion) Vec3d(net.minecraft.util.math.Vec3d) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Location(org.spongepowered.api.world.Location) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) Overwrite(org.spongepowered.asm.mixin.Overwrite) Final(org.spongepowered.asm.mixin.Final)

Example 64 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project SpongeCommon by SpongePowered.

the class MixinWorld method collidesWithAnyBlock.

/**
 * @author gabizou - August 4th, 2016
 * @reason Inlines the isValidXZPosition check to BlockPos.
 *
 * @param bbox The AABB to check
 * @return True if the AABB collides with a block
 */
@Overwrite
public boolean collidesWithAnyBlock(AxisAlignedBB bbox) {
    List<AxisAlignedBB> list = Lists.<AxisAlignedBB>newArrayList();
    int i = MathHelper.floor(bbox.minX) - 1;
    int j = MathHelper.ceil(bbox.maxX) + 1;
    int k = MathHelper.floor(bbox.minY) - 1;
    int l = MathHelper.ceil(bbox.maxY) + 1;
    int i1 = MathHelper.floor(bbox.minZ) - 1;
    int j1 = MathHelper.ceil(bbox.maxZ) + 1;
    BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain();
    try {
        for (int k1 = i; k1 < j; ++k1) {
            for (int l1 = i1; l1 < j1; ++l1) {
                int i2 = (k1 != i && k1 != j - 1 ? 0 : 1) + (l1 != i1 && l1 != j1 - 1 ? 0 : 1);
                if (i2 != 2 && this.isBlockLoaded(blockpos$pooledmutableblockpos.setPos(k1, 64, l1))) {
                    for (int j2 = k; j2 < l; ++j2) {
                        if (i2 <= 0 || j2 != k && j2 != l - 1) {
                            blockpos$pooledmutableblockpos.setPos(k1, j2, l1);
                            // if (k1 < -30000000 || k1 >= 30000000 || l1 < -30000000 || l1 >= 30000000) // Vanilla
                            if (!((IMixinBlockPos) (Object) blockpos$pooledmutableblockpos).isValidXZPosition()) {
                                // Sponge End
                                boolean flag1 = true;
                                return flag1;
                            }
                            IBlockState iblockstate = this.getBlockState(blockpos$pooledmutableblockpos);
                            iblockstate.addCollisionBoxToList((net.minecraft.world.World) (Object) this, blockpos$pooledmutableblockpos, bbox, list, (net.minecraft.entity.Entity) null, false);
                            if (!list.isEmpty()) {
                                boolean flag = true;
                                return flag;
                            }
                        }
                    }
                }
            }
        }
        return false;
    } finally {
        blockpos$pooledmutableblockpos.release();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) IMixinBlockPos(org.spongepowered.common.interfaces.util.math.IMixinBlockPos) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 65 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project SilentGems by SilentChaos512.

the class EntityThrownTomahawk method onImpactWithBlock.

protected void onImpactWithBlock(BlockPos pos, IBlockState state) {
    // Get info on block hit
    Block block = state.getBlock();
    AxisAlignedBB boundingBox = state.getBoundingBox(world, pos);
    // Collide only if it has a bounding box.
    if (boundingBox != null) {
        Material mat = state.getMaterial();
        // Break glass blocks! But slows it down.
        if ((block == Blocks.GLASS || block == Blocks.GLASS_PANE || block == Blocks.STAINED_GLASS || block == Blocks.STAINED_GLASS_PANE)) {
            if (!world.isRemote) {
                world.setBlockToAir(pos);
                world.playSound(null, pos, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.BLOCKS, 1f, 1f);
            }
            motionX *= 0.7f;
            motionZ *= 0.7f;
        } else // Ignore leaves and plants
        if (mat == Material.LEAVES || mat == Material.PLANTS || mat == Material.VINE) {
            SoundEvent sound = block.getSoundType(state, world, pos, this).getPlaceSound();
            world.playSound(null, pos, sound, SoundCategory.BLOCKS, 0.25f, 1f);
        } else // Stop if we hit anything else
        {
            if (motionX > 0.1f || motionZ > 0.1f) {
                SoundEvent sound = block.getSoundType(state, world, pos, this).getPlaceSound();
                world.playSound(null, pos, sound, SoundCategory.BLOCKS, 1f, 1f);
            }
            // Stop the tomahawk.
            hasHit = true;
            inAir = false;
            motionX = 0;
            motionY = 0;
            motionZ = 0;
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SoundEvent(net.minecraft.util.SoundEvent) Block(net.minecraft.block.Block) Material(net.minecraft.block.material.Material)

Aggregations

AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)597 BlockPos (net.minecraft.util.math.BlockPos)194 Entity (net.minecraft.entity.Entity)133 EntityPlayer (net.minecraft.entity.player.EntityPlayer)119 IBlockState (net.minecraft.block.state.IBlockState)110 Vec3d (net.minecraft.util.math.Vec3d)95 EntityLivingBase (net.minecraft.entity.EntityLivingBase)93 EnumFacing (net.minecraft.util.EnumFacing)88 ItemStack (net.minecraft.item.ItemStack)77 World (net.minecraft.world.World)69 TileEntity (net.minecraft.tileentity.TileEntity)67 List (java.util.List)48 ArrayList (java.util.ArrayList)47 RayTraceResult (net.minecraft.util.math.RayTraceResult)45 EntityItem (net.minecraft.entity.item.EntityItem)43 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)41 Block (net.minecraft.block.Block)36 PotionEffect (net.minecraft.potion.PotionEffect)36 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)25 Nullable (javax.annotation.Nullable)24