use of org.valkyrienskies.mod.common.ships.QueryableShipData 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.QueryableShipData 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.QueryableShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipDataConverter method convert.
@Override
public ShipData convert(String value) throws TypeConversionException {
World world = sender.getEntityWorld();
QueryableShipData data = QueryableShipData.get(world);
return data.getShipFromName(value).orElseThrow(() -> new TypeConversionException("That ship, " + value + ", could not be found"));
}
use of org.valkyrienskies.mod.common.ships.QueryableShipData 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.QueryableShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class WorldClientShipManager method loadAndUnloadShips.
private void loadAndUnloadShips() {
QueryableShipData queryableShipData = QueryableShipData.get(world);
// Load ships queued for loading
for (final UUID toLoadID : loadQueue) {
if (loadedShips.containsKey(toLoadID)) {
logger.error("Tried loading a for ship that was already loaded? UUID is\n" + toLoadID);
continue;
}
Optional<ShipData> toLoadOptional = queryableShipData.getShip(toLoadID);
if (!toLoadOptional.isPresent()) {
logger.error("No ship found for UUID:\n" + toLoadID);
continue;
}
ShipData shipData = toLoadOptional.get();
PhysicsObject physicsObject = new PhysicsObject(world, shipData);
for (final Chunk chunk : physicsObject.getClaimedChunkCache()) {
chunk.loaded = true;
}
loadedShips.put(toLoadID, physicsObject);
if (VSConfig.showAnnoyingDebugOutput) {
System.out.println("Successfully loaded " + shipData);
}
}
loadQueue.clear();
// Unload ships queued for unloading
for (final UUID toUnloadID : unloadQueue) {
if (!loadedShips.containsKey(toUnloadID)) {
logger.error("Tried unloading that isn't loaded? ID is\n" + toUnloadID);
continue;
}
PhysicsObject removedShip = loadedShips.get(toUnloadID);
removedShip.unload();
loadedShips.remove(toUnloadID);
if (VSConfig.showAnnoyingDebugOutput) {
System.out.println("Successfully unloaded " + removedShip.getShipData());
}
}
unloadQueue.clear();
}
Aggregations