use of org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsClient method onChunkLoadEvent.
/**
* Used to handle when a chunk in a ship gets updated. This allows us to create ships on the client without
* requiring all the chunks are present at the time of ship creation.
*/
@SubscribeEvent
public void onChunkLoadEvent(ChunkEvent.Load event) {
if (!event.getWorld().isRemote) {
return;
}
Chunk chunk = event.getChunk();
QueryableShipData queryableShipData = QueryableShipData.get(event.getWorld());
Optional<ShipData> shipClaimingOptional = queryableShipData.getShipFromChunk(chunk.x, chunk.z);
if (shipClaimingOptional.isPresent()) {
ShipData shipData = shipClaimingOptional.get();
IPhysObjectWorld physObjectWorld = ValkyrienUtils.getPhysObjWorld(event.getWorld());
PhysicsObject physicsObject = physObjectWorld.getPhysObjectFromUUID(shipData.getUuid());
if (physicsObject != null) {
physicsObject.updateChunk(chunk);
}
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method rayTraceBlocksForGetBlockDensity.
/**
* Use Bresenham's tracing algorithm instead of raytracing for getBlockDensity, makes it way faster
*/
@Redirect(method = "getBlockDensity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;rayTraceBlocks(Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/RayTraceResult;"))
private RayTraceResult rayTraceBlocksForGetBlockDensity(World world, Vec3d start, Vec3d end) {
if (VSConfig.explosionMode == ExplosionMode.VANILLA) {
// Vanilla raytrace, ignore ships and perform the function like normal
this.shouldInterceptRayTrace = false;
RayTraceResult result = rayTraceBlocks(start, end);
this.shouldInterceptRayTrace = true;
return result;
} else if (VSConfig.explosionMode == ExplosionMode.SLOW_VANILLA) {
// Vanilla raytrace, include ships and perform the function like normal
return rayTraceBlocks(start, end);
}
java.util.function.Predicate<BlockPos> canCollide = pos -> {
IBlockState blockState = world.getBlockState(pos);
return blockState.getBlock().canCollideCheck(blockState, false);
};
// Get all the blocks between start and end
List<BlockPos> blocks = VSMath.generateLineBetween(start, end, BlockPos::new);
// Whether or not this ray trace hit a block that was collidable.
boolean collided = blocks.stream().anyMatch(canCollide);
IPhysObjectWorld physObjectWorld = ((IHasShipManager) (this)).getManager();
if (physObjectWorld != null) {
List<PhysicsObject> nearbyShips = physObjectWorld.getPhysObjectsInAABB(new AxisAlignedBB(start.x, start.y, start.z, end.x, end.y, end.z));
for (PhysicsObject obj : nearbyShips) {
Vec3d transformedStart = obj.transformVector(start, TransformType.GLOBAL_TO_SUBSPACE);
Vec3d transformedEnd = obj.transformVector(end, TransformType.GLOBAL_TO_SUBSPACE);
// Transform the raytrace into ship space and check whether or not it hit a block
List<BlockPos> physoBlocks = VSMath.generateLineBetween(transformedStart, transformedEnd, BlockPos::new);
collided |= physoBlocks.stream().anyMatch(canCollide);
}
}
// important information in the ray trace result.
return collided ? DUMMY_RAYTRACE_RESULT : null;
}
use of org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipIndexDataMessageHandler method onMessage.
@Override
@SuppressWarnings("Convert2Lambda")
public // errors. DON'T USE A LAMBDA
IMessage onMessage(ShipIndexDataMessage message, MessageContext ctx) {
IThreadListener mainThread = Minecraft.getMinecraft();
mainThread.addScheduledTask(new Runnable() {
@Override
public void run() {
World world = Minecraft.getMinecraft().world;
IPhysObjectWorld physObjectWorld = ValkyrienUtils.getPhysObjWorld(world);
QueryableShipData worldData = QueryableShipData.get(world);
for (ShipData shipData : message.indexedData) {
worldData.addOrUpdateShipPreservingPhysObj(shipData, world);
}
for (UUID loadID : message.shipsToLoad) {
physObjectWorld.queueShipLoad(loadID);
}
for (UUID unloadID : message.shipsToUnload) {
physObjectWorld.queueShipUnload(unloadID);
}
}
});
return null;
}
use of org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipTransformUpdateMessageHandler method onMessage.
@Override
@SuppressWarnings("Convert2Lambda")
public // errors. DON'T USE A LAMBDA
IMessage onMessage(final ShipTransformUpdateMessage message, final MessageContext ctx) {
IThreadListener mainThread = Minecraft.getMinecraft();
mainThread.addScheduledTask(new Runnable() {
@Override
public void run() {
World world = Minecraft.getMinecraft().world;
IPhysObjectWorld physObjectWorld = ValkyrienUtils.getPhysObjWorld(world);
QueryableShipData worldData = QueryableShipData.get(world);
for (Map.Entry<UUID, Tuple<ShipTransform, AxisAlignedBB>> transformUpdate : message.shipTransforms.entrySet()) {
final UUID shipID = transformUpdate.getKey();
final ShipTransform shipTransform = transformUpdate.getValue().getFirst();
final AxisAlignedBB shipBB = transformUpdate.getValue().getSecond();
final PhysicsObject physicsObject = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectFromUUID(shipID);
if (physicsObject != null) {
// Do not update the transform in ShipData, that will be done by PhysicsObject.tick()
ITransformInterpolator interpolator = physicsObject.getTransformInterpolator();
interpolator.onNewTransformPacket(shipTransform, shipBB);
}
}
}
});
return null;
}
use of org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld 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