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:
@ -20,8 +20,6 @@
|
||||
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.BaseBlock;
|
||||
@ -34,7 +32,6 @@ import com.sk89q.worldedit.function.mask.BlockMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
@ -53,32 +50,6 @@ public abstract class AbstractWorld implements World {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean setBlockType(Vector position, int type) {
|
||||
try {
|
||||
return setBlock(position, new BaseBlock(type));
|
||||
} catch (WorldEditException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setBlockData(Vector position, int data) {
|
||||
try {
|
||||
setBlock(position, new BaseBlock(getLazyBlock(position).getType().getLegacyId(), data));
|
||||
} catch (WorldEditException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean setTypeIdAndData(Vector position, int type, int data) {
|
||||
try {
|
||||
return setBlock(position, new BaseBlock(type, data));
|
||||
} catch (WorldEditException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean setBlock(Vector pt, BaseBlock block) throws WorldEditException {
|
||||
return setBlock(pt, block, true);
|
||||
@ -89,17 +60,6 @@ public abstract class AbstractWorld implements World {
|
||||
return getMaximumPoint().getBlockY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidBlockType(int type) {
|
||||
return BlockType.fromID(type) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesBlockData(int type) {
|
||||
// We future proof here by assuming all unknown blocks use data
|
||||
return BlockType.usesData(type) || BlockType.fromID(type) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask createLiquidMask() {
|
||||
return new BlockMask(this,
|
||||
@ -124,7 +84,7 @@ public abstract class AbstractWorld implements World {
|
||||
if (stack != null) {
|
||||
final int amount = stack.getAmount();
|
||||
if (amount > 1) {
|
||||
dropItem(pt, new BaseItemStack(stack.getType(), 1, stack.getData()), amount);
|
||||
dropItem(pt, new BaseItemStack(stack.getType(), stack.getNbtData(), 1), amount);
|
||||
} else {
|
||||
dropItem(pt, stack, amount);
|
||||
}
|
||||
@ -137,31 +97,6 @@ public abstract class AbstractWorld implements World {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.TREE, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateBigTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.BIG_TREE, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateBirchTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.BIRCH, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateRedwoodTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.REDWOOD, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) throws MaxChangedBlocksException {
|
||||
return generateTree(TreeType.TALL_REDWOOD, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkLoadedChunk(Vector pt) {
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.world.registry.WorldData;
|
||||
|
||||
/**
|
||||
@ -56,24 +55,6 @@ public interface World extends Extent {
|
||||
*/
|
||||
int getMaxY();
|
||||
|
||||
/**
|
||||
* Checks whether the given block ID is a valid block ID.
|
||||
*
|
||||
* @param id the block ID
|
||||
* @return true if the block ID is a valid one
|
||||
*/
|
||||
@Deprecated
|
||||
boolean isValidBlockType(int id);
|
||||
|
||||
/**
|
||||
* Checks whether the given block ID uses data values for differentiating
|
||||
* types of blocks.
|
||||
*
|
||||
* @param id the block ID
|
||||
* @return true if the block uses data values
|
||||
*/
|
||||
boolean usesBlockData(int id);
|
||||
|
||||
/**
|
||||
* Create a mask that matches all liquids.
|
||||
*
|
||||
@ -113,24 +94,6 @@ public interface World extends Extent {
|
||||
*/
|
||||
boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight) throws WorldEditException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setBlockType(Vector position, int type);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setBlockData(Vector position, int data);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setBlock(Vector, BaseBlock)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean setTypeIdAndData(Vector position, int type, int data);
|
||||
|
||||
/**
|
||||
* Get the light level at the given block.
|
||||
*
|
||||
@ -192,36 +155,6 @@ public interface World extends Extent {
|
||||
*/
|
||||
boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateBigTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateBirchTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateRedwoodTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #generateTree(TreeType, EditSession, Vector)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean generateTallRedwoodTree(EditSession editSession, Vector position) throws MaxChangedBlocksException;
|
||||
|
||||
/**
|
||||
* Load the chunk at the given position if it isn't loaded.
|
||||
*
|
||||
|
@ -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) {
|
||||
|
@ -53,13 +53,13 @@ public class BundledBlockRegistry implements BlockRegistry {
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockMaterial getMaterial(BaseBlock block) {
|
||||
return BundledBlockData.getInstance().getMaterialById(block.getType().getId());
|
||||
return BundledBlockData.getInstance().getMaterialById(block.getBlockType().getId());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<String, ? extends State> getStates(BaseBlock block) {
|
||||
return BundledBlockData.getInstance().getStatesById(block.getType().getId());
|
||||
return BundledBlockData.getInstance().getStatesById(block.getBlockType().getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user