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.queue;
020
021import com.plotsquared.core.location.Location;
022import com.sk89q.jnbt.CompoundTag;
023import com.sk89q.worldedit.function.pattern.Pattern;
024import com.sk89q.worldedit.world.biome.BiomeType;
025import com.sk89q.worldedit.world.block.BaseBlock;
026import com.sk89q.worldedit.world.block.BlockState;
027import org.checkerframework.checker.nullness.qual.NonNull;
028import org.checkerframework.checker.nullness.qual.Nullable;
029
030/**
031 * Queue that only sets blocks with a designated X-Z area, will accept any Y values. Requires all blocks be set normalized in
032 * the x and z directions, i.e. starting from 0,0. An offset of the minimum point of the region will then be applied to x and z.
033 *
034 * @deprecated This should be renamed to NormalizedScopedQueueCoordinator or something.
035 */
036@Deprecated(forRemoval = true, since = "6.8.0")
037public class ScopedQueueCoordinator extends DelegateQueueCoordinator {
038
039    private final Location min;
040    private final Location max;
041    private final int minX;
042    private final int minZ;
043
044    private final int maxX;
045    private final int maxZ;
046
047    private final int dx;
048    private final int dz;
049
050    /**
051     * Create a new ScopedQueueCoordinator instance that delegates to a given QueueCoordinator. Locations are inclusive.
052     */
053    public ScopedQueueCoordinator(@Nullable QueueCoordinator parent, @NonNull Location min, @NonNull Location max) {
054        super(parent);
055        this.min = min;
056        this.max = max;
057        this.minX = min.getX();
058        this.minZ = min.getZ();
059
060        this.maxX = max.getX();
061        this.maxZ = max.getZ();
062
063        this.dx = maxX - minX;
064        this.dz = maxZ - minZ;
065    }
066
067    @Override
068    public boolean setBiome(int x, int z, @NonNull BiomeType biome) {
069        return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBiome(x + minX, z + minZ, biome);
070    }
071
072    @Override
073    public boolean setBiome(int x, int y, int z, @NonNull BiomeType biome) {
074        return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBiome(x + minX, y, z + minZ, biome);
075    }
076
077    public void fillBiome(BiomeType biome) {
078        for (int y = min.getY(); y <= max.getY(); y++) {
079            for (int x = 0; x <= dx; x++) {
080                for (int z = 0; z < dz; z++) {
081                    setBiome(x, y, z, biome);
082                }
083            }
084        }
085    }
086
087    @Override
088    public boolean setBlock(int x, int y, int z, @NonNull BaseBlock id) {
089        return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBlock(x + minX, y, z + minZ, id);
090    }
091
092    @Override
093    public boolean setBlock(int x, int y, int z, @NonNull BlockState id) {
094        return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBlock(x + minX, y, z + minZ, id);
095    }
096
097    @Override
098    public boolean setBlock(int x, int y, int z, @NonNull Pattern pattern) {
099        return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setBlock(x + minX, y, z + minZ, pattern);
100    }
101
102    @Override
103    public boolean setTile(int x, int y, int z, @NonNull CompoundTag tag) {
104        return x >= 0 && x <= dx && z >= 0 && z <= dz && super.setTile(x + minX, y, z + minZ, tag);
105    }
106
107    public @NonNull Location getMin() {
108        return min;
109    }
110
111    public @NonNull Location getMax() {
112        return max;
113    }
114
115}