2018-08-12 14:03:07 +00:00
|
|
|
package com.boydti.fawe.object.extent;
|
|
|
|
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-01-31 15:08:58 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockState;
|
|
|
|
import com.sk89q.worldedit.extent.Extent;
|
|
|
|
import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2019-03-31 16:09:20 +00:00
|
|
|
import com.sk89q.worldedit.math.MutableBlockVector3;
|
|
|
|
import com.sk89q.worldedit.math.MutableVector3;
|
2019-04-03 05:53:58 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
|
|
|
|
|
|
|
public class TransformExtent extends BlockTransformExtent {
|
|
|
|
|
2019-03-31 16:09:20 +00:00
|
|
|
private final MutableBlockVector3 mutable = new MutableBlockVector3();
|
2018-12-23 16:19:33 +00:00
|
|
|
private BlockVector3 min;
|
2018-08-12 14:03:07 +00:00
|
|
|
private int maxy;
|
|
|
|
|
|
|
|
public TransformExtent(Extent parent) {
|
|
|
|
super(parent);
|
|
|
|
this.maxy = parent.getMaximumPoint().getBlockY();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResettableExtent setExtent(Extent extent) {
|
|
|
|
min = null;
|
|
|
|
maxy = extent.getMaximumPoint().getBlockY();
|
|
|
|
return super.setExtent(extent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockVector3 getMinimumPoint() {
|
2019-01-09 07:13:44 +00:00
|
|
|
BlockVector3 pos1 = getPos(super.getMinimumPoint());
|
|
|
|
BlockVector3 pos2 = getPos(super.getMaximumPoint());
|
2018-12-23 16:19:33 +00:00
|
|
|
return pos1.getMinimum(pos2);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockVector3 getMaximumPoint() {
|
2019-01-09 07:13:44 +00:00
|
|
|
BlockVector3 pos1 = getPos(super.getMinimumPoint());
|
|
|
|
BlockVector3 pos2 = getPos(super.getMaximumPoint());
|
2018-12-23 16:19:33 +00:00
|
|
|
return pos1.getMaximum(pos2);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public void setOrigin(BlockVector3 pos) {
|
2018-08-12 14:03:07 +00:00
|
|
|
this.min = pos;
|
|
|
|
}
|
|
|
|
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockVector3 getPos(BlockVector3 pos) {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (min == null) {
|
2018-12-23 16:19:33 +00:00
|
|
|
min = pos;
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
mutable.mutX(((pos.getX() - min.getX())));
|
|
|
|
mutable.mutY(((pos.getY() - min.getY())));
|
|
|
|
mutable.mutZ(((pos.getZ() - min.getZ())));
|
2019-03-31 16:09:20 +00:00
|
|
|
MutableVector3 tmp = new MutableVector3(getTransform().apply(mutable.toVector3()));
|
2018-08-12 14:03:07 +00:00
|
|
|
tmp.mutX((tmp.getX() + min.getX()));
|
|
|
|
tmp.mutY((tmp.getY() + min.getY()));
|
|
|
|
tmp.mutZ((tmp.getZ() + min.getZ()));
|
2018-12-23 16:19:33 +00:00
|
|
|
return tmp.toBlockPoint();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockVector3 getPos(int x, int y, int z) {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (min == null) {
|
2018-10-19 20:13:32 +00:00
|
|
|
min = BlockVector3.at(x, y, z);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
mutable.mutX(((x - min.getX())));
|
|
|
|
mutable.mutY(((y - min.getY())));
|
|
|
|
mutable.mutZ(((z - min.getZ())));
|
2019-03-31 16:09:20 +00:00
|
|
|
MutableVector3 tmp = new MutableVector3(getTransform().apply(mutable.toVector3()));
|
2018-08-12 14:03:07 +00:00
|
|
|
tmp.mutX((tmp.getX() + min.getX()));
|
|
|
|
tmp.mutY((tmp.getY() + min.getY()));
|
|
|
|
tmp.mutZ((tmp.getZ() + min.getZ()));
|
2018-12-23 16:19:33 +00:00
|
|
|
return tmp.toBlockPoint();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockState getLazyBlock(int x, int y, int z) {
|
2019-04-07 10:43:59 +00:00
|
|
|
return transform(super.getLazyBlock(getPos(x, y, z)));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockState getLazyBlock(BlockVector3 position) {
|
2019-04-07 10:43:59 +00:00
|
|
|
return transform(super.getLazyBlock(getPos(position)));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockState getBlock(BlockVector3 position) {
|
2019-04-07 10:43:59 +00:00
|
|
|
return transform(super.getBlock(getPos(position)));
|
2019-01-31 15:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BaseBlock getFullBlock(BlockVector3 position) {
|
2019-04-07 10:43:59 +00:00
|
|
|
return transform(super.getFullBlock(getPos(position)));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-03 05:53:58 +00:00
|
|
|
public BiomeType getBiome(BlockVector2 position) {
|
2018-08-12 14:03:07 +00:00
|
|
|
mutable.mutX(position.getBlockX());
|
|
|
|
mutable.mutZ(position.getBlockZ());
|
|
|
|
mutable.mutY(0);
|
2019-03-31 16:09:20 +00:00
|
|
|
return super.getBiome(getPos(mutable).toBlockVector2());
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-07 10:43:59 +00:00
|
|
|
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
|
|
|
|
return super.setBlock(getPos(x, y, z), transformInverse(block));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-04-07 10:43:59 +00:00
|
|
|
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
|
|
|
return super.setBlock(getPos(location), transformInverse(block));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-04-03 05:53:58 +00:00
|
|
|
public boolean setBiome(BlockVector2 position, BiomeType biome) {
|
2018-08-12 14:03:07 +00:00
|
|
|
mutable.mutX(position.getBlockX());
|
|
|
|
mutable.mutZ(position.getBlockZ());
|
|
|
|
mutable.mutY(0);
|
2019-03-31 16:09:20 +00:00
|
|
|
return super.setBiome(getPos(mutable).toBlockVector2(), biome);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
}
|