Search in sources :

Example 66 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 67 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)

Example 68 with PhysicsWrapperEntity

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

the class ShipPilotingController method setPilotEntity.

/**
	 * Sets the inputed player as the pilot of this ship
	 * @param toSet
	 * @param ignorePilotConflicts Should be set to false for almost every single case
	 */
public void setPilotEntity(EntityPlayerMP toSet, boolean ignorePilotConflicts) {
    if (shipPilot != null) {
        sendPlayerPilotingPacket(shipPilot, null);
        //TEMPORARY CODE!!!
        controlledShip.physicsProcessor.actAsArchimedes = false;
    } else {
        //TEMPORARY CODE!!!
        controlledShip.physicsProcessor.actAsArchimedes = true;
    }
    if (toSet != null) {
        //Send packets here or something
        mostRecentPilotID = toSet.getPersistentID();
        PhysicsWrapperEntity otherShipPiloted = getShipPlayerIsPiloting(toSet);
        if (otherShipPiloted != null) {
            //Removes this player from piloting the other ship
            otherShipPiloted.wrapping.pilotingController.setPilotEntity(null, true);
        }
        sendPlayerPilotingPacket(toSet, controlledShip.wrapper);
    } else {
        mostRecentPilotID = null;
    }
    shipPilot = toSet;
}
Also used : PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)

Example 69 with PhysicsWrapperEntity

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

the class ItemShipStealer method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    BlockPos looking = playerIn.rayTrace(playerIn.isCreative() ? 5.0 : 4.5, 1).getBlockPos();
    PhysicsWrapperEntity entity = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(playerIn.getEntityWorld(), looking);
    if (entity != null) {
        String oldOwner = entity.wrapping.creator;
        if (oldOwner == playerIn.entityUniqueID.toString()) {
            playerIn.addChatMessage(new TextComponentString("You can't steal your own airship!"));
            return EnumActionResult.SUCCESS;
        }
        switch(entity.wrapping.changeOwner(playerIn)) {
            case ERROR_NEWOWNER_NOT_ENOUGH:
                playerIn.addChatMessage(new TextComponentString("You already own the maximum amount of airships!"));
                break;
            case ERROR_IMPOSSIBLE_STATUS:
                playerIn.addChatMessage(new TextComponentString("Error! Please report to mod devs."));
                break;
            case SUCCESS:
                playerIn.addChatMessage(new TextComponentString("You've stolen an airship!"));
                break;
            case ALREADY_CLAIMED:
                playerIn.addChatMessage(new TextComponentString("You already own that airship!"));
                break;
        }
        return EnumActionResult.SUCCESS;
    }
    playerIn.addChatMessage(new TextComponentString("The block needs to be part of an airship!"));
    return EnumActionResult.SUCCESS;
}
Also used : PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

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