Search in sources :

Example 61 with PhysicsWrapperEntity

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

the class CallRunner method getDistanceSq.

public static double getDistanceSq(double vanilla, Entity entity, double x, double y, double z) {
    if (vanilla < 64.0D) {
        return vanilla;
    } else {
        BlockPos pos = new BlockPos(x, y, z);
        PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(entity.worldObj, pos);
        if (wrapper != null) {
            Vector posVec = new Vector(x, y, z);
            wrapper.wrapping.coordTransform.fromLocalToGlobal(posVec);
            posVec.X -= entity.posX;
            posVec.Y -= entity.posY;
            posVec.Z -= entity.posZ;
            if (vanilla > posVec.lengthSq()) {
                return posVec.lengthSq();
            }
        }
    }
    return vanilla;
}
Also used : PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) BlockPos(net.minecraft.util.math.BlockPos) Vector(ValkyrienWarfareBase.API.Vector)

Example 62 with PhysicsWrapperEntity

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

the class CallRunner method onGetLook.

public static Vec3d onGetLook(Entity entityFor, float partialTicks) {
    Vec3d defaultOutput = entityFor.getLook(partialTicks);
    PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getShipFixedOnto(entityFor);
    if (wrapper != null) {
        Vector newOutput = new Vector(defaultOutput);
        RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.RlToWRotation, newOutput);
        return newOutput.toVec3d();
    }
    return defaultOutput;
}
Also used : PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) Vector(ValkyrienWarfareBase.API.Vector) Vec3d(net.minecraft.util.math.Vec3d)

Example 63 with PhysicsWrapperEntity

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

the class HovercraftControllerGUIInputHandler method onMessage.

@Override
public IMessage onMessage(final HovercraftControllerGUIInputMessage message, final MessageContext ctx) {
    IThreadListener mainThread = ctx.getServerHandler().serverController;
    mainThread.addScheduledTask(new Runnable() {

        @Override
        public void run() {
            PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(ctx.getServerHandler().playerEntity.worldObj, message.tilePos);
            TileEntity tileEnt = wrapper.wrapping.VKChunkCache.getTileEntity(message.tilePos);
            if (tileEnt != null) {
                if (tileEnt instanceof TileEntityHoverController) {
                    ((TileEntityHoverController) tileEnt).handleGUIInput(message, ctx);
                }
            } else {
                System.out.println("Player: " + ctx.getServerHandler().playerEntity.getName() + " sent a broken packet");
            }
        }
    });
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) IThreadListener(net.minecraft.util.IThreadListener) TileEntityHoverController(ValkyrienWarfareControl.TileEntity.TileEntityHoverController)

Example 64 with PhysicsWrapperEntity

use of ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity 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)

Example 65 with PhysicsWrapperEntity

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

the class PilotControlsMessageHandler method onMessage.

@Override
public IMessage onMessage(final PilotControlsMessage message, final MessageContext ctx) {
    IThreadListener mainThread = ctx.getServerHandler().serverController;
    mainThread.addScheduledTask(new Runnable() {

        @Override
        public void run() {
            World worldObj = ctx.getServerHandler().playerEntity.worldObj;
            if (ValkyrienWarfareMod.physicsManager.getManagerForWorld(worldObj) != null) {
                UUID shipId = message.shipFor;
                for (PhysicsWrapperEntity entity : ValkyrienWarfareMod.physicsManager.getManagerForWorld(worldObj).physicsEntities) {
                    if (entity.getUniqueID().equals(shipId)) {
                        entity.wrapping.pilotingController.receivePilotControlsMessage(message, ctx.getServerHandler().playerEntity);
                    }
                }
            }
        }
    });
    return null;
}
Also used : PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) IThreadListener(net.minecraft.util.IThreadListener) World(net.minecraft.world.World) UUID(java.util.UUID)

Aggregations

PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)69 BlockPos (net.minecraft.util.math.BlockPos)29 Vector (ValkyrienWarfareBase.API.Vector)28 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 IBlockState (net.minecraft.block.state.IBlockState)9 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)9 TextComponentString (net.minecraft.util.text.TextComponentString)9 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)8 Vec3d (net.minecraft.util.math.Vec3d)7 WorldPhysObjectManager (ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager)6 Block (net.minecraft.block.Block)6 Entity (net.minecraft.entity.Entity)6 TileEntity (net.minecraft.tileentity.TileEntity)6 IThreadListener (net.minecraft.util.IThreadListener)5 World (net.minecraft.world.World)5 Quaternion (ValkyrienWarfareBase.Math.Quaternion)4 ArrayList (java.util.ArrayList)4 RayTraceResult (net.minecraft.util.math.RayTraceResult)4 EntityPolygon (ValkyrienWarfareBase.Collision.EntityPolygon)3 Polygon (ValkyrienWarfareBase.Collision.Polygon)3