use of org.valkyrienskies.mod.common.block.IBlockForceProvider in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class BlockPhysicsDetails method getForceFromState.
/**
* Assigns the output parameter of toSet to be the force Vector for the given IBlockState.
*/
static void getForceFromState(IBlockState state, BlockPos pos, World world, double secondsToApply, PhysicsObject obj, Vector3d toSet) {
Block block = state.getBlock();
if (block instanceof IBlockForceProvider) {
Vector3dc forceVector = ((IBlockForceProvider) block).getBlockForceInWorldSpace(world, pos, state, obj, secondsToApply);
if (forceVector == null) {
toSet.zero();
} else {
toSet.x = forceVector.x();
toSet.y = forceVector.y();
toSet.z = forceVector.z();
}
}
}
use of org.valkyrienskies.mod.common.block.IBlockForceProvider in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsCalculations method calculateForces.
private void calculateForces() {
applyAirDrag();
applyGravity();
Vector3d blockForce = new Vector3d();
Vector3d inBodyWO = new Vector3d();
Vector3d crossVector = new Vector3d();
World worldObj = getParent().getWorld();
if (VSConfig.doPhysicsBlocks) {
// We want to loop through all the physics nodes in a sorted order. Priority Queue handles that.
Queue<IPhysicsBlockController> nodesPriorityQueue = new PriorityQueue<>(parent.getPhysicsControllersInShip());
while (nodesPriorityQueue.size() > 0) {
IPhysicsBlockController controller = nodesPriorityQueue.poll();
controller.onPhysicsTick(parent, this, this.getPhysicsTimeDeltaPerPhysTick());
}
SortedMap<IBlockTorqueProvider, List<BlockPos>> torqueProviders = new TreeMap<>();
BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();
// Note that iterating over "activeForcePositions" is not thread safe, so this could lead to problems.
// However we're going to completely replace this code soon anyways, so its not a big deal.
parent.getShipData().activeForcePositions.forEachUnsafe((x, y, z) -> {
mutablePos.setPos(x, y, z);
IBlockState state = getParent().getChunkAt(mutablePos.getX() >> 4, mutablePos.getZ() >> 4).getBlockState(mutablePos);
Block blockAt = state.getBlock();
if (blockAt instanceof IBlockForceProvider) {
try {
BlockPhysicsDetails.getForceFromState(state, mutablePos, worldObj, getPhysicsTimeDeltaPerPhysTick(), getParent(), blockForce);
Vector3dc otherPosition = ((IBlockForceProvider) blockAt).getCustomBlockForcePosition(worldObj, mutablePos, state, getParent(), getPhysicsTimeDeltaPerPhysTick());
if (otherPosition != null) {
inBodyWO.set(otherPosition);
inBodyWO.sub(physCenterOfMass);
getParent().getShipTransformationManager().getCurrentPhysicsTransform().transformDirection(inBodyWO, TransformType.SUBSPACE_TO_GLOBAL);
} else {
inBodyWO.set(mutablePos.getX() + .5, mutablePos.getY() + .5, mutablePos.getZ() + .5);
inBodyWO.sub(physCenterOfMass);
getParent().getShipTransformationManager().getCurrentPhysicsTransform().transformDirection(inBodyWO, TransformType.SUBSPACE_TO_GLOBAL);
}
addForceAtPoint(inBodyWO, blockForce, crossVector);
} catch (Exception e) {
e.printStackTrace();
}
}
if (blockAt instanceof IBlockTorqueProvider) {
// Add it to the torque sorted map; we do this so the torque dampeners can run
// after the gyroscope stabilizers.
IBlockTorqueProvider torqueProviderBlock = (IBlockTorqueProvider) blockAt;
if (!torqueProviders.containsKey(torqueProviderBlock)) {
torqueProviders.put(torqueProviderBlock, new LinkedList<>());
}
torqueProviders.get(torqueProviderBlock).add(new BlockPos(x, y, z));
}
});
// Now add the torque from the torque providers, in a sorted order!
for (IBlockTorqueProvider torqueProviderBlock : torqueProviders.keySet()) {
List<BlockPos> blockPositions = torqueProviders.get(torqueProviderBlock);
for (BlockPos pos : blockPositions) {
this.convertTorqueToVelocity();
Vector3dc torqueVector = torqueProviderBlock.getTorqueInGlobal(this, pos);
if (torqueVector != null) {
torque.add(torqueVector);
}
}
}
}
// Add pilot input
final ShipPilot parentPilot = parent.getShipPilot();
if (parentPilot != null) {
final Vector3dc pilotForce = parentPilot.getBlockForceInShipSpace(parent, physTickTimeDelta);
final Vector3dc pilotTorque = parentPilot.getTorqueInGlobal(this);
this.linearVelocity.fma(getInvMass(), pilotForce);
this.torque.add(pilotTorque);
}
convertTorqueToVelocity();
}
Aggregations