2014-03-31 23:55:58 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
2014-03-31 23:55:58 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
2014-03-31 23:55:58 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-03-31 23:55:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.extent;
|
|
|
|
|
2018-12-23 16:19:33 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2019-07-06 00:46:48 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-06-12 13:45:41 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
2019-06-25 17:07:47 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
2019-06-12 13:45:41 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2019-06-25 17:07:47 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
2014-03-31 23:55:58 +00:00
|
|
|
|
2014-04-01 03:29:05 +00:00
|
|
|
/**
|
|
|
|
* Requires that all mutating methods pass a given {@link Mask}.
|
|
|
|
*/
|
2014-04-04 01:41:36 +00:00
|
|
|
public class MaskingExtent extends AbstractDelegateExtent {
|
2014-03-31 23:55:58 +00:00
|
|
|
|
|
|
|
private Mask mask;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param extent the extent
|
2019-06-04 15:48:30 +00:00
|
|
|
* @param mask the mask
|
2014-03-31 23:55:58 +00:00
|
|
|
*/
|
|
|
|
public MaskingExtent(Extent extent, Mask mask) {
|
|
|
|
super(extent);
|
|
|
|
checkNotNull(mask);
|
|
|
|
this.mask = mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mask.
|
|
|
|
*
|
|
|
|
* @return the mask
|
|
|
|
*/
|
|
|
|
public Mask getMask() {
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a mask.
|
|
|
|
*
|
|
|
|
* @param mask a mask
|
|
|
|
*/
|
|
|
|
public void setMask(Mask mask) {
|
|
|
|
checkNotNull(mask);
|
|
|
|
this.mask = mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-27 00:39:10 +00:00
|
|
|
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
2014-04-01 03:29:05 +00:00
|
|
|
return mask.test(location) && super.setBlock(location, block);
|
2014-03-31 23:55:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Override
|
2019-04-03 05:53:34 +00:00
|
|
|
public boolean setBiome(BlockVector2 position, BiomeType biome) {
|
2019-01-09 07:13:44 +00:00
|
|
|
return mask.test(position.toBlockVector3()) && super.setBiome(position, biome);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-03 05:53:34 +00:00
|
|
|
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
2018-10-19 20:13:32 +00:00
|
|
|
return mask.test(BlockVector3.at(x, y, z)) && super.setBiome(x, y, z, biome);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 16:36:39 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
}
|