Plex-FAWE/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java

113 lines
3.6 KiB
Java
Raw Normal View History

package com.boydti.fawe.object.extent;
import com.sk89q.worldedit.WorldEditException;
2019-05-28 20:31:22 +00:00
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.block.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;
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;
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;
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-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);
}
@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);
}
@Override
2018-12-23 16:19:33 +00:00
public void setOrigin(BlockVector3 pos) {
this.min = pos;
}
2018-12-23 16:19:33 +00:00
public BlockVector3 getPos(BlockVector3 pos) {
if (min == null) {
2018-12-23 16:19:33 +00:00
min = pos;
}
2019-05-28 20:31:22 +00:00
mutable1.mutX(((pos.getX() - min.getX())));
mutable1.mutY(((pos.getY() - min.getY())));
mutable1.mutZ(((pos.getZ() - min.getZ())));
Vector3 tmp = getTransform().apply(mutable1);
mutable2.mutX((tmp.getX() + min.getX()));
mutable2.mutY((tmp.getY() + min.getY()));
mutable2.mutZ((tmp.getZ() + min.getZ()));
return mutable2;
}
2018-12-23 16:19:33 +00:00
public BlockVector3 getPos(int x, int y, int z) {
if (min == null) {
min = BlockVector3.at(x, y, z);
}
2019-05-28 20:31:22 +00:00
mutable1.mutX(((x - min.getX())));
mutable1.mutY(((y - min.getY())));
mutable1.mutZ(((z - min.getZ())));
Vector3 tmp = getTransform().apply(mutable1);
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();
}
@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-06-23 18:00:22 +00:00
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
return transform(super.getFullBlock(getPos(position)));
}
@Override
2019-07-09 07:18:51 +00:00
public BiomeType getBiomeType(int x, int z) {
2019-05-28 20:31:22 +00:00
BlockVector3 p = getPos(x, 0, z);
2019-07-09 07:18:51 +00:00
return super.getBiomeType(p.getX(), p.getZ());
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
return super.setBlock(getPos(x, y, z), transformInverse(block));
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
return super.setBlock(getPos(location), transformInverse(block));
}
@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);
}
}