Search in sources :

Example 26 with ShipTransform

use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldShipLoadingController method determineLoadAndUnload.

/**
 * Tells the WorldServerShipManager which ships to load/unload/load in background.
 */
void determineLoadAndUnload() {
    for (ShipData data : QueryableShipData.get(shipManager.getWorld())) {
        ShipTransform transform = data.getShipTransform();
        Vec3d shipPos = transform.getShipPositionVec3d();
        if (shipManager.getPhysObjectFromUUID(data.getUuid()) == null) {
            if (existsPlayerWithinDistanceXZ(shipManager.getWorld(), shipPos, VSConfig.SHIP_LOADING_SETTINGS.loadDistance)) {
                shipManager.queueShipLoad(data.getUuid());
            } else {
                if (VSConfig.SHIP_LOADING_SETTINGS.permanentlyLoaded || existsPlayerWithinDistanceXZ(shipManager.getWorld(), shipPos, VSConfig.SHIP_LOADING_SETTINGS.loadBackgroundDistance)) {
                    shipManager.queueShipLoadBackground(data.getUuid());
                }
            }
        } else {
            if (!VSConfig.SHIP_LOADING_SETTINGS.permanentlyLoaded && !existsPlayerWithinDistanceXZ(shipManager.getWorld(), shipPos, VSConfig.SHIP_LOADING_SETTINGS.unloadDistance)) {
                shipManager.queueShipUnload(data.getUuid());
            }
        }
    }
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) ShipData(org.valkyrienskies.mod.common.ships.ShipData) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) Vec3d(net.minecraft.util.math.Vec3d)

Example 27 with ShipTransform

use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class TileEntityBoatChair method getTorqueInGlobal.

@Nullable
public Vector3dc getTorqueInGlobal(PhysicsCalculations physicsCalculations) {
    // Don't add force if theres no pilot
    if (getPilotEntity() == null) {
        return null;
    }
    final PhysicsObject physicsObject = physicsCalculations.getParent();
    final ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentPhysicsTransform();
    final Vector3dc idealAngularVelocity = shipTransform.transformDirectionNew(new Vector3d(targetAngularVelocity), TransformType.SUBSPACE_TO_GLOBAL);
    final Vector3dc currentAngularVelocity = physicsCalculations.getAngularVelocity();
    final Vector3dc velocityDifference = idealAngularVelocity.sub(currentAngularVelocity, new Vector3d());
    final Vector3d resultingTorque = physicsCalculations.getPhysMOITensor().transform(velocityDifference, new Vector3d());
    resultingTorque.mul(physicsCalculations.getPhysicsTimeDeltaPerPhysTick());
    resultingTorque.mul(ANGULAR_EMA_FILTER_CONSTANT);
    // Only effect y axis
    resultingTorque.x = 0;
    resultingTorque.z = 0;
    // Add a stabilization torque
    final Vector3dc shipUp = shipTransform.transformDirectionNew(new Vector3d(0, 1, 0), TransformType.SUBSPACE_TO_GLOBAL);
    final Vector3dc idealUp = new Vector3d(0, 1, 0);
    final double angleBetween = shipUp.angle(idealUp);
    if (angleBetween > .01) {
        final Vector3dc stabilizationRotationAxisNormalized = shipUp.cross(idealUp, new Vector3d()).normalize();
        final Vector3d stabilizationTorque = physicsCalculations.getPhysMOITensor().transform(stabilizationRotationAxisNormalized.mul(angleBetween, new Vector3d()));
        stabilizationTorque.mul(physicsCalculations.getPhysicsTimeDeltaPerPhysTick());
        stabilizationTorque.mul(STABILIZATION_TORQUE_CONSTANT);
        resultingTorque.add(stabilizationTorque);
    }
    return resultingTorque;
}
Also used : Vector3dc(org.joml.Vector3dc) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Nullable(javax.annotation.Nullable)

Example 28 with ShipTransform

use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method destroyShip.

void destroyShip() {
    // Then tell the game to stop tracking/loading the chunks
    List<EntityPlayerMP> watchersCopy = new ArrayList<>(getWatchingPlayers());
    for (ChunkPos chunkPos : getChunkClaim()) {
        SPacketUnloadChunk unloadPacket = new SPacketUnloadChunk(chunkPos.x, chunkPos.z);
        for (EntityPlayerMP wachingPlayer : watchersCopy) {
            wachingPlayer.connection.sendPacket(unloadPacket);
        }
    // NOTICE: This method isnt being called to avoid the
    // watchingPlayers.remove(player) call, which is a waste of CPU time
    // onPlayerUntracking(wachingPlayer);
    }
    getWatchingPlayers().clear();
    // Finally, copy all the blocks from the ship to the world
    if (!getBlockPositions().isEmpty()) {
        if (deconstructState.copyBlocks) {
            MutableBlockPos newPos = new MutableBlockPos();
            ShipTransform currentTransform = getShipTransformationManager().getCurrentTickTransform();
            Vector3dc position = new Vector3d(currentTransform.getPosX(), currentTransform.getPosY(), currentTransform.getPosZ());
            BlockPos centerDifference = new BlockPos(Math.round(getCenterCoord().x() - position.x()), Math.round(getCenterCoord().y() - position.y()), Math.round(getCenterCoord().z() - position.z()));
            for (BlockPos oldPos : this.getBlockPositions()) {
                newPos.setPos(oldPos.getX() - centerDifference.getX(), oldPos.getY() - centerDifference.getY(), oldPos.getZ() - centerDifference.getZ());
                MoveBlocks.copyBlockToPos(getWorld(), oldPos, newPos, null);
            }
            // Then relight the chunks we just copied the blocks to
            {
                Set<Long> chunksRelit = new HashSet<>();
                for (BlockPos changedPos : this.getBlockPositions()) {
                    int changedChunkX = (changedPos.getX() - centerDifference.getX()) >> 4;
                    int changedChunkZ = (changedPos.getZ() - centerDifference.getZ()) >> 4;
                    long changedChunkPos = ChunkPos.asLong(changedChunkX, changedChunkZ);
                    if (chunksRelit.contains(changedChunkPos)) {
                        continue;
                    }
                    final Chunk chunk = world.getChunk(changedChunkX, changedChunkZ);
                    chunk.generateSkylightMap();
                    chunk.checkLight();
                    chunk.markDirty();
                    chunksRelit.add(changedChunkPos);
                }
            }
        }
        // Just delete the tile entities in ship to prevent any dupe bugs.
        for (BlockPos oldPos : this.getBlockPositions()) {
            getWorld().removeTileEntity(oldPos);
        }
    }
    // Delete all the old ship chunks
    getClaimedChunkCache().deleteShipChunksFromWorld();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Chunk(net.minecraft.world.chunk.Chunk) SPacketUnloadChunk(net.minecraft.network.play.server.SPacketUnloadChunk) Vector3dc(org.joml.Vector3dc) SPacketUnloadChunk(net.minecraft.network.play.server.SPacketUnloadChunk) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ChunkPos(net.minecraft.util.math.ChunkPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos)

Example 29 with ShipTransform

use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method onTick.

void onTick() {
    if (!world.isRemote) {
        cachedSurroundingChunks.updateChunkCache();
        final boolean forceToUseShipDataTransformLocalCopy = forceToUseShipDataTransform;
        forceToUseShipDataTransform = false;
        if (forceToUseShipDataTransformLocalCopy) {
            final ShipTransform forcedTransform = shipData.getShipTransform();
            // This is BAD! Race condition! But I don't think this will cause any problems (I hope).
            getShipTransformationManager().setPrevPhysicsTransform(forcedTransform);
            getShipTransformationManager().setCurrentPhysicsTransform(forcedTransform);
            getShipTransformationManager().setPrevTickTransform(forcedTransform);
            getShipTransformationManager().setCurrentTickTransform(forcedTransform);
        }
        ticksSinceShipTeleport++;
        ShipTransform physicsTransform = getShipTransformationManager().getCurrentPhysicsTransform();
        getShipTransformationManager().updateAllTransforms(physicsTransform, false, true);
        // Copy the current and prev transforms into ShipData
        getShipData().setShipTransform(getShipTransformationManager().getCurrentTickTransform());
        getShipData().setPrevTickShipTransform(getShipTransformationManager().getPrevTickTransform());
    } else {
        transformInterpolator.tickTransformInterpolator();
        ShipTransform newTransform = transformInterpolator.getCurrentTickTransform();
        AxisAlignedBB newAABB = transformInterpolator.getCurrentAABB();
        shipData.setPrevTickShipTransform(shipData.getShipTransform());
        shipData.setShipTransform(newTransform);
        shipData.setShipBB(newAABB);
        shipTransformationManager.updateAllTransforms(newTransform, false, false);
    }
    this.ticksExisted++;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)

Example 30 with ShipTransform

use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ShipPilot method getBlockForceInShipSpace.

public Vector3dc getBlockForceInShipSpace(PhysicsObject physicsObject, double secondsToApply) {
    final ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentPhysicsTransform();
    final Vector3dc idealLinearVelocity = shipTransform.transformDirectionNew(new Vector3d(targetLinearVelocity), TransformType.SUBSPACE_TO_GLOBAL);
    final Vector3dc currentLinearVelocity = physicsObject.getPhysicsCalculations().getLinearVelocity();
    final Vector3dc velocityDifference = idealLinearVelocity.sub(currentLinearVelocity, new Vector3d());
    final Vector3d resultingBlockForce = new Vector3d(velocityDifference);
    resultingBlockForce.mul(physicsObject.getInertiaData().getGameTickMass());
    resultingBlockForce.mul(secondsToApply);
    resultingBlockForce.mul(LINEAR_EMA_FILTER_CONSTANT);
    // Do not affect y axis
    resultingBlockForce.y = 0;
    return resultingBlockForce;
}
Also used : Vector3dc(org.joml.Vector3dc) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d)

Aggregations

ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)32 Vector3d (org.joml.Vector3d)18 Vector3dc (org.joml.Vector3dc)15 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)9 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)7 World (net.minecraft.world.World)7 ShipData (org.valkyrienskies.mod.common.ships.ShipData)6 UUID (java.util.UUID)4 Nullable (javax.annotation.Nullable)4 BlockPos (net.minecraft.util.math.BlockPos)4 Vec3d (net.minecraft.util.math.Vec3d)4 IPhysObjectWorld (org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld)4 IBlockState (net.minecraft.block.state.IBlockState)3 Entity (net.minecraft.entity.Entity)3 Chunk (net.minecraft.world.chunk.Chunk)3 EntityShipMovementData (org.valkyrienskies.mod.common.entity.EntityShipMovementData)3 DecimalFormat (java.text.DecimalFormat)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 ExtendedBlockStorage (net.minecraft.world.chunk.storage.ExtendedBlockStorage)2