Fix BlockArrayClipboard offset

This commit is contained in:
Jesse Boyd 2019-11-05 15:08:44 +00:00
parent 69b2b4eea8
commit 0bfb1dbdd1
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 37 additions and 39 deletions

View File

@ -85,13 +85,11 @@ public class AsyncChunk implements Chunk {
return task.value; return task.value;
} }
if (world.isWorld()) { if (world.isWorld()) {
if (world.isChunkLoaded(x, z)) {
if (world.isChunkLoaded(x, z)) { if (world.isChunkLoaded(x, z)) {
task.run(); task.run();
return task.value; return task.value;
} }
} }
}
return TaskManager.IMP.sync(task); return TaskManager.IMP.sync(task);
} }

View File

@ -139,7 +139,7 @@ public class ClipboardCommands {
actor.checkConfirmationRegion(() -> { actor.checkConfirmationRegion(() -> {
session.setClipboard(null); session.setClipboard(null);
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId()); Clipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId());
session.setClipboard(new ClipboardHolder(clipboard)); session.setClipboard(new ClipboardHolder(clipboard));

View File

@ -50,7 +50,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class BlockArrayClipboard extends DelegateClipboard implements Clipboard, Closeable { public class BlockArrayClipboard extends DelegateClipboard implements Clipboard, Closeable {
private Region region; private Region region;
private BlockVector3 origin; private BlockVector3 offset;
public BlockArrayClipboard(Region region) { public BlockArrayClipboard(Region region) {
this(region, UUID.randomUUID()); this(region, UUID.randomUUID());
@ -67,14 +67,14 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
this(region, Clipboard.create(region.getDimensions(), clipboardId)); this(region, Clipboard.create(region.getDimensions(), clipboardId));
checkNotNull(region); checkNotNull(region);
this.region = region.clone(); this.region = region.clone();
this.origin = region.getMinimumPoint(); this.offset = region.getMinimumPoint();
} }
public BlockArrayClipboard(Region region, Clipboard clipboard) { public BlockArrayClipboard(Region region, Clipboard clipboard) {
super(clipboard); super(clipboard);
checkNotNull(region); checkNotNull(region);
this.region = region.clone(); this.region = region.clone();
this.origin = region.getMinimumPoint(); this.offset = region.getMinimumPoint();
} }
@Override @Override
@ -88,12 +88,12 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
@Override @Override
public BlockVector3 getOrigin() { public BlockVector3 getOrigin() {
return origin; return getParent().getOrigin().add(region.getMinimumPoint());
} }
@Override @Override
public void setOrigin(BlockVector3 origin) { public void setOrigin(BlockVector3 origin) {
this.origin = origin; // this.origin = origin;
getParent().setOrigin(origin.subtract(region.getMinimumPoint())); getParent().setOrigin(origin.subtract(region.getMinimumPoint()));
} }
@ -110,9 +110,9 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
@Override @Override
public BlockState getBlock(BlockVector3 position) { public BlockState getBlock(BlockVector3 position) {
if (region.contains(position)) { if (region.contains(position)) {
int x = position.getBlockX()- origin.getX(); int x = position.getBlockX()- offset.getX();
int y = position.getBlockY()- origin.getY(); int y = position.getBlockY()- offset.getY();
int z = position.getBlockZ()- origin.getZ(); int z = position.getBlockZ()- offset.getZ();
return getParent().getBlock(x, y, z); return getParent().getBlock(x, y, z);
} }
@ -122,9 +122,9 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
@Override @Override
public BaseBlock getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
if(region.contains(position)) { if(region.contains(position)) {
int x = position.getBlockX()- origin.getX(); int x = position.getBlockX()- offset.getX();
int y = position.getBlockY()- origin.getY(); int y = position.getBlockY()- offset.getY();
int z = position.getBlockZ()- origin.getZ(); int z = position.getBlockZ()- offset.getZ();
return getParent().getFullBlock(x, y, z); return getParent().getFullBlock(x, y, z);
} }
return BlockTypes.AIR.getDefaultState().toBaseBlock(); return BlockTypes.AIR.getDefaultState().toBaseBlock();
@ -143,9 +143,9 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tag) { public boolean setTile(int x, int y, int z, CompoundTag tag) {
x -= origin.getX(); x -= offset.getX();
y -= origin.getY(); y -= offset.getY();
z -= origin.getZ(); z -= offset.getZ();
return getParent().setTile(x, y, z, tag); return getParent().setTile(x, y, z, tag);
} }
@ -155,9 +155,9 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
@Override @Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException { public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
x -= origin.getX(); x -= offset.getX();
y -= origin.getY(); y -= offset.getY();
z -= origin.getZ(); z -= offset.getZ();
return getParent().setBlock(x, y, z, block); return getParent().setBlock(x, y, z, block);
} }
@ -174,23 +174,23 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
@Override @Override
public boolean setBiome(BlockVector2 position, BiomeType biome) { public boolean setBiome(BlockVector2 position, BiomeType biome) {
int x = position.getBlockX() - origin.getX(); int x = position.getBlockX() - offset.getX();
int z = position.getBlockZ() - origin.getZ(); int z = position.getBlockZ() - offset.getZ();
return getParent().setBiome(x, 0, z, biome); return getParent().setBiome(x, 0, z, biome);
} }
@Override @Override
public boolean setBiome(int x, int y, int z, BiomeType biome) { public boolean setBiome(int x, int y, int z, BiomeType biome) {
x -= origin.getX(); x -= offset.getX();
y -= origin.getY(); y -= offset.getY();
z -= origin.getZ(); z -= offset.getZ();
return getParent().setBiome(x, y, z, biome); return getParent().setBiome(x, y, z, biome);
} }
@Override @Override
public List<? extends Entity> getEntities(Region region) { public List<? extends Entity> getEntities(Region region) {
region = region.clone(); region = region.clone();
region.shift(origin); region.shift(BlockVector3.ZERO.subtract(offset));
return getParent().getEntities(region); return getParent().getEntities(region);
} }
@ -203,32 +203,32 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
@Override @Override
@Nullable @Nullable
public void removeEntity(int x, int y, int z, UUID uuid) { public void removeEntity(int x, int y, int z, UUID uuid) {
x -= origin.getX(); x -= offset.getX();
y -= origin.getY(); y -= offset.getY();
z -= origin.getZ(); z -= offset.getZ();
getParent().removeEntity(x, y, z, uuid); getParent().removeEntity(x, y, z, uuid);
} }
@Override @Override
public BlockState getBlock(int x, int y, int z) { public BlockState getBlock(int x, int y, int z) {
x -= origin.getX(); x -= offset.getX();
y -= origin.getY(); y -= offset.getY();
z -= origin.getZ(); z -= offset.getZ();
return getParent().getBlock(x, y, z); return getParent().getBlock(x, y, z);
} }
@Override @Override
public BaseBlock getFullBlock(int x, int y, int z) { public BaseBlock getFullBlock(int x, int y, int z) {
x -= origin.getX(); x -= offset.getX();
y -= origin.getY(); y -= offset.getY();
z -= origin.getZ(); z -= offset.getZ();
return getParent().getFullBlock(x, y, z); return getParent().getFullBlock(x, y, z);
} }
@Override @Override
public BiomeType getBiomeType(int x, int z) { public BiomeType getBiomeType(int x, int z) {
x -= origin.getX(); x -= offset.getX();
z -= origin.getZ(); z -= offset.getZ();
return getParent().getBiomeType(x, z); return getParent().getBiomeType(x, z);
} }