mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
Further BaseBlock modernisation
This commit is contained in:
@ -118,8 +118,7 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockID(Vector position) throws DataException {
|
||||
private int getBlockID(Vector position) throws DataException {
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
@ -130,9 +129,6 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
|
||||
int yindex = y & 0x0F;
|
||||
if (yindex < 0 || yindex >= 16) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
|
||||
int index = x + (z * 16 + (yindex * 16 * 16));
|
||||
|
||||
@ -155,8 +151,7 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockData(Vector position) throws DataException {
|
||||
private int getBlockData(Vector position) throws DataException {
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
@ -167,10 +162,6 @@ public class AnvilChunk implements Chunk {
|
||||
if (section < 0 || section >= blocks.length) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
|
||||
if (yIndex < 0 || yIndex >= 16) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
|
||||
int index = x + (z * 16 + (yIndex * 16 * 16));
|
||||
boolean shift = index % 2 == 0;
|
||||
@ -200,8 +191,7 @@ public class AnvilChunk implements Chunk {
|
||||
|
||||
for (Tag tag : tags) {
|
||||
if (!(tag instanceof CompoundTag)) {
|
||||
throw new InvalidFormatException(
|
||||
"CompoundTag expected in TileEntities");
|
||||
throw new InvalidFormatException("CompoundTag expected in TileEntities");
|
||||
}
|
||||
|
||||
CompoundTag t = (CompoundTag) tag;
|
||||
@ -268,21 +258,7 @@ public class AnvilChunk implements Chunk {
|
||||
int data = getBlockData(position);
|
||||
BaseBlock block;
|
||||
|
||||
/*if (id == BlockID.WALL_SIGN || id == BlockID.SIGN_POST) {
|
||||
block = new SignBlock(id, data);
|
||||
} else if (id == BlockID.CHEST) {
|
||||
block = new ChestBlock(data);
|
||||
} else if (id == BlockID.FURNACE || id == BlockID.BURNING_FURNACE) {
|
||||
block = new FurnaceBlock(id, data);
|
||||
} else if (id == BlockID.DISPENSER) {
|
||||
block = new DispenserBlock(data);
|
||||
} else if (id == BlockID.MOB_SPAWNER) {
|
||||
block = new MobSpawnerBlock(data);
|
||||
} else if (id == BlockID.NOTE_BLOCK) {
|
||||
block = new NoteBlock(data);
|
||||
} else {*/
|
||||
block = new BaseBlock(id, data);
|
||||
//}
|
||||
block = new BaseBlock(id, data);
|
||||
|
||||
CompoundTag tileEntity = getBlockTileEntity(position);
|
||||
if (tileEntity != null) {
|
||||
|
@ -27,25 +27,6 @@ import com.sk89q.worldedit.world.DataException;
|
||||
* A 16 by 16 block chunk.
|
||||
*/
|
||||
public interface Chunk {
|
||||
|
||||
/**
|
||||
* Get the block ID of a block.
|
||||
*
|
||||
* @param position the position of the block
|
||||
* @return the type ID of the block
|
||||
* @throws DataException thrown on data error
|
||||
*/
|
||||
public int getBlockID(Vector position) throws DataException;
|
||||
|
||||
/**
|
||||
* Get the block data of a block.
|
||||
*
|
||||
* @param position the position of the block
|
||||
* @return the data value of the block
|
||||
* @throws DataException thrown on data error
|
||||
*/
|
||||
public int getBlockData(Vector position) throws DataException;
|
||||
|
||||
|
||||
/**
|
||||
* Get a block;
|
||||
@ -54,6 +35,6 @@ public interface Chunk {
|
||||
* @return block the block
|
||||
* @throws DataException thrown on data error
|
||||
*/
|
||||
public BaseBlock getBlock(Vector position) throws DataException;
|
||||
BaseBlock getBlock(Vector position) throws DataException;
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
||||
@ -76,43 +77,6 @@ public class OldChunk implements Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockID(Vector position) throws DataException {
|
||||
if(position.getBlockY() >= 128) return 0;
|
||||
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
int index = y + (z * 128 + (x * 128 * 16));
|
||||
try {
|
||||
return blocks[index];
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockData(Vector position) throws DataException {
|
||||
if(position.getBlockY() >= 128) return 0;
|
||||
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
int index = y + (z * 128 + (x * 128 * 16));
|
||||
boolean shift = index % 2 == 0;
|
||||
index /= 2;
|
||||
|
||||
try {
|
||||
if (!shift) {
|
||||
return (data[index] & 0xF0) >> 4;
|
||||
} else {
|
||||
return data[index] & 0xF;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to load the tile entities.
|
||||
*
|
||||
@ -188,25 +152,33 @@ public class OldChunk implements Chunk {
|
||||
|
||||
@Override
|
||||
public BaseBlock getBlock(Vector position) throws DataException {
|
||||
int id = getBlockID(position);
|
||||
int data = getBlockData(position);
|
||||
BaseBlock block;
|
||||
if(position.getBlockY() >= 128) new BaseBlock(BlockTypes.AIR);
|
||||
int id, dataVal;
|
||||
|
||||
/*if (id == BlockID.WALL_SIGN || id == BlockID.SIGN_POST) {
|
||||
block = new SignBlock(id, data);
|
||||
} else if (id == BlockID.CHEST) {
|
||||
block = new ChestBlock(data);
|
||||
} else if (id == BlockID.FURNACE || id == BlockID.BURNING_FURNACE) {
|
||||
block = new FurnaceBlock(id, data);
|
||||
} else if (id == BlockID.DISPENSER) {
|
||||
block = new DispenserBlock(data);
|
||||
} else if (id == BlockID.MOB_SPAWNER) {
|
||||
block = new MobSpawnerBlock(data);
|
||||
} else if (id == BlockID.NOTE_BLOCK) {
|
||||
block = new NoteBlock(data);
|
||||
} else {*/
|
||||
block = new BaseBlock(id, data);
|
||||
//}
|
||||
int x = position.getBlockX() - rootX * 16;
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ() - rootZ * 16;
|
||||
int index = y + (z * 128 + (x * 128 * 16));
|
||||
try {
|
||||
id = blocks[index];
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
|
||||
boolean shift = index % 2 == 0;
|
||||
index /= 2;
|
||||
|
||||
try {
|
||||
if (!shift) {
|
||||
dataVal = (data[index] & 0xF0) >> 4;
|
||||
} else {
|
||||
dataVal = data[index] & 0xF;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new DataException("Chunk does not contain position " + position);
|
||||
}
|
||||
|
||||
BaseBlock block = new BaseBlock(id, dataVal);
|
||||
|
||||
CompoundTag tileEntity = getBlockTileEntity(position);
|
||||
if (tileEntity != null) {
|
||||
|
Reference in New Issue
Block a user