mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +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:
@ -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];
|
||||
|
Reference in New Issue
Block a user