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));
}
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;
}
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);
}
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");
}
}
}
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);
}
Aggregations