Search in sources :

Example 1 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ShipPhysicsCollider method doShipCollision.

public void doShipCollision(PhysicsObject toCollideWith) {
    //Don't process collision if either of them are phased
    if (toCollideWith.physicsProcessor instanceof PhysicsCalculationsOrbital) {
        if (((PhysicsCalculationsOrbital) toCollideWith.physicsProcessor).isOrbitalPhased) {
            return;
        }
    }
    if (parent.physicsProcessor instanceof PhysicsCalculationsOrbital) {
        if (((PhysicsCalculationsOrbital) parent.physicsProcessor).isOrbitalPhased) {
            return;
        }
    }
    AxisAlignedBB firstBB = parent.collisionBB;
    AxisAlignedBB secondBB = toCollideWith.collisionBB;
    AxisAlignedBB betweenBB = BigBastardMath.getBetweenAABB(firstBB, secondBB);
    Polygon betweenBBPoly = new Polygon(betweenBB, toCollideWith.coordTransform.wToLTransform);
    List<AxisAlignedBB> bbsInFirst = parent.worldObj.getCollisionBoxes(betweenBBPoly.getEnclosedAABB());
    if (bbsInFirst.isEmpty()) {
        return;
    }
    Vector[] axes = parent.coordTransform.getSeperatingAxisWithShip(toCollideWith);
    // RandomIterator.getRandomIteratorForList(bbsInFirst);
    Iterator<AxisAlignedBB> firstRandIter = bbsInFirst.iterator();
    while (firstRandIter.hasNext()) {
        AxisAlignedBB fromIter = firstRandIter.next();
        Polygon firstInWorld = new Polygon(fromIter, toCollideWith.coordTransform.lToWTransform);
        AxisAlignedBB inWorldAABB = firstInWorld.getEnclosedAABB();
        Polygon inShip2Poly = new Polygon(inWorldAABB, parent.coordTransform.wToLTransform);
        // This is correct
        List<AxisAlignedBB> bbsInSecond = parent.worldObj.getCollisionBoxes(inShip2Poly.getEnclosedAABB());
        // RandomIterator.getRandomIteratorForList(bbsInSecond);
        Iterator<AxisAlignedBB> secondRandIter = bbsInSecond.iterator();
        while (secondRandIter.hasNext()) {
            // System.out.println("test");
            Polygon secondInWorld = new Polygon(secondRandIter.next(), parent.coordTransform.lToWTransform);
            // Both of these are in WORLD coordinates
            Vector firstCenter = firstInWorld.getCenter();
            Vector secondCenter = secondInWorld.getCenter();
            Vector inBodyFirst = new Vector(firstCenter.X - parent.wrapper.posX, firstCenter.Y - parent.wrapper.posY, firstCenter.Z - parent.wrapper.posZ);
            Vector inBodySecond = new Vector(secondCenter.X - toCollideWith.wrapper.posX, secondCenter.Y - toCollideWith.wrapper.posY, secondCenter.Z - toCollideWith.wrapper.posZ);
            Vector velAtFirst = parent.physicsProcessor.getVelocityAtPoint(inBodyFirst);
            Vector velAtSecond = toCollideWith.physicsProcessor.getVelocityAtPoint(inBodySecond);
            velAtFirst.subtract(velAtSecond);
            PhysPolygonCollider polyCol = new PhysPolygonCollider(firstInWorld, secondInWorld, axes);
            if (!polyCol.seperated) {
                Vector speedAtPoint = velAtFirst;
                double xDot = Math.abs(speedAtPoint.X);
                double yDot = Math.abs(speedAtPoint.Y);
                double zDot = Math.abs(speedAtPoint.Z);
                PhysCollisionObject polyColObj = null;
                if (yDot > xDot && yDot > zDot) {
                    // Y speed is greatest
                    if (xDot > zDot) {
                        polyColObj = polyCol.collisions[2];
                    } else {
                        polyColObj = polyCol.collisions[0];
                    }
                } else {
                    if (xDot > zDot) {
                        // X speed is greatest
                        polyColObj = polyCol.collisions[1];
                    } else {
                        // Z speed is greatest
                        polyColObj = polyCol.collisions[1];
                    }
                }
                // PhysCollisionObject polyColObj = polyCol.collisions[1];
                if (polyColObj.penetrationDistance > axisTolerance || polyColObj.penetrationDistance < -axisTolerance) {
                    polyColObj = polyCol.collisions[polyCol.minDistanceIndex];
                }
                // PhysCollisionObject physCol = new PhysCollisionObject(firstInWorld,secondInWorld,polyColObj.axis);
                processCollisionAtPoint(toCollideWith, polyColObj);
                if (Math.abs(polyColObj.movMaxFixMin) > Math.abs(polyColObj.movMinFixMax)) {
                    for (Vector v : polyColObj.movable.vertices) {
                        if (v.dot(polyColObj.axis) == polyColObj.playerMinMax[1]) {
                            polyColObj.firstContactPoint = v;
                        }
                    }
                } else {
                    for (Vector v : polyColObj.movable.vertices) {
                        if (v.dot(polyColObj.axis) == polyColObj.playerMinMax[0]) {
                            polyColObj.firstContactPoint = v;
                        }
                    }
                }
                // physCol.firstContactPoint = physCol.getSecondContactPoint();
                processCollisionAtPoint(toCollideWith, polyColObj);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PhysicsCalculationsOrbital(ValkyrienWarfareBase.Physics.PhysicsCalculationsOrbital) PhysCollisionObject(ValkyrienWarfareBase.Collision.PhysCollisionObject) Polygon(ValkyrienWarfareBase.Collision.Polygon) Vector(ValkyrienWarfareBase.API.Vector) PhysPolygonCollider(ValkyrienWarfareBase.Collision.PhysPolygonCollider)

Example 2 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldPhysicsCollider method updatePotentialCollisionCache.

private void updatePotentialCollisionCache() {
    final AxisAlignedBB collisionBB = parent.collisionBB.expand(expansion, expansion, expansion).addCoord(calculator.linearMomentum.X * calculator.invMass, calculator.linearMomentum.Y * calculator.invMass, calculator.linearMomentum.Z * calculator.invMass);
    ticksSinceCacheUpdate = 0D;
    //in the same tick
    if (Math.random() > .5) {
        ticksSinceCacheUpdate -= .05D;
    }
    // cachedPotentialHits = new ArrayList<BlockPos>();
    cachedPotentialHits = new TIntArrayList();
    // Ship is outside of world blockSpace, just skip this all together
    if (collisionBB.maxY < 0 || collisionBB.minY > 255) {
        // internalCachedPotentialHits = new BlockPos[0];
        return;
    }
    //Has a -1 on the minY value, I hope this helps with preventing things from falling through the floor
    final BlockPos min = new BlockPos(collisionBB.minX, Math.max(collisionBB.minY - 1, 0), collisionBB.minZ);
    final BlockPos max = new BlockPos(collisionBB.maxX, Math.min(collisionBB.maxY, 255), collisionBB.maxZ);
    centerPotentialHit = new BlockPos((min.getX() + max.getX()) / 2D, (min.getY() + max.getY()) / 2D, (min.getZ() + max.getZ()) / 2D);
    final ChunkCache cache = parent.surroundingWorldChunksCache;
    final Vector inLocal = new Vector();
    int maxX, maxY, maxZ, localX, localY, localZ, x, y, z, chunkX, chunkZ;
    double rangeCheck = 1.8D;
    if (ValkyrienWarfareMod.highAccuracyCollisions) {
        rangeCheck = 3D;
    }
    Chunk chunk, chunkIn;
    ExtendedBlockStorage extendedblockstorage;
    IBlockState state, localState;
    int chunkMinX = min.getX() >> 4;
    int chunkMaxX = (max.getX() >> 4) + 1;
    int storageMinY = min.getY() >> 4;
    int storageMaxY = (max.getY() >> 4) + 1;
    int chunkMinZ = min.getZ() >> 4;
    int chunkMaxZ = (max.getZ() >> 4) + 1;
    int storageY;
    int mmX = min.getX(), mmY = min.getY(), mmZ = min.getZ(), mxX = max.getX(), mxY = max.getY(), mxZ = max.getZ();
    Vector inBody = new Vector();
    Vector speedInBody = new Vector();
    for (chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
        for (chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
            int arrayChunkX = chunkX - cache.chunkX;
            int arrayChunkZ = chunkZ - cache.chunkZ;
            if (!(arrayChunkX < 0 || arrayChunkZ < 0 || arrayChunkX > cache.chunkArray.length - 1 || arrayChunkZ > cache.chunkArray[0].length - 1)) {
                chunk = cache.chunkArray[arrayChunkX][arrayChunkZ];
                for (storageY = storageMinY; storageY < storageMaxY; storageY++) {
                    extendedblockstorage = chunk.storageArrays[storageY];
                    if (extendedblockstorage != null) {
                        int minStorageX = chunkX << 4;
                        int minStorageY = storageY << 4;
                        int minStorageZ = chunkZ << 4;
                        int maxStorageX = minStorageX + 16;
                        int maxStorageY = minStorageY + 16;
                        int maxStorageZ = minStorageZ + 16;
                        minStorageX = Math.max(minStorageX, mmX);
                        minStorageY = Math.max(minStorageY, mmY);
                        minStorageZ = Math.max(minStorageZ, mmZ);
                        maxStorageX = Math.min(maxStorageX, mxX);
                        maxStorageY = Math.min(maxStorageY, mxY);
                        maxStorageZ = Math.min(maxStorageZ, mxZ);
                        for (x = minStorageX; x < maxStorageX; x++) {
                            for (y = minStorageY; y < maxStorageY; y++) {
                                for (z = minStorageZ; z < maxStorageZ; z++) {
                                    state = extendedblockstorage.get(x & 15, y & 15, z & 15);
                                    if (state.getMaterial().isSolid()) {
                                        inLocal.X = x + .5D;
                                        inLocal.Y = y + .5D;
                                        inLocal.Z = z + .5D;
                                        parent.coordTransform.fromGlobalToLocal(inLocal);
                                        inBody.setSubtraction(inLocal, parent.centerCoord);
                                        parent.physicsProcessor.setVectorToVelocityAtPoint(inBody, speedInBody);
                                        speedInBody.multiply(-parent.physicsProcessor.physRawSpeed);
                                        if (ValkyrienWarfareMod.highAccuracyCollisions) {
                                            speedInBody.multiply(20D);
                                        }
                                        //											System.out.println(speedInBody);
                                        int minX, minY, minZ;
                                        if (speedInBody.X > 0) {
                                            minX = MathHelper.floor_double(inLocal.X - rangeCheck);
                                            maxX = MathHelper.floor_double(inLocal.X + rangeCheck + speedInBody.X);
                                        } else {
                                            minX = MathHelper.floor_double(inLocal.X - rangeCheck + speedInBody.X);
                                            maxX = MathHelper.floor_double(inLocal.X + rangeCheck);
                                        }
                                        if (speedInBody.Y > 0) {
                                            minY = MathHelper.floor_double(inLocal.Y - rangeCheck);
                                            maxY = MathHelper.floor_double(inLocal.Y + rangeCheck + speedInBody.Y);
                                        } else {
                                            minY = MathHelper.floor_double(inLocal.Y - rangeCheck + speedInBody.Y);
                                            maxY = MathHelper.floor_double(inLocal.Y + rangeCheck);
                                        }
                                        if (speedInBody.Z > 0) {
                                            minZ = MathHelper.floor_double(inLocal.Z - rangeCheck);
                                            maxZ = MathHelper.floor_double(inLocal.Z + rangeCheck + speedInBody.Z);
                                        } else {
                                            minZ = MathHelper.floor_double(inLocal.Z - rangeCheck + speedInBody.Z);
                                            maxZ = MathHelper.floor_double(inLocal.Z + rangeCheck);
                                        }
                                        /** The Old Way of doing things; approx. 33% slower overall when running this code instead of new
											for (localX = minX; localX < maxX; localX++) {
												for (localZ = minZ; localZ < maxZ; localZ++) {
													for (localY = minY; localY < maxY; localY++) {
														if (parent.ownsChunk(localX >> 4, localZ >> 4)) {
															chunkIn = parent.VKChunkCache.getChunkAt(localX >> 4, localZ >> 4);
															localState = chunkIn.getBlockState(localX, localY, localZ);
															if (localState.getMaterial().isSolid()) {
																cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
																localX = localY = localZ = Integer.MAX_VALUE - 420;
															}
														}
													}
												}
											}
											**/
                                        int shipChunkMinX = minX >> 4;
                                        int shipChunkMinY = Math.max(minY >> 4, 0);
                                        int shipChunkMinZ = minZ >> 4;
                                        int shipChunkMaxX = maxX >> 4;
                                        int shipChunkMaxY = Math.min(maxY >> 4, 15);
                                        int shipChunkMaxZ = maxZ >> 4;
                                        shipChunkMaxX++;
                                        shipChunkMaxY++;
                                        shipChunkMaxZ++;
                                        if (shipChunkMaxZ - shipChunkMinZ > 200 || shipChunkMaxX - shipChunkMinX > 200) {
                                            System.err.println("Wtf. This fucking error");
                                            return;
                                        }
                                        testForNearbyBlocks: for (int shipChunkX = shipChunkMinX; shipChunkX < shipChunkMaxX; shipChunkX++) {
                                            for (int shipChunkZ = shipChunkMinZ; shipChunkZ < shipChunkMaxZ; shipChunkZ++) {
                                                if (parent.ownsChunk(shipChunkX, shipChunkZ)) {
                                                    chunkIn = parent.VKChunkCache.getChunkAt(shipChunkX, shipChunkZ);
                                                    for (int shipChunkYStorage = shipChunkMinY; shipChunkYStorage < shipChunkMaxY; shipChunkYStorage++) {
                                                        ExtendedBlockStorage storage = chunkIn.storageArrays[shipChunkYStorage];
                                                        if (storage != null) {
                                                            int shipStorageMinX = shipChunkX << 4;
                                                            int shipStorageMinY = shipChunkYStorage << 4;
                                                            int shipStorageMinZ = shipChunkZ << 4;
                                                            int shipStorageMaxX = shipStorageMinX + 16;
                                                            int shipStorageMaxY = shipStorageMinY + 16;
                                                            int shipStorageMaxZ = shipStorageMinZ + 16;
                                                            shipStorageMinX = Math.max(shipStorageMinX, minX);
                                                            shipStorageMinY = Math.max(shipStorageMinY, minY);
                                                            shipStorageMinZ = Math.max(shipStorageMinZ, minZ);
                                                            shipStorageMaxX = Math.min(shipStorageMaxX, maxX);
                                                            shipStorageMaxY = Math.min(shipStorageMaxY, maxY);
                                                            shipStorageMaxZ = Math.min(shipStorageMaxZ, maxZ);
                                                            for (localX = shipStorageMinX; localX < shipStorageMaxX; localX++) {
                                                                for (localY = shipStorageMinY; localY < shipStorageMaxY; localY++) {
                                                                    for (localZ = shipStorageMinZ; localZ < shipStorageMaxZ; localZ++) {
                                                                        localState = chunkIn.getBlockState(localX, localY, localZ);
                                                                        if (localState.getMaterial().isSolid()) {
                                                                            cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
                                                                            break testForNearbyBlocks;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    /**
		for (x = min.getX(); x <= max.getX(); x++) {
			for (z = min.getZ(); z < max.getZ(); z++) {
				chunkX = (x >> 4) - cache.chunkX;
				chunkZ = (z >> 4) - cache.chunkZ;
				if (!(chunkX < 0 || chunkZ < 0 || chunkX > cache.chunkArray.length - 1 || chunkZ > cache.chunkArray[0].length - 1)) {
					chunk = cache.chunkArray[chunkX][chunkZ];
					for (y = min.getY(); y < max.getY(); y++) {
						extendedblockstorage = chunk.storageArrays[y >> 4];
						if (extendedblockstorage != null) {
							state = extendedblockstorage.get(x & 15, y & 15, z & 15);

							if (state.getMaterial().isSolid()) {
								inLocal.X = x + .5D;
								inLocal.Y = y + .5D;
								inLocal.Z = z + .5D;
								parent.coordTransform.fromGlobalToLocal(inLocal);

								maxX = (int) Math.floor(inLocal.X + rangeCheck);
								maxY = (int) Math.floor(inLocal.Y + rangeCheck);
								maxZ = (int) Math.floor(inLocal.Z + rangeCheck);

								for (localX = MathHelper.floor_double(inLocal.X - rangeCheck); localX < maxX; localX++) {
									for (localZ = MathHelper.floor_double(inLocal.Z - rangeCheck); localZ < maxZ; localZ++) {
										for (localY = MathHelper.floor_double(inLocal.Y - rangeCheck); localY < maxY; localY++) {
											if (parent.ownsChunk(localX >> 4, localZ >> 4)) {
												chunkIn = parent.VKChunkCache.getChunkAt(localX >> 4, localZ >> 4);
												localState = chunkIn.getBlockState(localX, localY, localZ);
												if (localState.getMaterial().isSolid()) {
													cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
													localX = localY = localZ = Integer.MAX_VALUE - 420;
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		**/
    cachedPotentialHits.shuffle(rand);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) ChunkCache(net.minecraft.world.ChunkCache) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) Vector(ValkyrienWarfareBase.API.Vector) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 3 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldPhysicsCollider method handleLikelyCollision.

//Tests two block positions directly against each other, and figures out whether a collision is occuring or not
private boolean handleLikelyCollision(BlockPos inWorldPos, BlockPos inLocalPos, IBlockState inWorldState, IBlockState inLocalState) {
    // System.out.println("Handling a likely collision");
    AxisAlignedBB inLocalBB = new AxisAlignedBB(inLocalPos.getX(), inLocalPos.getY(), inLocalPos.getZ(), inLocalPos.getX() + 1, inLocalPos.getY() + 1, inLocalPos.getZ() + 1);
    AxisAlignedBB inGlobalBB = new AxisAlignedBB(inWorldPos.getX(), inWorldPos.getY(), inWorldPos.getZ(), inWorldPos.getX() + 1, inWorldPos.getY() + 1, inWorldPos.getZ() + 1);
    //This changes the box bounding box to the real bounding box, not sure if this is better or worse for this mod
    //		List<AxisAlignedBB> colBB = worldObj.getCollisionBoxes(inLocalBB);
    //		inLocalBB = colBB.get(0);
    Polygon shipInWorld = new Polygon(inLocalBB, parent.coordTransform.lToWTransform);
    Polygon worldPoly = new Polygon(inGlobalBB);
    PhysPolygonCollider collider = new PhysPolygonCollider(shipInWorld, worldPoly, parent.coordTransform.normals);
    if (!collider.seperated) {
        return handleActualCollision(collider, inWorldPos, inLocalPos, inWorldState, inLocalState);
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Polygon(ValkyrienWarfareBase.Collision.Polygon) PhysPolygonCollider(ValkyrienWarfareBase.Collision.PhysPolygonCollider)

Example 4 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class NewExp method doExplosionA.

/**
     * Does the first part of the explosion (destroy blocks)
     */
public void doExplosionA() {
    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.explosionSize * (0.3F + this.worldObj.rand.nextFloat() * 0.3F);
                    double d4 = this.explosionX;
                    double d6 = this.explosionY;
                    double d8 = this.explosionZ;
                    for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
                        BlockPos blockpos = new BlockPos(d4, d6, d8);
                        IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
                        if (iblockstate.getMaterial() != Material.AIR) {
                            float f2 = this.exploder != null ? this.exploder.getExplosionResistance(this, this.worldObj, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(worldObj, blockpos, (Entity) null, this);
                            //  f -= ((f2 + 0.3F) * 0.3F) / this.explosionPower ;
                            f -= (f2 * this.explosionBlast) + this.explosionPower;
                        }
                        if (f > 0.0F && (this.exploder == null || this.exploder.verifyExplosion(this, this.worldObj, 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.explosionSize * 2.0F;
    int k1 = MathHelper.floor_double(this.explosionX - (double) f3 - 1.0D);
    int l1 = MathHelper.floor_double(this.explosionX + (double) f3 + 1.0D);
    int i2 = MathHelper.floor_double(this.explosionY - (double) f3 - 1.0D);
    int i1 = MathHelper.floor_double(this.explosionY + (double) f3 + 1.0D);
    int j2 = MathHelper.floor_double(this.explosionZ - (double) f3 - 1.0D);
    int j1 = MathHelper.floor_double(this.explosionZ + (double) f3 + 1.0D);
    List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1));
    net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.worldObj, this, list, f3);
    Vec3d vec3d = new Vec3d(this.explosionX, this.explosionY, this.explosionZ);
    for (int k2 = 0; k2 < list.size(); ++k2) {
        Entity entity = (Entity) list.get(k2);
        if (!entity.isImmuneToExplosions()) {
            double d12 = entity.getDistance(this.explosionX, this.explosionY, this.explosionZ) / f3;
            if (d12 <= 1.0D) {
                double d5 = entity.posX - this.explosionX;
                double d7 = entity.posY + (double) entity.getEyeHeight() - this.explosionY;
                double d9 = entity.posZ - this.explosionZ;
                double d13 = (double) MathHelper.sqrt_double(d5 * d5 + d7 * d7 + d9 * d9);
                if (d13 != 0.0D) {
                    d5 = d5 / d13;
                    d7 = d7 / d13;
                    d9 = d9 / d13;
                    double d14 = (double) this.worldObj.getBlockDensity(vec3d, entity.getEntityBoundingBox());
                    double d10 = (1.0D - d12) * d14;
                    entity.attackEntityFrom(DamageSource.causeExplosionDamage(this), (float) ((int) ((d10 * d10 + d10) + this.explosionDamage / 2.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) IBlockState(net.minecraft.block.state.IBlockState) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 5 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class NewExp2 method doExplosionA.

/**
     * Does the first part of the explosion (destroy blocks)
     */
public void doExplosionA() {
    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.explosionSize * (0.3F + this.worldObj.rand.nextFloat() * 0.3F);
                    double d4 = this.explosionX;
                    double d6 = this.explosionY;
                    double d8 = this.explosionZ;
                    for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
                        BlockPos blockpos = new BlockPos(d4, d6, d8);
                        IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
                        if (iblockstate.getMaterial() != Material.AIR) {
                            float f2 = this.exploder != null ? this.exploder.getExplosionResistance(this, this.worldObj, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(worldObj, blockpos, (Entity) null, this);
                            //  f -= ((f2 + 0.3F) * 0.3F) / this.explosionPower ;
                            f -= (f2 * this.explosionBlast) + this.explosionPower;
                        }
                        if (f > 0.0F && (this.exploder == null || this.exploder.verifyExplosion(this, this.worldObj, 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.explosionSize * 2;
    int k1 = MathHelper.floor_double(this.explosionX - (double) f3 - 1.0D);
    int l1 = MathHelper.floor_double(this.explosionX + (double) f3 + 1.0D);
    int i2 = MathHelper.floor_double(this.explosionY - (double) f3 - 1.0D);
    int i1 = MathHelper.floor_double(this.explosionY + (double) f3 + 1.0D);
    int j2 = MathHelper.floor_double(this.explosionZ - (double) f3 - 1.0D);
    int j1 = MathHelper.floor_double(this.explosionZ + (double) f3 + 1.0D);
    List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1));
    net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.worldObj, this, list, f3);
    Vec3d vec3d = new Vec3d(this.explosionX, this.explosionY, this.explosionZ);
    for (int k2 = 0; k2 < list.size(); ++k2) {
        Entity entity = (Entity) list.get(k2);
        if (!entity.isImmuneToExplosions()) {
            double d12 = entity.getDistance(this.explosionX, this.explosionY, this.explosionZ) / f3;
            if (d12 <= 1.0D) {
                double d5 = entity.posX - this.explosionX;
                double d7 = entity.posY + (double) entity.getEyeHeight() - this.explosionY;
                double d9 = entity.posZ - this.explosionZ;
                double d13 = (double) MathHelper.sqrt_double(d5 * d5 + d7 * d7 + d9 * d9);
                if (d13 != 0.0D) {
                    d5 = d5 / d13;
                    d7 = d7 / d13;
                    d9 = d9 / d13;
                    double d14 = (double) this.worldObj.getBlockDensity(vec3d, entity.getEntityBoundingBox());
                    double d10 = (1.0D - d12) * d14;
                    entity.attackEntityFrom(DamageSource.causeExplosionDamage(this), (float) ((int) ((d10 * d10 + d10) + this.explosionDamage / 2.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) IBlockState(net.minecraft.block.state.IBlockState) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)626 BlockPos (net.minecraft.util.math.BlockPos)202 Entity (net.minecraft.entity.Entity)138 EntityPlayer (net.minecraft.entity.player.EntityPlayer)127 IBlockState (net.minecraft.block.state.IBlockState)117 Vec3d (net.minecraft.util.math.Vec3d)99 EntityLivingBase (net.minecraft.entity.EntityLivingBase)96 EnumFacing (net.minecraft.util.EnumFacing)91 ItemStack (net.minecraft.item.ItemStack)82 World (net.minecraft.world.World)70 TileEntity (net.minecraft.tileentity.TileEntity)69 ArrayList (java.util.ArrayList)49 List (java.util.List)48 RayTraceResult (net.minecraft.util.math.RayTraceResult)48 EntityItem (net.minecraft.entity.item.EntityItem)43 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)41 Block (net.minecraft.block.Block)37 PotionEffect (net.minecraft.potion.PotionEffect)36 Nullable (javax.annotation.Nullable)25 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)25