Search in sources :

Example 31 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityCannonBall method processMovementForTick.

private void processMovementForTick() {
    Vec3d origin = new Vec3d(posX, posY, posZ);
    Vec3d traceEnd = origin.addVector(motionX, motionY, motionZ);
    RayTraceResult traceResult = CallRunner.onRayTraceBlocks(worldObj, origin, traceEnd, false, true, false);
    if (traceResult == null || traceResult.typeOfHit == Type.MISS) {
        posX += motionX;
        posY += motionY;
        posZ += motionZ;
        // double drag = .98D;
        // motionX*=drag;
        // motionY*=drag;
        // motionZ*=drag;
        motionY -= .01;
    } else {
        if (traceResult.hitVec != null && !worldObj.isRemote) {
            processCollision(traceResult);
            kill();
        }
    }
}
Also used : RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d)

Example 32 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult 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

RayTraceResult (net.minecraft.util.math.RayTraceResult)32 ItemStack (net.minecraft.item.ItemStack)16 IBlockState (net.minecraft.block.state.IBlockState)12 Vec3d (net.minecraft.util.math.Vec3d)12 Entity (net.minecraft.entity.Entity)11 BlockPos (net.minecraft.util.math.BlockPos)11 TileEntity (net.minecraft.tileentity.TileEntity)9 Block (net.minecraft.block.Block)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 World (net.minecraft.world.World)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 EntityLivingBase (net.minecraft.entity.EntityLivingBase)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)4 ArrayList (java.util.ArrayList)4 Vector (ValkyrienWarfareBase.API.Vector)2 WorldPhysObjectManager (ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager)2 ChemthrowerEffect_Potion (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2 EntityArmorStand (net.minecraft.entity.item.EntityArmorStand)2