Search in sources :

Example 6 with ShipData

use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ShipIndexDataMessage method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    PacketBuffer packetBuffer = new PacketBuffer(buf);
    int numberOfIndices = packetBuffer.readInt();
    int numberOfUUIDLoad = packetBuffer.readInt();
    int numberOfUUIDUnload = packetBuffer.readInt();
    for (int i = 0; i < numberOfIndices; i++) {
        // Read index data from the byte buffer.
        int bytesSize = packetBuffer.readInt();
        byte[] bytes = new byte[bytesSize];
        packetBuffer.readBytes(bytes);
        try {
            ShipData data = serializer.readValue(bytes, ShipData.class);
            this.indexedData.add(data);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    for (int i = 0; i < numberOfUUIDLoad; i++) {
        shipsToLoad.add(packetBuffer.readUniqueId());
    }
    for (int i = 0; i < numberOfUUIDUnload; i++) {
        shipsToUnload.add(packetBuffer.readUniqueId());
    }
    dimensionID = packetBuffer.readInt();
}
Also used : ShipData(org.valkyrienskies.mod.common.ships.ShipData) IOException(java.io.IOException) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 7 with ShipData

use of org.valkyrienskies.mod.common.ships.ShipData 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)

Example 8 with ShipData

use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldShipLoadingController method sendUpdatesPackets.

/**
 * Send load/unload/update packets accordingly.
 */
private void sendUpdatesPackets(Map<ShipData, Set<EntityPlayerMP>> oldWatching, Map<ShipData, Set<EntityPlayerMP>> newWatching) {
    // First send the update packets
    // Create a map for every player to the ship data updates it will receive
    Map<EntityPlayerMP, List<ShipData>> updatesMap = new HashMap<>();
    shipManager.getWorld().playerEntities.forEach((player) -> updatesMap.put((EntityPlayerMP) player, new ArrayList<>()));
    for (PhysicsObject ship : shipManager.getAllLoadedPhysObj()) {
        ShipData shipData = ship.getShipData();
        Set<EntityPlayerMP> currentWatchers = newWatching.get(shipData);
        currentWatchers.forEach((player) -> updatesMap.get(player).add(shipData));
    }
    Map<EntityPlayerMP, ShipIndexDataMessage> playerPacketMap = new HashMap<>();
    // Then send those updates
    updatesMap.forEach((player, updates) -> {
        ShipIndexDataMessage indexDataMessage = new ShipIndexDataMessage();
        indexDataMessage.setDimensionID(shipManager.getWorld().provider.getDimension());
        if (!updates.isEmpty()) {
            indexDataMessage.addData(updates);
        }
        playerPacketMap.put(player, indexDataMessage);
    });
    // Then send ship loads to the packets
    for (PhysicsObject ship : shipManager.getAllLoadedPhysObj()) {
        ShipData shipData = ship.getShipData();
        Set<EntityPlayerMP> newWatchers = new HashSet<>(newWatching.get(shipData));
        if (oldWatching.containsKey(shipData)) {
            newWatchers.removeAll(oldWatching.get(shipData));
        }
        if (!newWatchers.isEmpty()) {
            // First send the ship chunks to the new watchers
            for (Chunk chunk : ship.getClaimedChunkCache()) {
                SPacketChunkData data = new SPacketChunkData(chunk, 65535);
                for (EntityPlayerMP player : newWatchers) {
                    player.connection.sendPacket(data);
                    shipManager.getWorld().getEntityTracker().sendLeashedEntitiesInChunk(player, chunk);
                }
            }
            newWatchers.forEach(player -> playerPacketMap.get(player).addLoadUUID(shipData.getUuid()));
        }
    }
    // Then add ship unloads to the packets
    for (ShipData shipData : oldWatching.keySet()) {
        Set<EntityPlayerMP> removedWatchers = new HashSet<>(oldWatching.get(shipData));
        if (newWatching.containsKey(shipData)) {
            removedWatchers.removeAll(newWatching.get(shipData));
        }
        for (EntityPlayerMP player : removedWatchers) {
            // BetterPortals.
            if (!playerPacketMap.containsKey(player)) {
                playerPacketMap.put(player, new ShipIndexDataMessage());
                playerPacketMap.get(player).setDimensionID(shipManager.getWorld().provider.getDimension());
            }
            playerPacketMap.get(player).addUnloadUUID(shipData.getUuid());
        }
    }
    // Finally, send each player their update packet
    playerPacketMap.forEach((player, packet) -> {
        if (!player.hasDisconnected()) {
            ValkyrienSkiesMod.physWrapperNetwork.sendTo(packet, player);
        }
    });
}
Also used : ShipData(org.valkyrienskies.mod.common.ships.ShipData) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) Chunk(net.minecraft.world.chunk.Chunk) SPacketChunkData(net.minecraft.network.play.server.SPacketChunkData) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ShipIndexDataMessage(org.valkyrienskies.mod.common.network.ShipIndexDataMessage)

Example 9 with ShipData

use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinEntityPlayer method preGetBedSpawnLocation.

@Inject(method = "getBedSpawnLocation", at = @At("HEAD"), cancellable = true)
private static void preGetBedSpawnLocation(World worldIn, BlockPos bedLocation, boolean forceSpawn, CallbackInfoReturnable<BlockPos> callbackInfo) {
    Optional<ShipData> shipData = ValkyrienUtils.getQueryableData(worldIn).getShipFromBlock(bedLocation);
    if (shipData.isPresent()) {
        ShipTransform positionData = shipData.get().getShipTransform();
        if (positionData != null) {
            Vector3d bedLocationD = JOML.castDouble(JOML.convert(bedLocation)).add(0.5, 0.5, 0.5);
            positionData.getSubspaceToGlobal().transformPosition(bedLocationD);
            bedLocationD.y += 1D;
            bedLocation = JOML.toMinecraft(JOML.castInt(bedLocationD));
            callbackInfo.setReturnValue(bedLocation);
        } else {
            System.err.println("A ship just had chunks claimed persistent, but not any position data persistent");
        }
    }
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) ShipData(org.valkyrienskies.mod.common.ships.ShipData) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with ShipData

use of org.valkyrienskies.mod.common.ships.ShipData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinMinecraft method rightClickBlockProxy.

/**
 * This mixin fixes slabs not placing correctly on ships.
 */
@Redirect(method = "rightClickMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;processRightClickBlock(Lnet/minecraft/client/entity/EntityPlayerSP;Lnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/EnumHand;)Lnet/minecraft/util/EnumActionResult;"))
private EnumActionResult rightClickBlockProxy(PlayerControllerMP playerControllerMP, EntityPlayerSP player, WorldClient worldIn, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand) {
    // Check if this is for a ship
    final Optional<ShipData> shipDataOptional = ValkyrienUtils.getShipManagingBlock(worldIn, pos);
    if (shipDataOptional.isPresent()) {
        // This ray trace was in the ship, we're going to have to mess with the hit vector
        final ShipData shipData = shipDataOptional.get();
        final ShipTransform shipTransform = shipData.getShipTransform();
        // Put the hit vector in ship coordinates
        final Vector3d hitVecInLocal = JOML.convert(vec);
        shipTransform.transformPosition(hitVecInLocal, TransformType.GLOBAL_TO_SUBSPACE);
        final Vec3d moddedHitVec = JOML.toMinecraft(hitVecInLocal);
        return playerControllerMP.processRightClickBlock(player, worldIn, pos, direction, moddedHitVec, hand);
    }
    return playerControllerMP.processRightClickBlock(player, worldIn, pos, direction, vec, hand);
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) ShipData(org.valkyrienskies.mod.common.ships.ShipData) Vec3d(net.minecraft.util.math.Vec3d) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

ShipData (org.valkyrienskies.mod.common.ships.ShipData)25 QueryableShipData (org.valkyrienskies.mod.common.ships.QueryableShipData)14 Vector3d (org.joml.Vector3d)9 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)6 Chunk (net.minecraft.world.chunk.Chunk)4 UUID (java.util.UUID)3 IBlockState (net.minecraft.block.state.IBlockState)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 BlockPos (net.minecraft.util.math.BlockPos)3 Vec3d (net.minecraft.util.math.Vec3d)3 World (net.minecraft.world.World)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 PacketBuffer (net.minecraft.network.PacketBuffer)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 WorldServer (net.minecraft.world.WorldServer)2