2018-08-12 14:03:07 +00:00
|
|
|
package com.boydti.fawe.object.extent;
|
|
|
|
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
|
|
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;
|
|
|
|
import com.sk89q.worldedit.math.MutableBlockVector;
|
|
|
|
import com.sk89q.worldedit.math.MutableVector;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BaseBiome;
|
|
|
|
import com.sk89q.worldedit.world.block.BlockState;
|
|
|
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
|
|
|
import com.sk89q.worldedit.world.registry.BlockRegistry;
|
|
|
|
|
|
|
|
public class TransformExtent extends BlockTransformExtent {
|
|
|
|
|
|
|
|
private final MutableBlockVector mutable = new MutableBlockVector();
|
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())));
|
2018-12-23 16:19:33 +00:00
|
|
|
MutableVector tmp = new MutableVector(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-12-23 16:19:33 +00:00
|
|
|
min = new BlockVector3(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())));
|
2018-12-23 16:19:33 +00:00
|
|
|
MutableVector tmp = new MutableVector(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) {
|
|
|
|
return transformFast(super.getLazyBlock(getPos(x, y, z)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockState getLazyBlock(BlockVector3 position) {
|
2018-08-12 14:03:07 +00:00
|
|
|
return transformFast(super.getLazyBlock(getPos(position)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockState getBlock(BlockVector3 position) {
|
2018-08-12 14:03:07 +00:00
|
|
|
return transformFast(super.getBlock(getPos(position)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BaseBiome getBiome(BlockVector2 position) {
|
2018-08-12 14:03:07 +00:00
|
|
|
mutable.mutX(position.getBlockX());
|
|
|
|
mutable.mutZ(position.getBlockZ());
|
|
|
|
mutable.mutY(0);
|
2019-01-09 07:13:44 +00:00
|
|
|
return super.getBiome(getPos(mutable.toBlockVector3()).toBlockVector2());
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
|
|
|
|
return super.setBlock(getPos(x, y, z), transformFastInverse((BlockState) block));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
2018-08-12 14:03:07 +00:00
|
|
|
return super.setBlock(getPos(location), transformFastInverse((BlockState) block));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public boolean setBiome(BlockVector2 position, BaseBiome biome) {
|
2018-08-12 14:03:07 +00:00
|
|
|
mutable.mutX(position.getBlockX());
|
|
|
|
mutable.mutZ(position.getBlockZ());
|
|
|
|
mutable.mutY(0);
|
2019-01-09 07:13:44 +00:00
|
|
|
return super.setBiome(getPos(mutable.toBlockVector3()).toBlockVector2(), biome);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
}
|