Search in sources :

Example 21 with DynmapChunk

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

the class MapChunkCache114_1 method getLoadedChunk.

// Load generic chunk from existing and already loaded chunk
protected GenericChunk getLoadedChunk(DynmapChunk chunk) {
    CraftWorld cw = (CraftWorld) w;
    NBTTagCompound nbt = null;
    GenericChunk gc = null;
    if (cw.isChunkLoaded(chunk.x, chunk.z)) {
        Chunk c = cw.getHandle().getChunkAt(chunk.x, chunk.z);
        if ((c != null) && c.loaded) {
            nbt = ChunkRegionLoader.saveChunk(cw.getHandle(), c);
        }
        if (nbt != null) {
            gc = parseChunkFromNBT(new NBT.NBTCompound(nbt));
        }
    }
    return gc;
}
Also used : GenericChunk(org.dynmap.common.chunk.GenericChunk) NBTTagCompound(net.minecraft.server.v1_14_R1.NBTTagCompound) GenericChunk(org.dynmap.common.chunk.GenericChunk) Chunk(net.minecraft.server.v1_14_R1.Chunk) DynmapChunk(org.dynmap.DynmapChunk) CraftWorld(org.bukkit.craftbukkit.v1_14_R1.CraftWorld)

Example 22 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 ChunkProviderServer */
        IChunkProvider cp = this.w.getChunkProvider();
        if (cp instanceof ChunkProviderServer) {
            cps = (ChunkProviderServer) 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][];
    try {
        if ((unloadqueue != null) && (cps != null)) {
            queue = (Set<?>) unloadqueue.get(cps);
        }
    } catch (IllegalArgumentException iax) {
    } catch (IllegalAccessException e) {
    }
}
Also used : DynmapChunk(org.dynmap.DynmapChunk) IChunkProvider(net.minecraft.world.chunk.IChunkProvider) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer)

Example 23 with DynmapChunk

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

the class ForgeMapChunkCache 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;
        // Skip if already processed
        if (snaparray[chunkindex] != null)
            continue;
        boolean vis = isChunkVisible(chunk);
        /* Check if cached chunk snapshot found */
        if (tryChunkCache(chunk, vis)) {
            endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
        } else {
            CompoundNBT nbt = readChunk(chunk.x, chunk.z);
            // If read was good
            if (nbt != null) {
                ChunkSnapshot ss;
                DynIntHashMap tileData;
                // If hidden
                if (!vis) {
                    if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
                        ss = STONE;
                    } else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
                        ss = OCEAN;
                    } else {
                        ss = EMPTY;
                    }
                    tileData = new DynIntHashMap();
                } else {
                    // Prep snapshot
                    SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
                    ss = ssr.ss;
                    tileData = ssr.tileData;
                }
                snaparray[chunkindex] = ss;
                snaptile[chunkindex] = tileData;
                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] = EMPTY;
            } else if (snaparray[i] != EMPTY) {
                isempty = false;
            }
        }
    }
    return cnt;
}
Also used : DynmapChunk(org.dynmap.DynmapChunk) SnapshotRec(org.dynmap.forge_1_15_2.SnapshotCache.SnapshotRec) CompoundNBT(net.minecraft.nbt.CompoundNBT) DynIntHashMap(org.dynmap.utils.DynIntHashMap)

Example 24 with DynmapChunk

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

the class ForgeMapChunkCache 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;
        // Skip if already processed
        if (snaparray[chunkindex] != null)
            continue;
        boolean vis = isChunkVisible(chunk);
        /* Check if cached chunk snapshot found */
        if (tryChunkCache(chunk, vis)) {
            endChunkLoad(startTime, ChunkStats.CACHED_SNAPSHOT_HIT);
        } else {
            CompoundNBT nbt = readChunk(chunk.x, chunk.z);
            // If read was good
            if (nbt != null) {
                ChunkSnapshot ss;
                DynIntHashMap tileData;
                // If hidden
                if (!vis) {
                    if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) {
                        ss = STONE;
                    } else if (hidestyle == HiddenChunkStyle.FILL_OCEAN) {
                        ss = OCEAN;
                    } else {
                        ss = EMPTY;
                    }
                    tileData = new DynIntHashMap();
                } else {
                    // Prep snapshot
                    SnapshotRec ssr = prepChunkSnapshot(chunk, nbt);
                    ss = ssr.ss;
                    tileData = ssr.tileData;
                }
                snaparray[chunkindex] = ss;
                snaptile[chunkindex] = tileData;
                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] = EMPTY;
            } else if (snaparray[i] != EMPTY) {
                isempty = false;
            }
        }
    }
    return cnt;
}
Also used : DynmapChunk(org.dynmap.DynmapChunk) SnapshotRec(org.dynmap.forge_1_14_4.SnapshotCache.SnapshotRec) CompoundNBT(net.minecraft.nbt.CompoundNBT) DynIntHashMap(org.dynmap.utils.DynIntHashMap)

Example 25 with DynmapChunk

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

the class GenericMapChunkCache method setChunks.

public void setChunks(DynmapWorld dw, List<DynmapChunk> chunks) {
    this.dw = dw;
    nsect = (dw.worldheight - dw.minY) >> 4;
    sectoff = (-dw.minY) >> 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 GenericChunk[snapcnt];
    isSectionNotEmpty = new boolean[snapcnt][];
}
Also used : DynmapChunk(org.dynmap.DynmapChunk)

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