use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinParticleManager method preAddEffect.
@Inject(method = "addEffect", at = @At("HEAD"), cancellable = true)
public void preAddEffect(Particle effect, CallbackInfo callbackInfoReturnable) {
if (effect == null) {
callbackInfoReturnable.cancel();
return;
}
BlockPos pos = new BlockPos(effect.posX, effect.posY, effect.posZ);
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(effect.world, pos);
if (physicsObject.isPresent()) {
Vector3d posVec = new Vector3d(effect.posX, effect.posY, effect.posZ);
Vector3d velocity = new Vector3d(effect.motionX, effect.motionY, effect.motionZ);
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(posVec, TransformType.SUBSPACE_TO_GLOBAL);
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformDirection(velocity, TransformType.SUBSPACE_TO_GLOBAL);
effect.setPosition(posVec.x, posVec.y, posVec.z);
effect.motionX = velocity.x;
effect.motionY = velocity.y;
effect.motionZ = velocity.z;
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinTileEntity method getDistanceSq.
/**
* This is easier to have as an overwrite because there's less laggy hackery to be done then :P
*
* @author DaPorkchop_
*/
@Overwrite
public double getDistanceSq(double x, double y, double z) {
World tileWorld = this.world;
double d0 = (double) this.pos.getX() + 0.5D - x;
double d1 = (double) this.pos.getY() + 0.5D - y;
double d2 = (double) this.pos.getZ() + 0.5D - z;
double toReturn = d0 * d0 + d1 * d1 + d2 * d2;
if (tileWorld != null) {
// Assume on Ship
if (tileWorld.isRemote && toReturn > 9999999D) {
BlockPos pos = this.pos;
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, pos);
if (physicsObject.isPresent()) {
Vector3d tilePos = new Vector3d(pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5);
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(tilePos, TransformType.SUBSPACE_TO_GLOBAL);
tilePos.x -= x;
tilePos.y -= y;
tilePos.z -= z;
return tilePos.lengthSquared();
}
}
}
return toReturn;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinChunkPos method getDistanceSq.
/**
* This is easier to have as an overwrite because there's less laggy hackery to be done then :P
*
* @author DaPorkchop_
*/
@Overwrite
public double getDistanceSq(Entity entityIn) {
double d0 = this.x * 16 + 8;
double d1 = this.z * 16 + 8;
double d2 = d0 - entityIn.posX;
double d3 = d1 - entityIn.posZ;
double vanilla = d2 * d2 + d3 * d3;
// A big number
if (vanilla < TOO_MUCH_DISTANCE) {
return vanilla;
}
try {
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(entityIn.world, new BlockPos(d0, 127, d1));
if (physicsObject.isPresent()) {
Vector3d entityPosInLocal = new Vector3d(entityIn.posX, entityIn.posY, entityIn.posZ);
// RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.wToLTransform,
// entityPosInLocal);
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(entityPosInLocal, TransformType.GLOBAL_TO_SUBSPACE);
entityPosInLocal.sub(d0, entityPosInLocal.y, d1);
return entityPosInLocal.lengthSquared();
}
} catch (Exception e) {
e.printStackTrace();
}
return vanilla;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method getEntitiesWithinAABB.
/**
* @author thebest108
*/
@Overwrite
public <T extends Entity> List<T> getEntitiesWithinAABB(Class<? extends T> clazz, AxisAlignedBB aabb, @Nullable Predicate<? super T> filter) {
List<T> toReturn = this.getEntitiesWithinAABBOriginal(clazz, aabb, filter);
BlockPos pos = new BlockPos((aabb.minX + aabb.maxX) / 2D, (aabb.minY + aabb.maxY) / 2D, (aabb.minZ + aabb.maxZ) / 2D);
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(World.class.cast(this), pos);
if (physicsObject.isPresent()) {
Polygon poly = new Polygon(aabb, physicsObject.get().getShipTransformationManager().getCurrentTickTransform(), TransformType.SUBSPACE_TO_GLOBAL);
// .contract(.3D);
aabb = poly.getEnclosedAABB();
toReturn.addAll(this.getEntitiesWithinAABBOriginal(clazz, aabb, filter));
}
return toReturn;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method rayTraceBlocksIgnoreShip.
@Override
public RayTraceResult rayTraceBlocksIgnoreShip(Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock, PhysicsObject toIgnore) {
this.shouldInterceptRayTrace = false;
RayTraceResult vanillaTrace = World.class.cast(this).rayTraceBlocks(vec31, vec32, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
IPhysObjectWorld physObjectWorld = ((IHasShipManager) (this)).getManager();
if (physObjectWorld == null) {
return vanillaTrace;
}
Vec3d playerReachVector = vec32.subtract(vec31);
AxisAlignedBB playerRangeBB = new AxisAlignedBB(vec31.x, vec31.y, vec31.z, vec32.x, vec32.y, vec32.z);
List<PhysicsObject> nearbyShips = physObjectWorld.getPhysObjectsInAABB(playerRangeBB);
// Get rid of the Ship that we're not supposed to be RayTracing for
nearbyShips.remove(toIgnore);
double reachDistance = playerReachVector.length();
double worldResultDistFromPlayer = 420000000D;
if (vanillaTrace != null && vanillaTrace.hitVec != null) {
worldResultDistFromPlayer = vanillaTrace.hitVec.distanceTo(vec31);
}
for (PhysicsObject wrapper : nearbyShips) {
Vec3d playerEyesPos = vec31;
playerReachVector = vec32.subtract(vec31);
ShipTransform shipTransform = wrapper.getShipTransformationManager().getRenderTransform();
playerEyesPos = shipTransform.transform(playerEyesPos, TransformType.GLOBAL_TO_SUBSPACE);
playerReachVector = shipTransform.rotate(playerReachVector, TransformType.GLOBAL_TO_SUBSPACE);
Vec3d playerEyesReachAdded = playerEyesPos.add(playerReachVector.x * reachDistance, playerReachVector.y * reachDistance, playerReachVector.z * reachDistance);
RayTraceResult resultInShip = World.class.cast(this).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;
// The hitVec must ALWAYS be in global coordinates.
resultInShip.hitVec = shipTransform.transform(resultInShip.hitVec, TransformType.SUBSPACE_TO_GLOBAL);
vanillaTrace = resultInShip;
}
}
}
this.shouldInterceptRayTrace = true;
return vanillaTrace;
}
Aggregations