001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.generator;
020
021import com.google.inject.Inject;
022import com.plotsquared.core.location.Location;
023import com.plotsquared.core.plot.PlotArea;
024import com.plotsquared.core.plot.PlotId;
025import com.plotsquared.core.plot.world.PlotAreaManager;
026import com.plotsquared.core.plot.world.SinglePlotArea;
027import com.plotsquared.core.plot.world.SinglePlotAreaManager;
028import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
029import com.sk89q.worldedit.world.biome.BiomeType;
030import com.sk89q.worldedit.world.biome.BiomeTypes;
031import com.sk89q.worldedit.world.block.BlockState;
032import com.sk89q.worldedit.world.block.BlockTypes;
033import org.checkerframework.checker.nullness.qual.NonNull;
034
035public class SingleWorldGenerator extends IndependentPlotGenerator {
036
037    private static final Location bedrock1 = Location.at("", 0, 0, 0);
038    private static final Location bedrock2 = Location.at("", 15, 0, 15);
039    private static final Location dirt1 = Location.at("", 0, 1, 0);
040    private static final Location dirt2 = Location.at("", 15, 2, 15);
041    private static final Location grass1 = Location.at("", 0, 3, 0);
042    private static final Location grass2 = Location.at("", 15, 3, 15);
043    private static final BlockState BEDROCK = BlockTypes.BEDROCK.getDefaultState();
044    private static final BlockState DIRT = BlockTypes.DIRT.getDefaultState();
045    private static final BlockState GRASS_BLOCK = BlockTypes.GRASS_BLOCK.getDefaultState();
046
047    private final PlotAreaManager plotAreaManager;
048
049    @Inject
050    public SingleWorldGenerator(final @NonNull PlotAreaManager plotAreaManager) {
051        this.plotAreaManager = plotAreaManager;
052    }
053
054    @Override
055    public String getName() {
056        return "PlotSquared:single";
057    }
058
059    @Override
060    public void generateChunk(ZeroedDelegateScopedQueueCoordinator result, PlotArea settings, boolean biomes) {
061        SinglePlotArea area = (SinglePlotArea) settings;
062        if (area.VOID) {
063            Location min = result.getMin();
064            if (min.getX() == 0 && min.getZ() == 0) {
065                result.setBlock(0, 0, 0, BEDROCK);
066            }
067        } else {
068            result.setCuboid(bedrock1, bedrock2, BEDROCK);
069            result.setCuboid(dirt1, dirt2, DIRT);
070            result.setCuboid(grass1, grass2, GRASS_BLOCK);
071        }
072        if (biomes) {
073            result.fillBiome(BiomeTypes.PLAINS);
074        }
075    }
076
077    @Override
078    public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
079        return ((SinglePlotAreaManager) this.plotAreaManager).getArea();
080    }
081
082    @Override
083    public void initialize(PlotArea area) {
084    }
085
086    @Override
087    public BiomeType getBiome(final PlotArea settings, final int x, final int y, final int z) {
088        return BiomeTypes.PLAINS;
089    }
090
091}