mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 20:36:42 +00:00
Refactor vector system to be cleaner
- Move Vector, etc. into `.math` package - Drop many methods that will be auto-promoted anyways, eg. with `divide(int)` and `divide(double)` the first is now gone. - Take Block vectors into their own class hierarchy - Make it clear throughout the API what takes blockvectors - many more improvements
This commit is contained in:
@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.world;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
@ -28,6 +26,9 @@ import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.function.mask.BlockTypeMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
@ -46,12 +47,12 @@ public abstract class AbstractWorld implements World {
|
||||
private int taskId = -1;
|
||||
|
||||
@Override
|
||||
public boolean useItem(Vector position, BaseItem item, Direction face) {
|
||||
public boolean useItem(BlockVector3 position, BaseItem item, Direction face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean setBlock(Vector pt, BlockStateHolder block) throws WorldEditException {
|
||||
public final boolean setBlock(BlockVector3 pt, BlockStateHolder block) throws WorldEditException {
|
||||
return setBlock(pt, block, true);
|
||||
}
|
||||
|
||||
@ -66,31 +67,31 @@ public abstract class AbstractWorld implements World {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropItem(Vector pt, BaseItemStack item, int times) {
|
||||
public void dropItem(Vector3 pt, BaseItemStack item, int times) {
|
||||
for (int i = 0; i < times; ++i) {
|
||||
dropItem(pt, item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkLoadedChunk(Vector pt) {
|
||||
public void checkLoadedChunk(BlockVector3 pt) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixAfterFastMode(Iterable<BlockVector2D> chunks) {
|
||||
public void fixAfterFastMode(Iterable<BlockVector2> chunks) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixLighting(Iterable<BlockVector2D> chunks) {
|
||||
public void fixLighting(Iterable<BlockVector2> chunks) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playEffect(Vector position, int type, int data) {
|
||||
public boolean playEffect(Vector3 position, int type, int data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean queueBlockBreakEffect(Platform server, Vector position, BlockType blockType, double priority) {
|
||||
public boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority) {
|
||||
if (taskId == -1) {
|
||||
taskId = server.schedule(0, 1, () -> {
|
||||
int max = Math.max(1, Math.min(30, effectQueue.size() / 3));
|
||||
@ -106,19 +107,19 @@ public abstract class AbstractWorld implements World {
|
||||
return false;
|
||||
}
|
||||
|
||||
effectQueue.offer(new QueuedEffect(position, blockType, priority));
|
||||
effectQueue.offer(new QueuedEffect(position.toVector3(), blockType, priority));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getMinimumPoint() {
|
||||
return new Vector(-30000000, 0, -30000000);
|
||||
public BlockVector3 getMinimumPoint() {
|
||||
return new BlockVector3(-30000000, 0, -30000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getMaximumPoint() {
|
||||
return new Vector(30000000, 255, 30000000);
|
||||
public BlockVector3 getMaximumPoint() {
|
||||
return new BlockVector3(30000000, 255, 30000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -127,11 +128,11 @@ public abstract class AbstractWorld implements World {
|
||||
}
|
||||
|
||||
private class QueuedEffect implements Comparable<QueuedEffect> {
|
||||
private final Vector position;
|
||||
private final Vector3 position;
|
||||
private final BlockType blockType;
|
||||
private final double priority;
|
||||
|
||||
private QueuedEffect(Vector position, BlockType blockType, double priority) {
|
||||
private QueuedEffect(Vector3 position, BlockType blockType, double priority) {
|
||||
this.position = position;
|
||||
this.blockType = blockType;
|
||||
this.priority = priority;
|
||||
|
@ -21,12 +21,13 @@ package com.sk89q.worldedit.world;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
@ -59,36 +60,36 @@ public class NullWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
|
||||
public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockLightLevel(Vector position) {
|
||||
public int getBlockLightLevel(BlockVector3 position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearContainerBlockContents(Vector position) {
|
||||
public boolean clearContainerBlockContents(BlockVector3 position) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBiome getBiome(Vector2D position) {
|
||||
public BaseBiome getBiome(BlockVector2 position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBiome(Vector2D position, BaseBiome biome) {
|
||||
public boolean setBiome(BlockVector2 position, BaseBiome biome) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropItem(Vector position, BaseItemStack item) {
|
||||
public void dropItem(Vector3 position, BaseItemStack item) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void simulateBlockMine(Vector position) {
|
||||
public void simulateBlockMine(BlockVector3 position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -97,7 +98,7 @@ public class NullWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateTree(TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException {
|
||||
public boolean generateTree(TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -120,12 +121,12 @@ public class NullWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(Vector position) {
|
||||
public BlockState getBlock(BlockVector3 position) {
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(Vector position) {
|
||||
public BaseBlock getFullBlock(BlockVector3 position) {
|
||||
return getBlock(position).toBaseBlock();
|
||||
}
|
||||
|
||||
|
@ -19,16 +19,17 @@
|
||||
|
||||
package com.sk89q.worldedit.world;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
@ -72,10 +73,10 @@ public interface World extends Extent {
|
||||
* @param face The face
|
||||
* @return Whether it succeeded
|
||||
*/
|
||||
boolean useItem(Vector position, BaseItem item, Direction face);
|
||||
boolean useItem(BlockVector3 position, BaseItem item, Direction face);
|
||||
|
||||
/**
|
||||
* Similar to {@link Extent#setBlock(Vector, BlockStateHolder)} but a
|
||||
* Similar to {@link Extent#setBlock(BlockVector3, BlockStateHolder)} but a
|
||||
* {@code notifyAndLight} parameter indicates whether adjacent blocks
|
||||
* should be notified that changes have been made and lighting operations
|
||||
* should be executed.
|
||||
@ -92,7 +93,7 @@ public interface World extends Extent {
|
||||
* @param notifyAndLight true to to notify and light
|
||||
* @return true if the block was successfully set (return value may not be accurate)
|
||||
*/
|
||||
boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException;
|
||||
boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException;
|
||||
|
||||
/**
|
||||
* Get the light level at the given block.
|
||||
@ -100,7 +101,7 @@ public interface World extends Extent {
|
||||
* @param position the position
|
||||
* @return the light level (0-15)
|
||||
*/
|
||||
int getBlockLightLevel(Vector position);
|
||||
int getBlockLightLevel(BlockVector3 position);
|
||||
|
||||
/**
|
||||
* Clear a chest's contents.
|
||||
@ -108,7 +109,7 @@ public interface World extends Extent {
|
||||
* @param position the position
|
||||
* @return true if the container was cleared
|
||||
*/
|
||||
boolean clearContainerBlockContents(Vector position);
|
||||
boolean clearContainerBlockContents(BlockVector3 position);
|
||||
|
||||
/**
|
||||
* Drop an item at the given position.
|
||||
@ -117,23 +118,23 @@ public interface World extends Extent {
|
||||
* @param item the item to drop
|
||||
* @param count the number of individual stacks to drop (number of item entities)
|
||||
*/
|
||||
void dropItem(Vector position, BaseItemStack item, int count);
|
||||
void dropItem(Vector3 position, BaseItemStack item, int count);
|
||||
|
||||
/**
|
||||
* Drop one stack of the item at the given position.
|
||||
*
|
||||
* @param position the position
|
||||
* @param item the item to drop
|
||||
* @see #dropItem(Vector, BaseItemStack, int) shortcut method to specify the number of stacks
|
||||
* @see #dropItem(Vector3, BaseItemStack, int) shortcut method to specify the number of stacks
|
||||
*/
|
||||
void dropItem(Vector position, BaseItemStack item);
|
||||
void dropItem(Vector3 position, BaseItemStack item);
|
||||
|
||||
/**
|
||||
* Simulate a block being mined at the given position.
|
||||
*
|
||||
* @param position the position
|
||||
*/
|
||||
void simulateBlockMine(Vector position);
|
||||
void simulateBlockMine(BlockVector3 position);
|
||||
|
||||
/**
|
||||
* Regenerate an area.
|
||||
@ -153,19 +154,19 @@ public interface World extends Extent {
|
||||
* @return true if generation was successful
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks were changed
|
||||
*/
|
||||
boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* Load the chunk at the given position if it isn't loaded.
|
||||
*
|
||||
* @param position the position
|
||||
*/
|
||||
void checkLoadedChunk(Vector position);
|
||||
void checkLoadedChunk(BlockVector3 position);
|
||||
|
||||
/**
|
||||
* Fix the given chunks after fast mode was used.
|
||||
*
|
||||
* <p>Fast mode makes calls to {@link #setBlock(Vector, BlockStateHolder, boolean)}
|
||||
* <p>Fast mode makes calls to {@link #setBlock(BlockVector3, BlockStateHolder, boolean)}
|
||||
* with {@code false} for the {@code notifyAndLight} parameter, which
|
||||
* may causes lighting errors to accumulate. Use of this method, if
|
||||
* it is implemented by the underlying world, corrects those lighting
|
||||
@ -173,14 +174,14 @@ public interface World extends Extent {
|
||||
*
|
||||
* @param chunks a list of chunk coordinates to fix
|
||||
*/
|
||||
void fixAfterFastMode(Iterable<BlockVector2D> chunks);
|
||||
void fixAfterFastMode(Iterable<BlockVector2> chunks);
|
||||
|
||||
/**
|
||||
* Relight the given chunks if possible.
|
||||
*
|
||||
* @param chunks a list of chunk coordinates to fix
|
||||
*/
|
||||
void fixLighting(Iterable<BlockVector2D> chunks);
|
||||
void fixLighting(Iterable<BlockVector2> chunks);
|
||||
|
||||
/**
|
||||
* Play the given effect.
|
||||
@ -190,7 +191,7 @@ public interface World extends Extent {
|
||||
* @param data the effect data
|
||||
* @return true if the effect was played
|
||||
*/
|
||||
boolean playEffect(Vector position, int type, int data);
|
||||
boolean playEffect(Vector3 position, int type, int data);
|
||||
|
||||
/**
|
||||
* Queue a block break effect.
|
||||
@ -201,7 +202,7 @@ public interface World extends Extent {
|
||||
* @param priority the priority
|
||||
* @return true if the effect was played
|
||||
*/
|
||||
boolean queueBlockBreakEffect(Platform server, Vector position, BlockType blockType, double priority);
|
||||
boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority);
|
||||
|
||||
/**
|
||||
* Gets the weather type of the world.
|
||||
|
@ -26,9 +26,8 @@ import com.sk89q.jnbt.IntTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTUtils;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@ -52,7 +51,7 @@ public class AnvilChunk implements Chunk {
|
||||
private int rootX;
|
||||
private int rootZ;
|
||||
|
||||
private Map<BlockVector, Map<String,Tag>> tileEntities;
|
||||
private Map<BlockVector3, Map<String,Tag>> tileEntities;
|
||||
|
||||
/**
|
||||
* Construct the chunk with a compound tag.
|
||||
@ -119,10 +118,10 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
private int getBlockID(Vector position) throws DataException {
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
private int getBlockID(BlockVector3 position) throws DataException {
|
||||
int x = position.getX() - rootX * 16;
|
||||
int y = position.getY();
|
||||
int z = position.getZ() - rootZ * 16;
|
||||
|
||||
int section = y >> 4;
|
||||
if (section < 0 || section >= blocks.length) {
|
||||
@ -152,10 +151,10 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
private int getBlockData(Vector position) throws DataException {
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
private int getBlockData(BlockVector3 position) throws DataException {
|
||||
int x = position.getX() - rootX * 16;
|
||||
int y = position.getY();
|
||||
int z = position.getZ() - rootZ * 16;
|
||||
|
||||
int section = y >> 4;
|
||||
int yIndex = y & 0x0F;
|
||||
@ -225,7 +224,7 @@ public class AnvilChunk implements Chunk {
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
BlockVector vec = new BlockVector(x, y, z);
|
||||
BlockVector3 vec = new BlockVector3(x, y, z);
|
||||
tileEntities.put(vec, values);
|
||||
}
|
||||
}
|
||||
@ -240,12 +239,12 @@ public class AnvilChunk implements Chunk {
|
||||
* @throws DataException thrown if there is a data error
|
||||
*/
|
||||
@Nullable
|
||||
private CompoundTag getBlockTileEntity(Vector position) throws DataException {
|
||||
private CompoundTag getBlockTileEntity(BlockVector3 position) throws DataException {
|
||||
if (tileEntities == null) {
|
||||
populateTileEntities();
|
||||
}
|
||||
|
||||
Map<String, Tag> values = tileEntities.get(new BlockVector(position));
|
||||
Map<String, Tag> values = tileEntities.get(position);
|
||||
if (values == null) {
|
||||
return null;
|
||||
}
|
||||
@ -254,7 +253,7 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder getBlock(Vector position) throws DataException {
|
||||
public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
|
||||
int id = getBlockID(position);
|
||||
int data = getBlockData(position);
|
||||
|
||||
|
@ -26,8 +26,7 @@ import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.LongArrayTag;
|
||||
import com.sk89q.jnbt.NBTUtils;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@ -52,7 +51,7 @@ public class AnvilChunk13 implements Chunk {
|
||||
private int rootX;
|
||||
private int rootZ;
|
||||
|
||||
private Map<BlockVector, Map<String,Tag>> tileEntities;
|
||||
private Map<BlockVector3, Map<String,Tag>> tileEntities;
|
||||
|
||||
/**
|
||||
* Construct the chunk with a compound tag.
|
||||
@ -201,7 +200,7 @@ public class AnvilChunk13 implements Chunk {
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
BlockVector vec = new BlockVector(x, y, z);
|
||||
BlockVector3 vec = new BlockVector3(x, y, z);
|
||||
tileEntities.put(vec, values);
|
||||
}
|
||||
}
|
||||
@ -216,12 +215,12 @@ public class AnvilChunk13 implements Chunk {
|
||||
* @throws DataException thrown if there is a data error
|
||||
*/
|
||||
@Nullable
|
||||
private CompoundTag getBlockTileEntity(Vector position) throws DataException {
|
||||
private CompoundTag getBlockTileEntity(BlockVector3 position) throws DataException {
|
||||
if (tileEntities == null) {
|
||||
populateTileEntities();
|
||||
}
|
||||
|
||||
Map<String, Tag> values = tileEntities.get(new BlockVector(position));
|
||||
Map<String, Tag> values = tileEntities.get(position);
|
||||
if (values == null) {
|
||||
return null;
|
||||
}
|
||||
@ -230,10 +229,10 @@ public class AnvilChunk13 implements Chunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder getBlock(Vector position) throws DataException {
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
|
||||
int x = position.getX() - rootX * 16;
|
||||
int y = position.getY();
|
||||
int z = position.getZ() - rootZ * 16;
|
||||
|
||||
int section = y >> 4;
|
||||
int yIndex = y & 0x0F;
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.world.chunk;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
@ -35,6 +35,6 @@ public interface Chunk {
|
||||
* @return block the block
|
||||
* @throws DataException thrown on data error
|
||||
*/
|
||||
BlockStateHolder getBlock(Vector position) throws DataException;
|
||||
BlockStateHolder getBlock(BlockVector3 position) throws DataException;
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,8 @@ import com.sk89q.jnbt.IntTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTUtils;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@ -51,7 +50,7 @@ public class OldChunk implements Chunk {
|
||||
private int rootX;
|
||||
private int rootZ;
|
||||
|
||||
private Map<BlockVector, Map<String,Tag>> tileEntities;
|
||||
private Map<BlockVector3, Map<String,Tag>> tileEntities;
|
||||
|
||||
/**
|
||||
* Construct the chunk with a compound tag.
|
||||
@ -127,7 +126,7 @@ public class OldChunk implements Chunk {
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
BlockVector vec = new BlockVector(x, y, z);
|
||||
BlockVector3 vec = new BlockVector3(x, y, z);
|
||||
tileEntities.put(vec, values);
|
||||
}
|
||||
}
|
||||
@ -141,12 +140,12 @@ public class OldChunk implements Chunk {
|
||||
* @return a tag
|
||||
* @throws DataException
|
||||
*/
|
||||
private CompoundTag getBlockTileEntity(Vector position) throws DataException {
|
||||
private CompoundTag getBlockTileEntity(BlockVector3 position) throws DataException {
|
||||
if (tileEntities == null) {
|
||||
populateTileEntities();
|
||||
}
|
||||
|
||||
Map<String, Tag> values = tileEntities.get(new BlockVector(position));
|
||||
Map<String, Tag> values = tileEntities.get(position);
|
||||
if (values == null) {
|
||||
return null;
|
||||
}
|
||||
@ -154,13 +153,13 @@ public class OldChunk implements Chunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder getBlock(Vector position) throws DataException {
|
||||
if(position.getBlockY() >= 128) BlockTypes.VOID_AIR.getDefaultState().toBaseBlock();
|
||||
public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
|
||||
if(position.getY() >= 128) return BlockTypes.VOID_AIR.getDefaultState().toBaseBlock();
|
||||
int id, dataVal;
|
||||
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
int x = position.getX() - rootX * 16;
|
||||
int y = position.getY();
|
||||
int z = position.getZ() - rootZ * 16;
|
||||
int index = y + (z * 128 + (x * 128 * 16));
|
||||
try {
|
||||
id = blocks[index];
|
||||
|
@ -23,7 +23,7 @@ import com.google.common.io.Resources;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.util.gson.VectorAdapter;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -73,7 +73,7 @@ public class BundledBlockData {
|
||||
*/
|
||||
private void loadFromResource() throws IOException {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(Vector.class, new VectorAdapter());
|
||||
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
|
||||
Gson gson = gsonBuilder.create();
|
||||
URL url = BundledBlockData.class.getResource("blocks.json");
|
||||
if (url == null) {
|
||||
|
@ -23,7 +23,7 @@ import com.google.common.io.Resources;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.util.gson.VectorAdapter;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -73,7 +73,7 @@ public class BundledItemData {
|
||||
*/
|
||||
private void loadFromResource() throws IOException {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(Vector.class, new VectorAdapter());
|
||||
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
|
||||
Gson gson = gsonBuilder.create();
|
||||
URL url = BundledItemData.class.getResource("items.json");
|
||||
if (url == null) {
|
||||
|
@ -25,9 +25,9 @@ import com.google.common.io.Resources;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.util.gson.VectorAdapter;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
@ -71,7 +71,7 @@ public class LegacyMapper {
|
||||
*/
|
||||
private void loadFromResource() throws IOException {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(Vector.class, new VectorAdapter());
|
||||
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
|
||||
Gson gson = gsonBuilder.disableHtmlEscaping().create();
|
||||
URL url = LegacyMapper.class.getResource("legacy.json");
|
||||
if (url == null) {
|
||||
|
@ -19,12 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.world.snapshot;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
@ -43,11 +41,11 @@ import java.util.Map;
|
||||
*/
|
||||
public class SnapshotRestore {
|
||||
|
||||
private final Map<BlockVector2D, ArrayList<Vector>> neededChunks = new LinkedHashMap<>();
|
||||
private final Map<BlockVector2, ArrayList<BlockVector3>> neededChunks = new LinkedHashMap<>();
|
||||
private final ChunkStore chunkStore;
|
||||
private final EditSession editSession;
|
||||
private ArrayList<Vector2D> missingChunks;
|
||||
private ArrayList<Vector2D> errorChunks;
|
||||
private ArrayList<BlockVector2> missingChunks;
|
||||
private ArrayList<BlockVector2> errorChunks;
|
||||
private String lastErrorMessage;
|
||||
|
||||
/**
|
||||
@ -74,15 +72,15 @@ public class SnapshotRestore {
|
||||
* @param region The {@link Region} to iterate
|
||||
*/
|
||||
private void findNeededCuboidChunks(Region region) {
|
||||
Vector min = region.getMinimumPoint();
|
||||
Vector max = region.getMaximumPoint();
|
||||
BlockVector3 min = region.getMinimumPoint();
|
||||
BlockVector3 max = region.getMaximumPoint();
|
||||
|
||||
// First, we need to group points by chunk so that we only need
|
||||
// to keep one chunk in memory at any given moment
|
||||
for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
|
||||
for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) {
|
||||
for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
|
||||
Vector pos = new Vector(x, y, z);
|
||||
BlockVector3 pos = new BlockVector3(x, y, z);
|
||||
checkAndAddBlock(pos);
|
||||
}
|
||||
}
|
||||
@ -97,16 +95,16 @@ public class SnapshotRestore {
|
||||
private void findNeededChunks(Region region) {
|
||||
// First, we need to group points by chunk so that we only need
|
||||
// to keep one chunk in memory at any given moment
|
||||
for (Vector pos : region) {
|
||||
for (BlockVector3 pos : region) {
|
||||
checkAndAddBlock(pos);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAndAddBlock(Vector pos) {
|
||||
private void checkAndAddBlock(BlockVector3 pos) {
|
||||
if (editSession.getMask() != null && !editSession.getMask().test(pos))
|
||||
return;
|
||||
|
||||
BlockVector2D chunkPos = ChunkStore.toChunk(pos);
|
||||
BlockVector2 chunkPos = ChunkStore.toChunk(pos);
|
||||
|
||||
// Unidentified chunk
|
||||
if (!neededChunks.containsKey(chunkPos)) {
|
||||
@ -136,8 +134,8 @@ public class SnapshotRestore {
|
||||
errorChunks = new ArrayList<>();
|
||||
|
||||
// Now let's start restoring!
|
||||
for (Map.Entry<BlockVector2D, ArrayList<Vector>> entry : neededChunks.entrySet()) {
|
||||
BlockVector2D chunkPos = entry.getKey();
|
||||
for (Map.Entry<BlockVector2, ArrayList<BlockVector3>> entry : neededChunks.entrySet()) {
|
||||
BlockVector2 chunkPos = entry.getKey();
|
||||
Chunk chunk;
|
||||
|
||||
try {
|
||||
@ -145,7 +143,7 @@ public class SnapshotRestore {
|
||||
// Good, the chunk could be at least loaded
|
||||
|
||||
// Now just copy blocks!
|
||||
for (Vector pos : entry.getValue()) {
|
||||
for (BlockVector3 pos : entry.getValue()) {
|
||||
try {
|
||||
editSession.setBlock(pos, chunk.getBlock(pos));
|
||||
} catch (DataException e) {
|
||||
@ -167,7 +165,7 @@ public class SnapshotRestore {
|
||||
*
|
||||
* @return a list of coordinates
|
||||
*/
|
||||
public List<Vector2D> getMissingChunks() {
|
||||
public List<BlockVector2> getMissingChunks() {
|
||||
return missingChunks;
|
||||
}
|
||||
|
||||
@ -177,7 +175,7 @@ public class SnapshotRestore {
|
||||
*
|
||||
* @return a list of coordinates
|
||||
*/
|
||||
public List<Vector2D> getErrorChunks() {
|
||||
public List<BlockVector2> getErrorChunks() {
|
||||
return errorChunks;
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,8 @@ package com.sk89q.worldedit.world.storage;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.chunk.AnvilChunk;
|
||||
@ -57,11 +56,8 @@ public abstract class ChunkStore implements Closeable {
|
||||
* @param position the position
|
||||
* @return chunk coordinates
|
||||
*/
|
||||
public static BlockVector2D toChunk(Vector position) {
|
||||
int chunkX = (int) Math.floor(position.getBlockX() / 16.0);
|
||||
int chunkZ = (int) Math.floor(position.getBlockZ() / 16.0);
|
||||
|
||||
return new BlockVector2D(chunkX, chunkZ);
|
||||
public static BlockVector2 toChunk(BlockVector3 position) {
|
||||
return new BlockVector2(position.getX() >> CHUNK_SHIFTS, position.getZ() >> CHUNK_SHIFTS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,7 +68,7 @@ public abstract class ChunkStore implements Closeable {
|
||||
* @throws DataException thrown on data error
|
||||
* @throws IOException thrown on I/O error
|
||||
*/
|
||||
public abstract CompoundTag getChunkTag(Vector2D position, World world) throws DataException, IOException;
|
||||
public abstract CompoundTag getChunkTag(BlockVector2 position, World world) throws DataException, IOException;
|
||||
|
||||
/**
|
||||
* Get a chunk at a location.
|
||||
@ -83,7 +79,7 @@ public abstract class ChunkStore implements Closeable {
|
||||
* @throws DataException thrown on data error
|
||||
* @throws IOException thrown on I/O error
|
||||
*/
|
||||
public Chunk getChunk(Vector2D position, World world) throws DataException, IOException {
|
||||
public Chunk getChunk(BlockVector2 position, World world) throws DataException, IOException {
|
||||
CompoundTag rootTag = getChunkTag(position, world);
|
||||
|
||||
Map<String, Tag> children = rootTag.getValue();
|
||||
|
@ -22,14 +22,13 @@ package com.sk89q.worldedit.world.storage;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
@ -46,7 +45,7 @@ public abstract class LegacyChunkStore extends ChunkStore {
|
||||
* @param separator folder separator character
|
||||
* @return pathname
|
||||
*/
|
||||
public static String getFilename(Vector2D position, String separator) {
|
||||
public static String getFilename(BlockVector2 position, String separator) {
|
||||
int x = position.getBlockX();
|
||||
int z = position.getBlockZ();
|
||||
|
||||
@ -65,12 +64,12 @@ public abstract class LegacyChunkStore extends ChunkStore {
|
||||
* @param position chunk position
|
||||
* @return pathname
|
||||
*/
|
||||
public static String getFilename(Vector2D position) {
|
||||
public static String getFilename(BlockVector2 position) {
|
||||
return getFilename(position, File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getChunkTag(Vector2D position, World world) throws DataException, IOException {
|
||||
public CompoundTag getChunkTag(BlockVector2 position, World world) throws DataException, IOException {
|
||||
int x = position.getBlockX();
|
||||
int z = position.getBlockZ();
|
||||
|
||||
|
@ -22,13 +22,12 @@ package com.sk89q.worldedit.world.storage;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class McRegionChunkStore extends ChunkStore {
|
||||
|
||||
@ -41,14 +40,14 @@ public abstract class McRegionChunkStore extends ChunkStore {
|
||||
* @param position chunk position
|
||||
* @return the filename
|
||||
*/
|
||||
public static String getFilename(Vector2D position) {
|
||||
public static String getFilename(BlockVector2 position) {
|
||||
int x = position.getBlockX();
|
||||
int z = position.getBlockZ();
|
||||
|
||||
return "r." + (x >> 5) + "." + (z >> 5) + ".mca";
|
||||
}
|
||||
|
||||
protected McRegionReader getReader(Vector2D pos, String worldname) throws DataException, IOException {
|
||||
protected McRegionReader getReader(BlockVector2 pos, String worldname) throws DataException, IOException {
|
||||
String filename = getFilename(pos);
|
||||
if (curFilename != null) {
|
||||
if (curFilename.equals(filename)) {
|
||||
@ -67,7 +66,7 @@ public abstract class McRegionChunkStore extends ChunkStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getChunkTag(Vector2D position, World world) throws DataException, IOException {
|
||||
public CompoundTag getChunkTag(BlockVector2 position, World world) throws DataException, IOException {
|
||||
McRegionReader reader = getReader(position, world.getName());
|
||||
|
||||
InputStream stream = reader.getChunkInputStream(position);
|
||||
|
@ -55,7 +55,7 @@
|
||||
|
||||
package com.sk89q.worldedit.world.storage;
|
||||
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.util.io.ForwardSeekableInputStream;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
|
||||
@ -120,7 +120,7 @@ public class McRegionReader {
|
||||
* @throws IOException
|
||||
* @throws DataException
|
||||
*/
|
||||
public synchronized InputStream getChunkInputStream(Vector2D position) throws IOException, DataException {
|
||||
public synchronized InputStream getChunkInputStream(BlockVector2 position) throws IOException, DataException {
|
||||
int x = position.getBlockX() & 31;
|
||||
int z = position.getBlockZ() & 31;
|
||||
|
||||
|
@ -19,20 +19,20 @@
|
||||
|
||||
package com.sk89q.worldedit.world.storage;
|
||||
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.math.Vector2;
|
||||
|
||||
/**
|
||||
* Thrown if a chunk is missing.
|
||||
*/
|
||||
public class MissingChunkException extends ChunkStoreException {
|
||||
|
||||
private Vector2D position;
|
||||
private Vector2 position;
|
||||
|
||||
public MissingChunkException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MissingChunkException(Vector2D position) {
|
||||
public MissingChunkException(Vector2 position) {
|
||||
super();
|
||||
this.position = position;
|
||||
}
|
||||
@ -42,7 +42,7 @@ public class MissingChunkException extends ChunkStoreException {
|
||||
*
|
||||
* @return a chunk position
|
||||
*/
|
||||
public Vector2D getChunkPosition() {
|
||||
public Vector2 getChunkPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user