Search in sources :

Example 1 with SailBlock

use of com.simibubi.create.content.contraptions.components.structureMovement.bearing.SailBlock in project Create_Aeronautics by Eriksonnaren.

the class SimulatedContraptionRigidbody method updateWings.

void updateWings() {
    for (Map.Entry<BlockPos, BlockState> entry : entity.sails.entrySet()) {
        Vector3d pos = getLocalCoordinate(entry.getKey());
        Vector3d vel = getLocalVelocityAtPosition(pos);
        Vector3d normal = getFacingVector(entry.getValue());
        Vector3d force = normal.scale(-0.8f * normal.dot(vel));
        addForce(force, pos);
    }
    for (Map.Entry<UUID, ControlledContraptionEntity> contraptionEntityEntry : entity.subContraptions.entrySet()) {
        // TODO: make propellers not provide lift
        if (contraptionEntityEntry.getValue() != null) {
            Contraption subContraption = contraptionEntityEntry.getValue().getContraption();
            for (Map.Entry<BlockPos, Template.BlockInfo> blockStateEntry : subContraption.getBlocks().entrySet()) {
                if (blockStateEntry.getValue().state.getBlock() instanceof SailBlock) {
                    Vector3d pos = contraptionEntityEntry.getValue().applyRotation(VecHelper.getCenterOf(blockStateEntry.getKey()), 0);
                    pos.subtract(centerOfMass);
                    Vector3d vel = getLocalVelocityAtPosition(pos);
                    Vector3d normal = getFacingVector(blockStateEntry.getValue().state);
                    normal = contraptionEntityEntry.getValue().applyRotation(normal, 0);
                    Vector3d force = normal.scale(-0.8f * normal.dot(vel));
                    addForce(force, pos);
                }
            }
        }
    }
}
Also used : ControlledContraptionEntity(com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity) BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) Contraption(com.simibubi.create.content.contraptions.components.structureMovement.Contraption) AirshipContraption(com.eriksonn.createaeronautics.contraptions.AirshipContraption) SailBlock(com.simibubi.create.content.contraptions.components.structureMovement.bearing.SailBlock)

Aggregations

AirshipContraption (com.eriksonn.createaeronautics.contraptions.AirshipContraption)1 Contraption (com.simibubi.create.content.contraptions.components.structureMovement.Contraption)1 ControlledContraptionEntity (com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity)1 SailBlock (com.simibubi.create.content.contraptions.components.structureMovement.bearing.SailBlock)1 BlockState (net.minecraft.block.BlockState)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1