use of ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsCommon method onPlaceEvent.
@SubscribeEvent
public void onPlaceEvent(PlaceEvent event) {
PhysicsWrapperEntity physObj = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(event.getWorld(), event.getPos());
if (physObj != null) {
if (ValkyrienWarfareMod.runAirshipPermissions && !(physObj.wrapping.creator.equals(event.getPlayer().entityUniqueID.toString()) || physObj.wrapping.allowedUsers.contains(event.getPlayer().entityUniqueID.toString()))) {
event.getPlayer().addChatMessage(new TextComponentString("You need to be added to the airship to do that!" + (physObj.wrapping.creator == null || physObj.wrapping.creator.trim().isEmpty() ? " Try using \"/airshipSettings claim\"!" : "")));
event.setCanceled(true);
return;
}
if (physObj.wrapping.shipType == ShipType.Oribtal) {
//Do not let it place any blocks
// System.out.println("test");
event.setCanceled(true);
}
}
}
use of ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity 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;
}
use of ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class CallRunner method onExplosionA.
public static void onExplosionA(Explosion e) {
Vector center = new Vector(e.explosionX, e.explosionY, e.explosionZ);
World worldIn = e.worldObj;
float radius = e.explosionSize;
AxisAlignedBB toCheck = new AxisAlignedBB(center.X - radius, center.Y - radius, center.Z - radius, center.X + radius, center.Y + radius, center.Z + radius);
List<PhysicsWrapperEntity> shipsNear = ValkyrienWarfareMod.physicsManager.getManagerForWorld(e.worldObj).getNearbyPhysObjects(toCheck);
e.doExplosionA();
// TODO: Make this compatible and shit!
for (PhysicsWrapperEntity ship : shipsNear) {
Vector inLocal = new Vector(center);
RotationMatrices.applyTransform(ship.wrapping.coordTransform.wToLTransform, inLocal);
// inLocal.roundToWhole();
Explosion expl = new Explosion(ship.worldObj, null, inLocal.X, inLocal.Y, inLocal.Z, radius, false, false);
double waterRange = .6D;
boolean cancelDueToWater = false;
for (int x = (int) Math.floor(expl.explosionX - waterRange); x <= Math.ceil(expl.explosionX + waterRange); x++) {
for (int y = (int) Math.floor(expl.explosionY - waterRange); y <= Math.ceil(expl.explosionY + waterRange); y++) {
for (int z = (int) Math.floor(expl.explosionZ - waterRange); z <= Math.ceil(expl.explosionZ + waterRange); z++) {
if (!cancelDueToWater) {
IBlockState state = e.worldObj.getBlockState(new BlockPos(x, y, z));
if (state.getBlock() instanceof BlockLiquid) {
cancelDueToWater = true;
}
}
}
}
}
expl.doExplosionA();
double affectedPositions = 0D;
for (Object o : expl.affectedBlockPositions) {
BlockPos pos = (BlockPos) o;
IBlockState state = ship.worldObj.getBlockState(pos);
Block block = state.getBlock();
if (!block.isAir(state, worldIn, (BlockPos) o) || ship.wrapping.explodedPositionsThisTick.contains((BlockPos) o)) {
affectedPositions++;
}
}
if (!cancelDueToWater) {
for (Object o : expl.affectedBlockPositions) {
BlockPos pos = (BlockPos) o;
IBlockState state = ship.worldObj.getBlockState(pos);
Block block = state.getBlock();
if (!block.isAir(state, worldIn, (BlockPos) o) || ship.wrapping.explodedPositionsThisTick.contains((BlockPos) o)) {
if (block.canDropFromExplosion(expl)) {
block.dropBlockAsItemWithChance(ship.worldObj, pos, state, 1.0F / expl.explosionSize, 0);
}
block.onBlockExploded(ship.worldObj, pos, expl);
if (!worldIn.isRemote) {
Vector posVector = new Vector(pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5);
ship.wrapping.coordTransform.fromLocalToGlobal(posVector);
double mass = BlockMass.basicMass.getMassFromState(state, pos, ship.worldObj);
double explosionForce = Math.sqrt(e.explosionSize) * 1000D * mass;
Vector forceVector = new Vector(pos.getX() + .5 - expl.explosionX, pos.getY() + .5 - expl.explosionY, pos.getZ() + .5 - expl.explosionZ);
double vectorDist = forceVector.length();
forceVector.normalize();
forceVector.multiply(explosionForce / vectorDist);
RotationMatrices.doRotationOnly(ship.wrapping.coordTransform.lToWRotation, forceVector);
PhysicsQueuedForce queuedForce = new PhysicsQueuedForce(forceVector, posVector, false, 1);
if (!ship.wrapping.explodedPositionsThisTick.contains(pos)) {
ship.wrapping.explodedPositionsThisTick.add(pos);
}
ship.wrapping.queueForce(queuedForce);
}
}
}
}
}
}
use of ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class CallRunner method onGetEntitiesWithinAABB.
public static <T extends Entity> List<T> onGetEntitiesWithinAABB(World world, Class<? extends T> clazz, AxisAlignedBB aabb, @Nullable Predicate<? super T> filter) {
List toReturn = world.getEntitiesWithinAABB(clazz, aabb, filter);
BlockPos pos = new BlockPos((aabb.minX + aabb.maxX) / 2D, (aabb.minY + aabb.maxY) / 2D, (aabb.minZ + aabb.maxZ) / 2D);
PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(world, pos);
if (wrapper != null) {
Polygon poly = new Polygon(aabb, wrapper.wrapping.coordTransform.lToWTransform);
//.contract(.3D);
aabb = poly.getEnclosedAABB();
toReturn.addAll(world.getEntitiesWithinAABB(clazz, aabb, filter));
}
return toReturn;
}
use of ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class CallRunner method onIsOnLadder.
public static boolean onIsOnLadder(EntityLivingBase base) {
boolean vanilla = base.isOnLadder();
if (vanilla) {
return true;
}
if (base instanceof EntityPlayer && ((EntityPlayer) base).isSpectator()) {
return false;
}
List<PhysicsWrapperEntity> nearbyPhys = ValkyrienWarfareMod.physicsManager.getManagerForWorld(base.worldObj).getNearbyPhysObjects(base.getEntityBoundingBox());
for (PhysicsWrapperEntity physWrapper : nearbyPhys) {
Vector playerPos = new Vector(base);
physWrapper.wrapping.coordTransform.fromGlobalToLocal(playerPos);
int i = MathHelper.floor_double(playerPos.X);
int j = MathHelper.floor_double(playerPos.Y);
int k = MathHelper.floor_double(playerPos.Z);
BlockPos blockpos = new BlockPos(i, j, k);
IBlockState iblockstate = base.worldObj.getBlockState(blockpos);
Block block = iblockstate.getBlock();
boolean isSpectator = (base instanceof EntityPlayer && ((EntityPlayer) base).isSpectator());
if (isSpectator)
return false;
EntityPolygon playerPoly = new EntityPolygon(base.getEntityBoundingBox(), physWrapper.wrapping.coordTransform.wToLTransform, base);
AxisAlignedBB bb = playerPoly.getEnclosedAABB();
for (int x = MathHelper.floor_double(bb.minX); x < bb.maxX; x++) {
for (int y = MathHelper.floor_double(bb.minY); y < bb.maxY; y++) {
for (int z = MathHelper.floor_double(bb.minZ); z < bb.maxZ; z++) {
BlockPos pos = new BlockPos(x, y, z);
IBlockState checkState = base.worldObj.getBlockState(pos);
if (checkState.getBlock().isLadder(checkState, base.worldObj, pos, base)) {
return true;
// AxisAlignedBB ladderBB = checkState.getBlock().getBoundingBox(checkState, base.worldObj, pos).offset(pos).expandXyz(.1D);
// Polygon checkBlock = new Polygon(ladderBB);
// EntityPolygonCollider collider = new EntityPolygonCollider(playerPoly, checkBlock, physWrapper.wrapping.coordTransform.normals, new Vector(base.motionX,base.motionY,base.motionZ));
//// System.out.println(!collider.seperated);
// if(!collider.seperated){
// return true;
// }
}
}
}
}
// return net.minecraftforge.common.ForgeHooks.isLivingOnLadder(iblockstate, base.worldObj, new BlockPos(i, j, k), base);
}
return false;
}
Aggregations