Search in sources :

Example 6 with WorldPhysObjectManager

use of ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ClientPilotingManager method rayTraceExcludingWrapper.

//Used to make Pilot 3rd person the 20 block range it is, without stopping on the ship the player is piloting
public static final RayTraceResult rayTraceExcludingWrapper(World world, Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock, PhysicsWrapperEntity toExclude) {
    RayTraceResult vanillaTrace = world.rayTraceBlocks(vec31, vec32, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
    WorldPhysObjectManager physManager = ValkyrienWarfareMod.physicsManager.getManagerForWorld(world);
    AxisAlignedBB playerRangeBB = new AxisAlignedBB(vec31.xCoord - 1D, vec31.yCoord - 1D, vec31.zCoord - 1D, vec31.xCoord + 1D, vec31.yCoord + 1D, vec31.zCoord + 1D);
    List<PhysicsWrapperEntity> nearbyShips = physManager.getNearbyPhysObjects(playerRangeBB);
    boolean changed = false;
    Vec3d playerEyesPos = vec31;
    Vec3d playerReachVector = vec32.subtract(vec31);
    double reachDistance = playerReachVector.lengthVector();
    double worldResultDistFromPlayer = 420D;
    if (vanillaTrace != null && vanillaTrace.hitVec != null) {
        worldResultDistFromPlayer = vanillaTrace.hitVec.distanceTo(vec31);
    }
    for (PhysicsWrapperEntity wrapper : nearbyShips) {
        if (ClientPilotingManager.getPilotedWrapperEntity() != null && wrapper.getEntityId() != ClientPilotingManager.getPilotedWrapperEntity().getEntityId()) {
            playerEyesPos = vec31;
            playerReachVector = vec32.subtract(vec31);
            // Transform the coordinate system for the player eye pos
            playerEyesPos = RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.RwToLTransform, playerEyesPos);
            playerReachVector = RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.RwToLRotation, playerReachVector);
            Vec3d playerEyesReachAdded = playerEyesPos.addVector(playerReachVector.xCoord * reachDistance, playerReachVector.yCoord * reachDistance, playerReachVector.zCoord * reachDistance);
            RayTraceResult resultInShip = world.rayTraceBlocks(playerEyesPos, playerEyesReachAdded, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
            if (resultInShip != null && resultInShip.hitVec != null && resultInShip.typeOfHit == Type.BLOCK) {
                double shipResultDistFromPlayer = resultInShip.hitVec.distanceTo(playerEyesPos);
                if (shipResultDistFromPlayer < worldResultDistFromPlayer) {
                    worldResultDistFromPlayer = shipResultDistFromPlayer;
                    resultInShip.hitVec = RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.RlToWTransform, resultInShip.hitVec);
                    vanillaTrace = resultInShip;
                }
            }
        } else {
            if (ClientPilotingManager.getMountedWrapperEntity() != null) {
            // System.out.println("test");
            }
        }
    }
    return vanillaTrace;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) WorldPhysObjectManager(ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)6 WorldPhysObjectManager (ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager)6 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 Vec3d (net.minecraft.util.math.Vec3d)2 Vector (ValkyrienWarfareBase.API.Vector)1 EntityDraggable (ValkyrienWarfareBase.Interaction.EntityDraggable)1 PlayerShipRefrenceMessage (ValkyrienWarfareBase.Network.PlayerShipRefrenceMessage)1 ArrayList (java.util.ArrayList)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 World (net.minecraft.world.World)1 Chunk (net.minecraft.world.chunk.Chunk)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1