Search in sources :

Example 1 with QueryableShipData

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);
        }
    }
}
Also used : QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) ShipData(org.valkyrienskies.mod.common.ships.ShipData) Chunk(net.minecraft.world.chunk.Chunk) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with QueryableShipData

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;
}
Also used : ShipData(org.valkyrienskies.mod.common.ships.ShipData) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) IThreadListener(net.minecraft.util.IThreadListener) World(net.minecraft.world.World) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) UUID(java.util.UUID) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData)

Example 3 with QueryableShipData

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"));
}
Also used : TypeConversionException(picocli.CommandLine.TypeConversionException) World(net.minecraft.world.World) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData)

Example 4 with QueryableShipData

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;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) ITransformInterpolator(org.valkyrienskies.mod.common.ships.interpolation.ITransformInterpolator) IThreadListener(net.minecraft.util.IThreadListener) World(net.minecraft.world.World) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) UUID(java.util.UUID) IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 5 with QueryableShipData

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();
}
Also used : ShipData(org.valkyrienskies.mod.common.ships.ShipData) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) Chunk(net.minecraft.world.chunk.Chunk) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData)

Aggregations

QueryableShipData (org.valkyrienskies.mod.common.ships.QueryableShipData)10 ShipData (org.valkyrienskies.mod.common.ships.ShipData)8 World (net.minecraft.world.World)4 IPhysObjectWorld (org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld)3 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)3 UUID (java.util.UUID)2 IThreadListener (net.minecraft.util.IThreadListener)2 Chunk (net.minecraft.world.chunk.Chunk)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)2 Nonnull (javax.annotation.Nonnull)1 IBlockState (net.minecraft.block.state.IBlockState)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 ChunkProviderServer (net.minecraft.world.gen.ChunkProviderServer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 Vector3d (org.joml.Vector3d)1 IHasPlayerMovementData (org.valkyrienskies.mod.common.network.IHasPlayerMovementData)1 PlayerMovementData (org.valkyrienskies.mod.common.network.PlayerMovementData)1 IDraggable (org.valkyrienskies.mod.common.ships.entity_interaction.IDraggable)1