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;
}
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;
}
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;
}
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);
}
}
}
}
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;
}
Aggregations