2021-07-23 15:48:51 +00:00
|
|
|
package com.fastasyncworldedit.core.extent;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.FaweCache;
|
2021-07-23 15:48:51 +00:00
|
|
|
import com.fastasyncworldedit.core.extent.processor.ProcessorScope;
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.object.FaweLimit;
|
2021-07-24 15:34:05 +00:00
|
|
|
import com.fastasyncworldedit.core.queue.IBatchProcessor;
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.util.ExtentTraverser;
|
|
|
|
import com.fastasyncworldedit.core.util.WEManager;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
|
|
|
import com.sk89q.worldedit.entity.BaseEntity;
|
|
|
|
import com.sk89q.worldedit.entity.Entity;
|
|
|
|
import com.sk89q.worldedit.extent.Extent;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
|
|
|
import com.sk89q.worldedit.util.Location;
|
2019-04-03 05:53:58 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2019-09-21 01:52:35 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
|
|
|
import com.sk89q.worldedit.world.block.BlockState;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
2019-06-23 18:05:14 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
2020-07-14 02:50:59 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import javax.annotation.Nullable;
|
2021-07-24 15:34:05 +00:00
|
|
|
import java.util.Collection;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2019-10-23 04:23:52 +00:00
|
|
|
public abstract class FaweRegionExtent extends ResettableExtent implements IBatchProcessor {
|
2020-04-30 20:26:52 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
private final FaweLimit limit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param extent the extent
|
|
|
|
*/
|
|
|
|
public FaweRegionExtent(Extent extent, FaweLimit limit) {
|
|
|
|
super(extent);
|
|
|
|
this.limit = limit;
|
|
|
|
}
|
|
|
|
|
2021-08-16 09:03:06 +00:00
|
|
|
@Override
|
2018-08-12 14:03:07 +00:00
|
|
|
public abstract boolean contains(int x, int y, int z);
|
|
|
|
|
|
|
|
public abstract boolean contains(int x, int z);
|
|
|
|
|
|
|
|
public abstract Collection<Region> getRegions();
|
|
|
|
|
|
|
|
public boolean isGlobal() {
|
2019-10-23 04:23:52 +00:00
|
|
|
for (Region r : getRegions()) {
|
|
|
|
if (r.isGlobal()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-24 02:33:51 +00:00
|
|
|
|
2019-10-23 04:23:52 +00:00
|
|
|
public Extent construct(Extent child) {
|
|
|
|
if (getExtent() != child) {
|
|
|
|
new ExtentTraverser<Extent>(this).setNext(child);
|
|
|
|
}
|
|
|
|
return this;
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public final boolean contains(BlockVector3 p) {
|
2018-08-12 14:03:07 +00:00
|
|
|
return contains(p.getBlockX(), p.getBlockY(), p.getBlockZ());
|
|
|
|
}
|
|
|
|
|
2018-12-23 16:19:33 +00:00
|
|
|
public final boolean contains(BlockVector2 p) {
|
2018-08-12 14:03:07 +00:00
|
|
|
return contains(p.getBlockX(), p.getBlockZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-30 20:26:52 +00:00
|
|
|
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block)
|
2021-07-24 15:34:05 +00:00
|
|
|
throws WorldEditException {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (!contains(x, y, z)) {
|
|
|
|
if (!limit.MAX_FAILS()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return super.setBlock(x, y, z, block);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-03 05:53:58 +00:00
|
|
|
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (!contains(x, y, z)) {
|
|
|
|
if (!limit.MAX_FAILS()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return super.setBiome(x, y, z, biome);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-09-12 13:31:42 +00:00
|
|
|
public BiomeType getBiome(BlockVector3 position) {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (!contains(position)) {
|
|
|
|
if (!limit.MAX_FAILS()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2019-04-03 05:53:58 +00:00
|
|
|
return null;
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
return super.getBiome(position);
|
|
|
|
}
|
2019-06-23 18:05:14 +00:00
|
|
|
|
2019-03-25 17:31:12 +00:00
|
|
|
@Override
|
2019-12-19 16:19:46 +00:00
|
|
|
public BiomeType getBiomeType(int x, int y, int z) {
|
2019-05-12 14:21:01 +00:00
|
|
|
if (!contains(x, z)) {
|
2019-03-25 17:31:12 +00:00
|
|
|
if (!limit.MAX_FAILS()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
2019-03-25 17:31:12 +00:00
|
|
|
}
|
2019-05-12 14:21:01 +00:00
|
|
|
return null;
|
2019-03-25 17:31:12 +00:00
|
|
|
}
|
2019-12-19 16:19:46 +00:00
|
|
|
return super.getBiomeType(x, y, z);
|
2019-03-25 17:31:12 +00:00
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
@Override
|
2019-05-12 14:21:01 +00:00
|
|
|
public BaseBlock getFullBlock(BlockVector3 position) {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (!contains(position)) {
|
|
|
|
if (!limit.MAX_FAILS()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2019-07-09 07:18:51 +00:00
|
|
|
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2019-05-12 14:21:01 +00:00
|
|
|
return super.getFullBlock(position);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-12 14:21:01 +00:00
|
|
|
public BlockState getBlock(BlockVector3 position) {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (!contains(position)) {
|
|
|
|
if (!limit.MAX_FAILS()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2019-06-23 18:05:14 +00:00
|
|
|
return BlockTypes.AIR.getDefaultState();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2019-05-12 14:21:01 +00:00
|
|
|
return super.getBlock(position);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public Entity createEntity(Location location, BaseEntity entity) {
|
|
|
|
if (!contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
|
|
|
|
if (!limit.MAX_FAILS()) {
|
2020-01-29 20:01:38 +00:00
|
|
|
WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return super.createEntity(location, entity);
|
|
|
|
}
|
2021-01-11 19:29:16 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ProcessorScope getScope() {
|
|
|
|
return ProcessorScope.READING_SET_BLOCKS;
|
|
|
|
}
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|