Search in sources :

Example 6 with DynmapChunk

use of org.dynmap.DynmapChunk in project dynmap by webbukkit.

the class OBJExport method processExport.

/**
 * Process export
 *
 * @param sender - command sender: use for feedback messages
 * @return true if successful, false if not
 */
public boolean processExport(DynmapCommandSender sender) {
    boolean good = false;
    try {
        // Open ZIP file destination
        zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(destZipFile)));
        List<DynmapChunk> requiredChunks = new ArrayList<DynmapChunk>();
        int mincx = (minX >> 4);
        int maxcx = (maxX + 15) >> 4;
        int mincz = (minZ >> 4);
        int maxcz = (maxZ + 15) >> 4;
        boolean[] edgebits = new boolean[6];
        startExportedFile(basename + ".obj");
        // Add material library
        addStringToExportedFile("mtllib " + basename + ".mtl\n");
        // Loop through - do 8x8 chunks at a time (plus 1 border each way)
        for (int cx = mincx; cx <= maxcx; cx += 4) {
            for (int cz = mincz; cz <= maxcz; cz += 4) {
                // Build chunk cache for block of chunks
                requiredChunks.clear();
                for (int i = -1; i < 5; i++) {
                    for (int j = -1; j < 5; j++) {
                        if (((cx + i) <= maxcx) && ((cz + j) <= maxcz) && ((cx + i) >= mincx) && ((cz + j) >= mincz)) {
                            requiredChunks.add(new DynmapChunk(cx + i, cz + j));
                        }
                    }
                }
                // Get the chunk buffer
                MapChunkCache cache = core.getServer().createMapChunkCache(world, requiredChunks, true, false, true, false);
                if (cache == null) {
                    throw new IOException("Error loading chunk cache");
                }
                MapIterator iter = cache.getIterator(minX, minY, minZ);
                for (int x = cx * 16; (x < (cx * 16 + 64)) && (x <= maxX); x++) {
                    if (x < minX)
                        x = minX;
                    edgebits[BlockStep.X_PLUS.ordinal()] = (x == minX);
                    edgebits[BlockStep.X_MINUS.ordinal()] = (x == maxX);
                    for (int z = cz * 16; (z < (cz * 16 + 64)) && (z <= maxZ); z++) {
                        if (z < minZ)
                            z = minZ;
                        edgebits[BlockStep.Z_PLUS.ordinal()] = (z == minZ);
                        edgebits[BlockStep.Z_MINUS.ordinal()] = (z == maxZ);
                        iter.initialize(x, minY, z);
                        updateGroup(GROUP_CHUNK, "chunk" + (x >> 4) + "_" + (z >> 4));
                        // Do first (bottom)
                        edgebits[BlockStep.Y_MINUS.ordinal()] = true;
                        edgebits[BlockStep.Y_PLUS.ordinal()] = false;
                        DynmapBlockState blk = iter.getBlockType();
                        if (blk.isNotAir()) {
                            // Not air
                            handleBlock(blk, iter, edgebits);
                        }
                        // Do middle
                        edgebits[BlockStep.Y_MINUS.ordinal()] = false;
                        for (int y = minY + 1; y < maxY; y++) {
                            iter.setY(y);
                            blk = iter.getBlockType();
                            if (blk.isNotAir()) {
                                // Not air
                                handleBlock(blk, iter, edgebits);
                            }
                        }
                        // Do top
                        edgebits[BlockStep.Y_PLUS.ordinal()] = true;
                        iter.setY(maxY);
                        blk = iter.getBlockType();
                        if (blk.isNotAir()) {
                            // Not air
                            handleBlock(blk, iter, edgebits);
                        }
                    }
                }
                // Output faces by texture
                String grp = "";
                for (String material : facesByTexture.keySet()) {
                    List<Face> faces = facesByTexture.get(material);
                    // Record material use
                    matIDs.add(material);
                    addStringToExportedFile(String.format("usemtl %s\n", material));
                    for (Face face : faces) {
                        if ((face.groupLine != null) && (!face.groupLine.equals(grp))) {
                            grp = face.groupLine;
                            addStringToExportedFile(grp);
                        }
                        addStringToExportedFile(face.faceLine);
                    }
                }
                // Clear face table
                facesByTexture.clear();
                // Clean up vertices we've moved past
                vertices.resetSet(minX, minY, minZ, cx * 16 + 64, maxY, cz * 16 + 64);
            }
        }
        finishExportedFile();
        // If shader provided, add shader content to ZIP
        if (shader != null) {
            sender.sendMessage("Adding textures from shader " + shader.getName());
            shader.exportAsMaterialLibrary(sender, this);
            sender.sendMessage("Texture export completed");
        }
        // And close the ZIP
        zos.finish();
        zos.close();
        zos = null;
        good = true;
        sender.sendMessage("Export completed - " + destZipFile.getPath());
    } catch (IOException iox) {
        sender.sendMessage("Export failed: " + iox.getMessage());
    } finally {
        if (zos != null) {
            try {
                zos.close();
            } catch (IOException e) {
            }
            zos = null;
            destZipFile.delete();
        }
    }
    return good;
}
Also used : MapChunkCache(org.dynmap.utils.MapChunkCache) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) ArrayList(java.util.ArrayList) IOException(java.io.IOException) MapIterator(org.dynmap.utils.MapIterator) DynmapChunk(org.dynmap.DynmapChunk) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 7 with DynmapChunk

use of org.dynmap.DynmapChunk in project dynmap by webbukkit.

the class IsoHDPerspective method getRequiredChunks.

@Override
public List<DynmapChunk> getRequiredChunks(MapTile tile) {
    if (!(tile instanceof HDMapTile))
        return Collections.emptyList();
    HDMapTile t = (HDMapTile) tile;
    int min_chunk_x = Integer.MAX_VALUE;
    int max_chunk_x = Integer.MIN_VALUE;
    int min_chunk_z = Integer.MAX_VALUE;
    int max_chunk_z = Integer.MIN_VALUE;
    int tileSize = tile.getTileSize();
    /* Make corners for volume: 
         * 0 = bottom-lower-left (xyz), 
         * 1 = top-lower-left (xyZ), 
         * 2 = bottom-upper-left (xYz), 
         * 3 = top-upper-left (xYZ),
         * 4 = bottom-lower-right (Xyz), 
         * 5 = top-lower-right (XyZ), 
         * 6 = bottom-upper-right (XYz), 
         * 7 = top-upper-right (XYZ) */
    Vector3D[] corners = new Vector3D[8];
    double dx = -basemodscale, dy = -basemodscale;
    /* Add 1 block on each axis */
    for (int x = t.tx, idx = 0; x <= (t.tx + 1); x++) {
        dy = -basemodscale;
        for (int y = t.ty; y <= (t.ty + 1); y++) {
            for (int z = 0; z <= 1; z++) {
                corners[idx] = new Vector3D();
                corners[idx].x = x * tileSize + dx;
                corners[idx].y = y * tileSize + dy;
                corners[idx].z = (z == 1) ? t.getDynmapWorld().worldheight : t.getDynmapWorld().minY;
                map_to_world.transform(corners[idx]);
                /* Compute chunk coordinates of corner */
                int cx = fastFloor(corners[idx].x / 16);
                int cz = fastFloor(corners[idx].z / 16);
                /* Compute min/max of chunk coordinates */
                if (min_chunk_x > cx)
                    min_chunk_x = cx;
                if (max_chunk_x < cx)
                    max_chunk_x = cx;
                if (min_chunk_z > cz)
                    min_chunk_z = cz;
                if (max_chunk_z < cz)
                    max_chunk_z = cz;
                idx++;
            }
            dy = basemodscale;
        }
        dx = basemodscale;
    }
    /* Make rectangles of X-Z projection of each side of the tile volume, 0 = top, 1 = bottom, 2 = left, 3 = right,
         * 4 = upper, 5 = lower */
    Polygon[] side = new Polygon[6];
    for (int sidenum = 0; sidenum < side.length; sidenum++) {
        side[sidenum] = new Polygon();
        for (int corner = 0; corner < corners_by_side[sidenum].length; corner++) {
            int cid = corners_by_side[sidenum][corner];
            side[sidenum].addVertex(corners[cid].x, corners[cid].z);
        }
    }
    /* Now, need to walk through the min/max range to see which chunks are actually needed */
    ArrayList<DynmapChunk> chunks = new ArrayList<DynmapChunk>();
    for (int x = min_chunk_x; x <= max_chunk_x; x++) {
        for (int z = min_chunk_z; z <= max_chunk_z; z++) {
            boolean hit = false;
            for (int sidenum = 0; (!hit) && (sidenum < side.length); sidenum++) {
                if (side[sidenum].clip(16.0 * x, 16.0 * z, 16.0 * (x + 1), 16.0 * (z + 1)) != null) {
                    hit = true;
                }
            }
            // xs += c;
            if (hit) {
                DynmapChunk chunk = new DynmapChunk(x, z);
                chunks.add(chunk);
            }
        }
    }
    return chunks;
}
Also used : DynmapChunk(org.dynmap.DynmapChunk) Vector3D(org.dynmap.utils.Vector3D) ArrayList(java.util.ArrayList) Polygon(org.dynmap.utils.Polygon)

Example 8 with DynmapChunk

use of org.dynmap.DynmapChunk in project dynmap by webbukkit.

the class GenericMapChunkCache method readChunks.

public int readChunks(int max_to_load) {
    if (!dw.isLoaded()) {
        isempty = true;
        unloadChunks();
        return 0;
    }
    int cnt = 0;
    if (iterator == null) {
        iterator = chunks.listIterator();
    }
    DynmapCore.setIgnoreChunkLoads(true);
    // Load the required chunks.
    while ((cnt < max_to_load) && iterator.hasNext()) {
        long startTime = System.nanoTime();
        DynmapChunk chunk = iterator.next();
        int chunkindex = (chunk.x - x_min) + (chunk.z - z_min) * x_dim;
        if (snaparray[chunkindex] != null)
            // Skip if already processed
            continue;
        boolean vis = isChunkVisible(chunk);
        /* Check if cached chunk snapshot found */
        if (tryChunkCache(chunk, vis)) {
            endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
        } else {
            GenericChunk ss = loadChunk(chunk);
            // If read was good
            if (ss != null) {
                // If hidden
                if (!vis) {
                    if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
                        ss = getStone();
                    } else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
                        ss = getOcean();
                    } else {
                        ss = getEmpty();
                    }
                } else {
                    // Prep snapshot
                    prepChunkSnapshot(chunk, ss);
                }
                snaparray[chunkindex] = ss;
                endChunkLoad(startTime, ChunkStats.UNLOADED_CHUNKS);
            } else {
                endChunkLoad(startTime, ChunkStats.UNGENERATED_CHUNKS);
            }
        }
        cnt++;
    }
    DynmapCore.setIgnoreChunkLoads(false);
    if (iterator.hasNext() == false) {
        /* If we're done */
        isempty = true;
        /* Fill missing chunks with empty dummy chunk */
        for (int i = 0; i < snaparray.length; i++) {
            if (snaparray[i] == null) {
                snaparray[i] = getEmpty();
            } else if (!snaparray[i].isEmpty) {
                isempty = false;
            }
        }
    }
    return cnt;
}
Also used : DynmapChunk(org.dynmap.DynmapChunk)

Example 9 with DynmapChunk

use of org.dynmap.DynmapChunk in project dynmap by webbukkit.

the class GenericMapChunkCache method getLoadedChunks.

/**
 * Read NBT data from loaded chunks - needs to be called from server/world
 * thread to be safe
 *
 * @returns number loaded
 */
public int getLoadedChunks() {
    int cnt = 0;
    if (!dw.isLoaded()) {
        isempty = true;
        unloadChunks();
        return 0;
    }
    ListIterator<DynmapChunk> iter = chunks.listIterator();
    while (iter.hasNext()) {
        long startTime = System.nanoTime();
        DynmapChunk chunk = iter.next();
        int chunkindex = (chunk.x - x_min) + (chunk.z - z_min) * x_dim;
        if (snaparray[chunkindex] != null)
            // Skip if already processed
            continue;
        boolean vis = isChunkVisible(chunk);
        /* Check if cached chunk snapshot found */
        if (tryChunkCache(chunk, vis)) {
            endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
            cnt++;
        } else // If chunk is loaded and not being unloaded, we're grabbing its NBT data
        {
            // Get generic chunk from already loaded chunk, if we can
            GenericChunk ss = getLoadedChunk(chunk);
            if (ss != null) {
                if (vis) {
                    // If visible
                    prepChunkSnapshot(chunk, ss);
                } else {
                    if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
                        ss = getStone();
                    } else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
                        ss = getOcean();
                    } else {
                        ss = getEmpty();
                    }
                }
                snaparray[chunkindex] = ss;
                endChunkLoad(startTime, ChunkStats.LOADED_CHUNKS);
                cnt++;
            }
        }
    }
    return cnt;
}
Also used : DynmapChunk(org.dynmap.DynmapChunk)

Example 10 with DynmapChunk

use of org.dynmap.DynmapChunk in project dynmap by webbukkit.

the class ForgeMapChunkCache method setChunks.

public void setChunks(ForgeWorld dw, List<DynmapChunk> chunks) {
    this.dw = dw;
    this.w = dw.getWorld();
    if (dw.isLoaded()) {
        /* Check if world's provider is ServerChunkProvider */
        AbstractChunkProvider cp = this.w.getChunkProvider();
        if (cp instanceof ServerChunkProvider) {
            cps = (ServerChunkProvider) cp;
        } else {
            Log.severe("Error: world " + dw.getName() + " has unsupported chunk provider");
        }
    } else {
        chunks = new ArrayList<DynmapChunk>();
    }
    nsect = dw.worldheight >> 4;
    this.chunks = chunks;
    /* Compute range */
    if (chunks.size() == 0) {
        this.x_min = 0;
        this.x_max = 0;
        this.z_min = 0;
        this.z_max = 0;
        x_dim = 1;
    } else {
        x_min = x_max = chunks.get(0).x;
        z_min = z_max = chunks.get(0).z;
        for (DynmapChunk c : chunks) {
            if (c.x > x_max) {
                x_max = c.x;
            }
            if (c.x < x_min) {
                x_min = c.x;
            }
            if (c.z > z_max) {
                z_max = c.z;
            }
            if (c.z < z_min) {
                z_min = c.z;
            }
        }
        x_dim = x_max - x_min + 1;
    }
    snapcnt = x_dim * (z_max - z_min + 1);
    snaparray = new ChunkSnapshot[snapcnt];
    snaptile = new DynIntHashMap[snapcnt];
    isSectionNotEmpty = new boolean[snapcnt][];
}
Also used : DynmapChunk(org.dynmap.DynmapChunk) AbstractChunkProvider(net.minecraft.world.chunk.AbstractChunkProvider) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider)

Aggregations

DynmapChunk (org.dynmap.DynmapChunk)25 GenericChunk (org.dynmap.common.chunk.GenericChunk)9 DynIntHashMap (org.dynmap.utils.DynIntHashMap)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 ArrayList (java.util.ArrayList)3 Chunk (net.minecraft.world.level.chunk.Chunk)3 Chunk (net.minecraft.server.v1_16_R2.Chunk)2 NBTTagCompound (net.minecraft.server.v1_16_R2.NBTTagCompound)2 AbstractChunkProvider (net.minecraft.world.chunk.AbstractChunkProvider)2 ServerChunkProvider (net.minecraft.world.server.ServerChunkProvider)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 CraftWorld (org.bukkit.craftbukkit.v1_16_R2.CraftWorld)2 SnapshotRec (org.dynmap.forge_1_12_2.SnapshotCache.SnapshotRec)2 SnapshotRec (org.dynmap.forge_1_14_4.SnapshotCache.SnapshotRec)2 SnapshotRec (org.dynmap.forge_1_15_2.SnapshotCache.SnapshotRec)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1