Search in sources :

Example 1 with PhysicsQueuedForce

use of ValkyrienWarfareBase.Physics.PhysicsQueuedForce in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method tickQueuedForces.

// Returns true if splitting happened
/*
	 * public boolean processPotentialSplitting(){ if(blocksChanged){ blocksChanged = false; }else{ return false; }
	 *
	 * ArrayList<BlockPos> dirtyBlockPositions = new ArrayList(blockPositions); if(dirtyBlockPositions.size()==0){ return false; }
	 *
	 * boolean hasSplit = false;
	 *
	 * while(dirtyBlockPositions.size()!=0){ BlockPos pos = dirtyBlockPositions.get(0); SpatialDetector firstDet = new ShipBlockPosFinder(pos, worldObj, dirtyBlockPositions.size(), true);
	 *
	 * if(firstDet.foundSet.size()!=dirtyBlockPositions.size()){ //Set Y to 300 to prevent picking up extra blocks PhysicsWrapperEntity newSplit = new PhysicsWrapperEntity(worldObj,wrapper.posX,300,wrapper.posZ, null,DetectorManager.DetectorIDs.BlockPosFinder.ordinal()); newSplit.yaw = wrapper.yaw; newSplit.pitch = wrapper.pitch; newSplit.roll = wrapper.roll; newSplit.posX = wrapper.posX; newSplit.posY = wrapper.posY; newSplit.posZ = wrapper.posZ; TIntIterator iter = firstDet.foundSet.iterator();
	 *
	 * BlockPos oldBlockCenter = this.getRegionCenter(); BlockPos newBlockCenter = newSplit.wrapping.getRegionCenter(); BlockPos centerDif = newBlockCenter.subtract(oldBlockCenter);
	 *
	 * ValkyrienWarfareMod.physicsManager.onShipLoad(newSplit);
	 *
	 * newSplit.wrapping.fromSplit = true;
	 *
	 * while(iter.hasNext()){ int hash = iter.next(); BlockPos fromHash = SpatialDetector.getPosWithRespectTo(hash, pos); dirtyBlockPositions.remove(fromHash); CallRunner.onSetBlockState(worldObj, fromHash.add(centerDif), VKChunkCache.getBlockState(fromHash), 3); CallRunner.onSetBlockState(worldObj, fromHash, Blocks.AIR.getDefaultState(), 2); }
	 *
	 * newSplit.wrapping.centerCoord = new Vector(centerCoord); newSplit.wrapping.centerCoord.X+=centerDif.getX(); newSplit.wrapping.centerCoord.Y+=centerDif.getY(); newSplit.wrapping.centerCoord.Z+=centerDif.getZ(); newSplit.wrapping.coordTransform.lToWRotation = coordTransform.lToWRotation; newSplit.wrapping.physicsProcessor.updateCenterOfMass(); newSplit.wrapping.coordTransform.updateAllTransforms();
	 *
	 * //TODO: THIS MATH IS NOT EVEN REMOTELY CORRECT!!!!! //Also the moment of inertia is wrong too newSplit.wrapping.physicsProcessor.linearMomentum = new Vector(physicsProcessor.linearMomentum); newSplit.wrapping.physicsProcessor.angularVelocity = new Vector(physicsProcessor.angularVelocity);
	 *
	 * worldObj.spawnEntityInWorld(newSplit);
	 *
	 * hasSplit = true; }else{ dirtyBlockPositions.clear(); }
	 *
	 * }
	 *
	 * return hasSplit; }
	 */
public void tickQueuedForces() {
    for (int i = 0; i < queuedPhysForces.size(); i++) {
        PhysicsQueuedForce queue = queuedPhysForces.get(i);
        if (queue.ticksToApply <= 0) {
            queuedPhysForces.remove(i);
            i--;
        }
        queue.ticksToApply--;
    }
}
Also used : PhysicsQueuedForce(ValkyrienWarfareBase.Physics.PhysicsQueuedForce)

Example 2 with PhysicsQueuedForce

use of ValkyrienWarfareBase.Physics.PhysicsQueuedForce in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class CallRunner method onExplosionA.

public static void onExplosionA(Explosion e) {
    Vector center = new Vector(e.explosionX, e.explosionY, e.explosionZ);
    World worldIn = e.worldObj;
    float radius = e.explosionSize;
    AxisAlignedBB toCheck = new AxisAlignedBB(center.X - radius, center.Y - radius, center.Z - radius, center.X + radius, center.Y + radius, center.Z + radius);
    List<PhysicsWrapperEntity> shipsNear = ValkyrienWarfareMod.physicsManager.getManagerForWorld(e.worldObj).getNearbyPhysObjects(toCheck);
    e.doExplosionA();
    // TODO: Make this compatible and shit!
    for (PhysicsWrapperEntity ship : shipsNear) {
        Vector inLocal = new Vector(center);
        RotationMatrices.applyTransform(ship.wrapping.coordTransform.wToLTransform, inLocal);
        // inLocal.roundToWhole();
        Explosion expl = new Explosion(ship.worldObj, null, inLocal.X, inLocal.Y, inLocal.Z, radius, false, false);
        double waterRange = .6D;
        boolean cancelDueToWater = false;
        for (int x = (int) Math.floor(expl.explosionX - waterRange); x <= Math.ceil(expl.explosionX + waterRange); x++) {
            for (int y = (int) Math.floor(expl.explosionY - waterRange); y <= Math.ceil(expl.explosionY + waterRange); y++) {
                for (int z = (int) Math.floor(expl.explosionZ - waterRange); z <= Math.ceil(expl.explosionZ + waterRange); z++) {
                    if (!cancelDueToWater) {
                        IBlockState state = e.worldObj.getBlockState(new BlockPos(x, y, z));
                        if (state.getBlock() instanceof BlockLiquid) {
                            cancelDueToWater = true;
                        }
                    }
                }
            }
        }
        expl.doExplosionA();
        double affectedPositions = 0D;
        for (Object o : expl.affectedBlockPositions) {
            BlockPos pos = (BlockPos) o;
            IBlockState state = ship.worldObj.getBlockState(pos);
            Block block = state.getBlock();
            if (!block.isAir(state, worldIn, (BlockPos) o) || ship.wrapping.explodedPositionsThisTick.contains((BlockPos) o)) {
                affectedPositions++;
            }
        }
        if (!cancelDueToWater) {
            for (Object o : expl.affectedBlockPositions) {
                BlockPos pos = (BlockPos) o;
                IBlockState state = ship.worldObj.getBlockState(pos);
                Block block = state.getBlock();
                if (!block.isAir(state, worldIn, (BlockPos) o) || ship.wrapping.explodedPositionsThisTick.contains((BlockPos) o)) {
                    if (block.canDropFromExplosion(expl)) {
                        block.dropBlockAsItemWithChance(ship.worldObj, pos, state, 1.0F / expl.explosionSize, 0);
                    }
                    block.onBlockExploded(ship.worldObj, pos, expl);
                    if (!worldIn.isRemote) {
                        Vector posVector = new Vector(pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5);
                        ship.wrapping.coordTransform.fromLocalToGlobal(posVector);
                        double mass = BlockMass.basicMass.getMassFromState(state, pos, ship.worldObj);
                        double explosionForce = Math.sqrt(e.explosionSize) * 1000D * mass;
                        Vector forceVector = new Vector(pos.getX() + .5 - expl.explosionX, pos.getY() + .5 - expl.explosionY, pos.getZ() + .5 - expl.explosionZ);
                        double vectorDist = forceVector.length();
                        forceVector.normalize();
                        forceVector.multiply(explosionForce / vectorDist);
                        RotationMatrices.doRotationOnly(ship.wrapping.coordTransform.lToWRotation, forceVector);
                        PhysicsQueuedForce queuedForce = new PhysicsQueuedForce(forceVector, posVector, false, 1);
                        if (!ship.wrapping.explodedPositionsThisTick.contains(pos)) {
                            ship.wrapping.explodedPositionsThisTick.add(pos);
                        }
                        ship.wrapping.queueForce(queuedForce);
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Explosion(net.minecraft.world.Explosion) IBlockState(net.minecraft.block.state.IBlockState) World(net.minecraft.world.World) BlockLiquid(net.minecraft.block.BlockLiquid) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) PhysicsQueuedForce(ValkyrienWarfareBase.Physics.PhysicsQueuedForce) Vector(ValkyrienWarfareBase.API.Vector)

Aggregations

PhysicsQueuedForce (ValkyrienWarfareBase.Physics.PhysicsQueuedForce)2 Vector (ValkyrienWarfareBase.API.Vector)1 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)1 Block (net.minecraft.block.Block)1 BlockLiquid (net.minecraft.block.BlockLiquid)1 IBlockState (net.minecraft.block.state.IBlockState)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 Explosion (net.minecraft.world.Explosion)1 World (net.minecraft.world.World)1