Search in sources :

Example 1 with AbstractChunkProvider

use of net.minecraft.world.chunk.AbstractChunkProvider 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)

Example 2 with AbstractChunkProvider

use of net.minecraft.world.chunk.AbstractChunkProvider 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)

Example 3 with AbstractChunkProvider

use of net.minecraft.world.chunk.AbstractChunkProvider in project FastAsyncWorldEdit by IntellectualSites.

the class ForgeWorld method regenerate.

@Override
public boolean regenerate(Region region, EditSession editSession) {
    // Don't even try to regen if it's going to fail.
    AbstractChunkProvider provider = getWorld().getChunkProvider();
    if (!(provider instanceof ServerChunkProvider)) {
        return false;
    }
    File saveFolder = Files.createTempDir();
    // register this just in case something goes wrong
    // normally it should be deleted at the end of this method
    saveFolder.deleteOnExit();
    try {
        ServerWorld originalWorld = (ServerWorld) getWorld();
        MinecraftServer server = originalWorld.getServer();
        SaveHandler saveHandler = new SaveHandler(saveFolder, originalWorld.getSaveHandler().getWorldDirectory().getName(), server, server.getDataFixer());
        try (World freshWorld = new ServerWorld(server, server.getBackgroundExecutor(), saveHandler, originalWorld.getWorldInfo(), originalWorld.dimension.getType(), originalWorld.getProfiler(), new NoOpChunkStatusListener())) {
            // Pre-gen all the chunks
            // We need to also pull one more chunk in every direction
            CuboidRegion expandedPreGen = new CuboidRegion(region.getMinimumPoint().subtract(16, 0, 16), region.getMaximumPoint().add(16, 0, 16));
            for (BlockVector2 chunk : expandedPreGen.getChunks()) {
                freshWorld.getChunk(chunk.getBlockX(), chunk.getBlockZ());
            }
            ForgeWorld from = new ForgeWorld(freshWorld);
            for (BlockVector3 vec : region) {
                editSession.setBlock(vec, from.getFullBlock(vec));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } catch (MaxChangedBlocksException e) {
        throw new RuntimeException(e);
    } finally {
        saveFolder.delete();
    }
    return true;
}
Also used : AbstractChunkProvider(net.minecraft.world.chunk.AbstractChunkProvider) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) IOException(java.io.IOException) World(net.minecraft.world.World) ServerWorld(net.minecraft.world.server.ServerWorld) AbstractWorld(com.sk89q.worldedit.world.AbstractWorld) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVector2(com.sk89q.worldedit.math.BlockVector2) MinecraftServer(net.minecraft.server.MinecraftServer) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) ServerWorld(net.minecraft.world.server.ServerWorld) SaveHandler(net.minecraft.world.storage.SaveHandler) File(java.io.File) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider)

Example 4 with AbstractChunkProvider

use of net.minecraft.world.chunk.AbstractChunkProvider in project minecolonies by Minecolonies.

the class WorldUtil method getEntitiesWithinBuilding.

/**
 * Get all entities within a building.
 *
 * @param world     the world to check this for.
 * @param clazz     the entity class.
 * @param building  the building to check the range for.
 * @param predicate the predicate to check
 * @param <T>       the type of the predicate.
 * @return a list of all within those borders.
 */
public static <T extends Entity> List<T> getEntitiesWithinBuilding(@NotNull final World world, @NotNull final Class<? extends T> clazz, @NotNull final IBuilding building, @Nullable final Predicate<? super T> predicate) {
    final Tuple<BlockPos, BlockPos> corners = building.getCorners();
    int minX = corners.getA().getX() >> 4;
    int maxX = corners.getB().getX() >> 4;
    int minZ = corners.getA().getZ() >> 4;
    int maxZ = corners.getB().getZ() >> 4;
    int minY = Math.max(0, corners.getA().getY()) >> 4;
    int maxY = Math.min(corners.getB().getY(), world.getHeight()) >> 4;
    List<T> list = Lists.newArrayList();
    AbstractChunkProvider abstractchunkprovider = world.getChunkSource();
    for (int x = minX; x <= maxX; ++x) {
        for (int z = minZ; z <= maxZ; ++z) {
            if (isEntityChunkLoaded(world, x, z)) {
                Chunk chunk = abstractchunkprovider.getChunkNow(x, z);
                if (chunk != null) {
                    for (int y = minY; y <= maxY; y++) {
                        for (final T entity : chunk.getEntitySections()[y].find(clazz)) {
                            if (building.isInBuilding(entity.blockPosition()) && (predicate == null || predicate.test(entity))) {
                                list.add(entity);
                            }
                        }
                    }
                }
            }
        }
    }
    return list;
}
Also used : NIGHT(com.minecolonies.api.util.constant.CitizenConstants.NIGHT) AbstractChunkProvider(net.minecraft.world.chunk.AbstractChunkProvider) BlockPos(net.minecraft.util.math.BlockPos) Chunk(net.minecraft.world.chunk.Chunk)

Example 5 with AbstractChunkProvider

use of net.minecraft.world.chunk.AbstractChunkProvider in project dynmap by webbukkit.

the class ForgeMapChunkCache method setChunks.

public void setChunks(ForgeWorld dw, List<DynmapChunk> chunks) {
    this.w = (ServerWorld) 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");
        }
    }
    super.setChunks(dw, chunks);
}
Also used : AbstractChunkProvider(net.minecraft.world.chunk.AbstractChunkProvider) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider)

Aggregations

AbstractChunkProvider (net.minecraft.world.chunk.AbstractChunkProvider)6 ServerChunkProvider (net.minecraft.world.server.ServerChunkProvider)4 NIGHT (com.minecolonies.api.util.constant.CitizenConstants.NIGHT)2 BlockPos (net.minecraft.util.math.BlockPos)2 Chunk (net.minecraft.world.chunk.Chunk)2 DynmapChunk (org.dynmap.DynmapChunk)2 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 AbstractWorld (com.sk89q.worldedit.world.AbstractWorld)1 File (java.io.File)1 IOException (java.io.IOException)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 World (net.minecraft.world.World)1 ServerWorld (net.minecraft.world.server.ServerWorld)1 SaveHandler (net.minecraft.world.storage.SaveHandler)1