Search in sources :

Example 11 with ShipTransform

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

the class PhysicsCalculations method rawPhysTickPostCol.

public void rawPhysTickPostCol() {
    if (!isPhysicsBroken()) {
        // This wasn't implemented very well at all! Maybe in the future I'll try again.
        // enforceStaticFriction();
        integrateAngularVelocity();
        integrateLinearVelocity();
    } else {
        getParent().getShipData().setPhysicsEnabled(false);
        getLinearVelocity().zero();
        getAngularVelocity().zero();
    }
    // Keep track of the forced transform, if there is one
    final boolean forceToUseGameTransformLocalCopy = this.forceToUseGameTransform;
    // Reset the forced transform
    this.forceToUseGameTransform = false;
    if (forceToUseGameTransformLocalCopy) {
        // Reset the physics transform to be the game tick transform
        generatePhysicsTransform();
        // Reset angular and linear velocities
        angularVelocity.zero();
        linearVelocity.zero();
    }
    ShipTransform finalPhysTransform = new ShipTransform(physX, physY, physZ, physRotation, physCenterOfMass);
    getParent().getShipTransformationManager().updatePreviousPhysicsTransform();
    getParent().getShipTransformationManager().setCurrentPhysicsTransform(finalPhysTransform);
    // Save a copy of linear and angular velocity in parent's ShipData
    getParent().getShipData().getPhysicsData().setAngularVelocity(new Vector3d(angularVelocity));
    getParent().getShipData().getPhysicsData().setLinearVelocity(new Vector3d(linearVelocity));
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d)

Example 12 with ShipTransform

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

the class TileEntityBoatChair method getBlockForceInShipSpace.

@Nullable
public Vector3dc getBlockForceInShipSpace(World world, BlockPos pos, IBlockState state, PhysicsObject physicsObject, double secondsToApply) {
    // Don't add force if theres no pilot
    if (getPilotEntity() == null) {
        return null;
    }
    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) Nullable(javax.annotation.Nullable)

Example 13 with ShipTransform

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

the class ValkyrienUtils method createNewShip.

/**
 * Creates a new ShipIndexedData based on the inputs provided by the physics infuser block.
 */
public ShipData createNewShip(World world, BlockPos physInfuserPos) {
    String name = NounListNameGenerator.getInstance().generateName();
    UUID shipID = UUID.randomUUID();
    // Create ship chunk claims
    VSChunkClaim chunkClaim = ValkyrienUtils.getShipChunkAllocator(world).allocateNextChunkClaim();
    Vector3dc centerOfMassInitial = VSMath.toVector3d(chunkClaim.getRegionCenter());
    Vector3dc shipPosInitial = VSMath.toVector3d(physInfuserPos);
    ShipTransform initial = new ShipTransform(shipPosInitial, centerOfMassInitial);
    AxisAlignedBB axisAlignedBB = new AxisAlignedBB(shipPosInitial.x(), shipPosInitial.y(), shipPosInitial.z(), shipPosInitial.x(), shipPosInitial.y(), shipPosInitial.z());
    return ShipData.createData(QueryableShipData.get(world).getAllShips(), name, chunkClaim, shipID, initial, axisAlignedBB);
}
Also used : Vector3dc(org.joml.Vector3dc) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) VSChunkClaim(org.valkyrienskies.mod.common.ships.chunk_claims.VSChunkClaim) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) UUID(java.util.UUID)

Example 14 with ShipTransform

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

the class MixinEntityPlayer method preGetBedSpawnLocation.

@Inject(method = "getBedSpawnLocation", at = @At("HEAD"), cancellable = true)
private static void preGetBedSpawnLocation(World worldIn, BlockPos bedLocation, boolean forceSpawn, CallbackInfoReturnable<BlockPos> callbackInfo) {
    Optional<ShipData> shipData = ValkyrienUtils.getQueryableData(worldIn).getShipFromBlock(bedLocation);
    if (shipData.isPresent()) {
        ShipTransform positionData = shipData.get().getShipTransform();
        if (positionData != null) {
            Vector3d bedLocationD = JOML.castDouble(JOML.convert(bedLocation)).add(0.5, 0.5, 0.5);
            positionData.getSubspaceToGlobal().transformPosition(bedLocationD);
            bedLocationD.y += 1D;
            bedLocation = JOML.toMinecraft(JOML.castInt(bedLocationD));
            callbackInfo.setReturnValue(bedLocation);
        } else {
            System.err.println("A ship just had chunks claimed persistent, but not any position data persistent");
        }
    }
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) ShipData(org.valkyrienskies.mod.common.ships.ShipData) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 15 with ShipTransform

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

the class MixinMinecraft method rightClickBlockProxy.

/**
 * This mixin fixes slabs not placing correctly on ships.
 */
@Redirect(method = "rightClickMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;processRightClickBlock(Lnet/minecraft/client/entity/EntityPlayerSP;Lnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/EnumHand;)Lnet/minecraft/util/EnumActionResult;"))
private EnumActionResult rightClickBlockProxy(PlayerControllerMP playerControllerMP, EntityPlayerSP player, WorldClient worldIn, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand) {
    // Check if this is for a ship
    final Optional<ShipData> shipDataOptional = ValkyrienUtils.getShipManagingBlock(worldIn, pos);
    if (shipDataOptional.isPresent()) {
        // This ray trace was in the ship, we're going to have to mess with the hit vector
        final ShipData shipData = shipDataOptional.get();
        final ShipTransform shipTransform = shipData.getShipTransform();
        // Put the hit vector in ship coordinates
        final Vector3d hitVecInLocal = JOML.convert(vec);
        shipTransform.transformPosition(hitVecInLocal, TransformType.GLOBAL_TO_SUBSPACE);
        final Vec3d moddedHitVec = JOML.toMinecraft(hitVecInLocal);
        return playerControllerMP.processRightClickBlock(player, worldIn, pos, direction, moddedHitVec, hand);
    }
    return playerControllerMP.processRightClickBlock(player, worldIn, pos, direction, vec, hand);
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) ShipData(org.valkyrienskies.mod.common.ships.ShipData) Vec3d(net.minecraft.util.math.Vec3d) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

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