Search in sources :

Example 1 with WorldPhysObjectManager

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

the class CallRunner method rayTraceBlocksIgnoreShip.

public static RayTraceResult rayTraceBlocksIgnoreShip(World world, Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock, PhysicsWrapperEntity toIgnore) {
    RayTraceResult vanillaTrace = world.rayTraceBlocks(vec31, vec32, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
    WorldPhysObjectManager physManager = ValkyrienWarfareMod.physicsManager.getManagerForWorld(world);
    if (physManager == null) {
        return vanillaTrace;
    }
    Vec3d playerEyesPos = vec31;
    Vec3d playerReachVector = vec32.subtract(vec31);
    AxisAlignedBB playerRangeBB = new AxisAlignedBB(vec31.xCoord, vec31.yCoord, vec31.zCoord, vec32.xCoord, vec32.yCoord, vec32.zCoord);
    List<PhysicsWrapperEntity> nearbyShips = physManager.getNearbyPhysObjects(playerRangeBB);
    //Get rid of the Ship that we're not supposed to be RayTracing for
    nearbyShips.remove(toIgnore);
    boolean changed = false;
    double reachDistance = playerReachVector.lengthVector();
    double worldResultDistFromPlayer = 420000000D;
    if (vanillaTrace != null && vanillaTrace.hitVec != null) {
        worldResultDistFromPlayer = vanillaTrace.hitVec.distanceTo(vec31);
    }
    for (PhysicsWrapperEntity wrapper : nearbyShips) {
        playerEyesPos = vec31;
        playerReachVector = vec32.subtract(vec31);
        // TODO: Re-enable
        if (world.isRemote) {
        // ValkyrienWarfareMod.proxy.updateShipPartialTicks(wrapper);
        }
        // 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;
            }
        }
    }
    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 2 with WorldPhysObjectManager

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

the class ShipPilotingController method getShipPlayerIsPiloting.

public static PhysicsWrapperEntity getShipPlayerIsPiloting(EntityPlayer pilot) {
    World playerWorld = pilot.worldObj;
    WorldPhysObjectManager worldManager = ValkyrienWarfareMod.physicsManager.getManagerForWorld(playerWorld);
    for (PhysicsWrapperEntity wrapperEntity : worldManager.physicsEntities) {
        if (wrapperEntity.wrapping.pilotingController.getPilotEntity() == pilot) {
            return wrapperEntity;
        }
    }
    return null;
}
Also used : WorldPhysObjectManager(ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) World(net.minecraft.world.World)

Example 3 with WorldPhysObjectManager

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

the class BlockPhysicsInfuser method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        WorldPhysObjectManager manager = ValkyrienWarfareMod.physicsManager.getManagerForWorld(worldIn);
        if (manager != null) {
            PhysicsWrapperEntity wrapperEnt = manager.getManagingObjectForChunk(worldIn.getChunkFromBlockCoords(pos));
            if (wrapperEnt != null) {
                wrapperEnt.wrapping.doPhysics = !wrapperEnt.wrapping.doPhysics;
                return true;
            }
        }
        if (ValkyrienWarfareMod.canChangeAirshipCounter(true, playerIn)) {
            PhysicsWrapperEntity wrapper = new PhysicsWrapperEntity(worldIn, pos.getX(), pos.getY(), pos.getZ(), playerIn, shipSpawnDetectorID, ShipType.Full_Unlocked);
            worldIn.spawnEntityInWorld(wrapper);
        } else {
            playerIn.addChatMessage(new TextComponentString("You've made too many airships! The limit per player is " + ValkyrienWarfareMod.maxAirships));
        }
    }
    return true;
}
Also used : WorldPhysObjectManager(ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 4 with WorldPhysObjectManager

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

the class EventsClient method onClientTickEvent.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onClientTickEvent(ClientTickEvent event) {
    if (mc.theWorld != null) {
        if (!mc.isGamePaused()) {
            WorldPhysObjectManager manager = ValkyrienWarfareMod.physicsManager.getManagerForWorld(mc.theWorld);
            if (event.phase == Phase.END) {
                for (PhysicsWrapperEntity wrapper : manager.physicsEntities) {
                    wrapper.wrapping.onPostTickClient();
                }
                EntityDraggable.tickAddedVelocityForWorld(mc.theWorld);
            }
        }
        if (event.phase == Phase.END) {
            Object o = Minecraft.getMinecraft().thePlayer;
            EntityDraggable draggable = (EntityDraggable) o;
            if (draggable.worldBelowFeet != null) {
                PlayerShipRefrenceMessage playerPosMessage = new PlayerShipRefrenceMessage(Minecraft.getMinecraft().thePlayer, draggable.worldBelowFeet);
                ValkyrienWarfareMod.physWrapperNetwork.sendToServer(playerPosMessage);
            }
        }
    }
}
Also used : WorldPhysObjectManager(ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager) EntityDraggable(ValkyrienWarfareBase.Interaction.EntityDraggable) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) PlayerShipRefrenceMessage(ValkyrienWarfareBase.Network.PlayerShipRefrenceMessage) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with WorldPhysObjectManager

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

the class EntityCollisionInjector method getCollidingPolygonsAndDoBlockCols.

/*
	 * This method generates an arrayList of Polygons that the player is colliding with
	 */
public static ArrayList<Polygon> getCollidingPolygonsAndDoBlockCols(Entity entity, Vec3d velocity) {
    ArrayList<Polygon> collisions = new ArrayList<Polygon>();
    AxisAlignedBB entityBB = entity.getEntityBoundingBox().addCoord(velocity.xCoord, velocity.yCoord, velocity.zCoord).expand(1, 1, 1);
    WorldPhysObjectManager localPhysManager = ValkyrienWarfareMod.physicsManager.getManagerForWorld(entity.worldObj);
    List<PhysicsWrapperEntity> ships = localPhysManager.getNearbyPhysObjects(entityBB);
    //If a player is riding a Ship, don't process any collision between that Ship and the Player
    for (PhysicsWrapperEntity wrapper : ships) {
        if (!entity.isRidingSameEntity(wrapper)) {
            Polygon playerInLocal = new Polygon(entityBB, wrapper.wrapping.coordTransform.wToLTransform);
            AxisAlignedBB bb = playerInLocal.getEnclosedAABB();
            if ((bb.maxX - bb.minX) * (bb.maxZ - bb.minZ) > 9898989) {
                //This is too big, something went wrong here
                break;
            }
            List<AxisAlignedBB> collidingBBs = entity.worldObj.getCollisionBoxes(bb);
            // TODO: Fix the performance of this!
            if (entity.worldObj.isRemote || entity instanceof EntityPlayer) {
                BigBastardMath.mergeAABBList(collidingBBs);
            }
            for (AxisAlignedBB inLocal : collidingBBs) {
                ShipPolygon poly = new ShipPolygon(inLocal, wrapper.wrapping.coordTransform.lToWTransform, wrapper.wrapping.coordTransform.normals, wrapper.wrapping);
                collisions.add(poly);
            }
        }
    }
    for (PhysicsWrapperEntity wrapper : ships) {
        if (!entity.isRidingSameEntity(wrapper)) {
            double posX = entity.posX;
            double posY = entity.posY;
            double posZ = entity.posZ;
            Vector entityPos = new Vector(posX, posY, posZ);
            RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.wToLTransform, entityPos);
            setEntityPositionAndUpdateBB(entity, entityPos.X, entityPos.Y, entityPos.Z);
            int entityChunkX = MathHelper.floor_double(entity.posX / 16.0D);
            int entityChunkZ = MathHelper.floor_double(entity.posZ / 16.0D);
            if (wrapper.wrapping.ownsChunk(entityChunkX, entityChunkZ)) {
                Chunk chunkIn = wrapper.wrapping.claimedChunks[entityChunkX - wrapper.wrapping.claimedChunks[0][0].xPosition][entityChunkZ - wrapper.wrapping.claimedChunks[0][0].zPosition];
                int chunkYIndex = MathHelper.floor_double(entity.posY / 16.0D);
                if (chunkYIndex < 0) {
                    chunkYIndex = 0;
                }
                if (chunkYIndex >= chunkIn.entityLists.length) {
                    chunkYIndex = chunkIn.entityLists.length - 1;
                }
                chunkIn.entityLists[chunkYIndex].add(entity);
                entity.doBlockCollisions();
                chunkIn.entityLists[chunkYIndex].remove(entity);
            }
            setEntityPositionAndUpdateBB(entity, posX, posY, posZ);
        }
    }
    return collisions;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ArrayList(java.util.ArrayList) Chunk(net.minecraft.world.chunk.Chunk) WorldPhysObjectManager(ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Vector(ValkyrienWarfareBase.API.Vector)

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