2018-08-12 14:03:07 +00:00
|
|
|
package com.boydti.fawe.object.extent;
|
|
|
|
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
|
|
|
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.BlockVector3;
|
2019-03-31 16:09:20 +00:00
|
|
|
import com.sk89q.worldedit.math.MutableBlockVector3;
|
|
|
|
import com.sk89q.worldedit.math.MutableVector3;
|
2019-07-22 20:42:40 +00:00
|
|
|
import com.sk89q.worldedit.math.Vector3;
|
2019-04-03 05:53:58 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2019-07-22 20:42:40 +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;
|
|
|
|
|
|
|
|
public class TransformExtent extends BlockTransformExtent {
|
|
|
|
|
2019-05-28 20:31:22 +00:00
|
|
|
private final MutableVector3 mutable1 = new MutableVector3();
|
|
|
|
private final MutableBlockVector3 mutable2 = new MutableBlockVector3();
|
2018-12-23 16:19:33 +00:00
|
|
|
private BlockVector3 min;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
public TransformExtent(Extent parent) {
|
|
|
|
super(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResettableExtent setExtent(Extent extent) {
|
|
|
|
min = null;
|
|
|
|
return super.setExtent(extent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockVector3 getMinimumPoint() {
|
2019-07-22 20:42:40 +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-07-22 20:42:40 +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
|
|
|
}
|
2019-09-21 01:52:35 +00:00
|
|
|
mutable1.mutX(pos.getX() - min.getX());
|
|
|
|
mutable1.mutY(pos.getY() - min.getY());
|
|
|
|
mutable1.mutZ(pos.getZ() - min.getZ());
|
2019-05-28 20:31:22 +00:00
|
|
|
Vector3 tmp = getTransform().apply(mutable1);
|
2019-09-21 01:52:35 +00:00
|
|
|
mutable2.mutX(tmp.getX() + min.getX());
|
|
|
|
mutable2.mutY(tmp.getY() + min.getY());
|
|
|
|
mutable2.mutZ(tmp.getZ() + min.getZ());
|
2019-05-28 20:31:22 +00:00
|
|
|
return mutable2;
|
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
|
|
|
}
|
2019-09-21 01:52:35 +00:00
|
|
|
mutable1.mutX(x - min.getX());
|
|
|
|
mutable1.mutY(y - min.getY());
|
|
|
|
mutable1.mutZ(z - min.getZ());
|
2019-05-28 20:31:22 +00:00
|
|
|
Vector3 tmp = getTransform().apply(mutable1);
|
2019-09-21 01:52:35 +00:00
|
|
|
mutable2.mutX(tmp.getX() + min.getX());
|
|
|
|
mutable2.mutY(tmp.getY() + min.getY());
|
|
|
|
mutable2.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
|
2019-05-28 20:31:22 +00:00
|
|
|
public BlockState getBlock(int x, int y, int z) {
|
|
|
|
BlockVector3 p = getPos(x, y, z);
|
|
|
|
return transform(super.getBlock(p.getX(), p.getY(), p.getZ()));
|
2019-01-31 15:08:58 +00:00
|
|
|
}
|
2019-06-23 18:00:22 +00:00
|
|
|
|
2019-01-31 15:08:58 +00:00
|
|
|
@Override
|
|
|
|
public BaseBlock getFullBlock(BlockVector3 position) {
|
2019-07-22 20:42:40 +00:00
|
|
|
return transform(super.getFullBlock(getPos(position)));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-12-19 16:19:46 +00:00
|
|
|
public BiomeType getBiomeType(int x, int y, int z) {
|
|
|
|
BlockVector3 p = getPos(x, y, z);
|
|
|
|
return super.getBiomeType(p.getX(), y, p.getZ());
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-21 01:52:35 +00:00
|
|
|
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
|
2019-04-07 10:43:59 +00:00
|
|
|
return super.setBlock(getPos(x, y, z), transformInverse(block));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-09-21 01:52:35 +00:00
|
|
|
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
2019-04-07 10:43:59 +00:00
|
|
|
return super.setBlock(getPos(location), transformInverse(block));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-28 20:31:22 +00:00
|
|
|
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
|
|
|
BlockVector3 p = getPos(x, y, z);
|
|
|
|
return super.setBiome(p.getX(), p.getY(), p.getZ(), biome);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
}
|