Removed foundation.* package.

This commit is contained in:
sk89q
2014-04-02 21:23:14 -07:00
parent a08ee7bce9
commit 08900cbfc2
9 changed files with 270 additions and 289 deletions

View File

@ -19,36 +19,216 @@
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
import com.sk89q.worldedit.foundation.Block;
import com.sk89q.worldedit.world.DataException;
import java.util.Collection;
/**
* Represents a block.
*
* @see Block new class to replace this one
* @author sk89q
* Represents a mutable copy of a block that is not tied to any 'real' block in a world.
* A single instance of this can be set to multiple locations and each location would
* have a copy of this instance's data.
* </p>
* Implementations can and should extend this class to allow native implementations
* of NBT data handling, primarily for performance reasons. Subclasses can only convert
* from and to WorldEdit-native NBT structures when absolutely necessary (a.k.a. when
* {@link #getNbtData()} and {@link #setNbtData(CompoundTag)} are called). When
* overriding the NBT methods, {@link #getNbtId()} should be overridden too, otherwise
* the default implementation will invoke {@link #getNbtData()}, a potentially costly
* operation when it is not needed. Implementations may want to cache converted NBT data
* structures if possible.
*/
public class BaseBlock extends Block {
public class BaseBlock extends Block implements TileEntityBlock {
/**
* Construct the block with its type, with default data value 0.
*
* @param type type ID of block
* Indicates the highest possible block ID (inclusive) that can be used. This value
* is subject to change depending on the implementation, but internally this class
* only supports a range of 4096 IDs (for space reasons), which coincides with the
* number of possible IDs that official Minecraft supports as of version 1.3.
*/
public BaseBlock(int type) {
this(type, 0);
public static final int MAX_ID = 4095;
/**
* Indicates the maximum data value (inclusive) that can be used. Minecraft 1.4 may
* abolish usage of data values and this value may be removed in the future.
*/
public static final int MAX_DATA = 15;
// Instances of this class should be _as small as possible_ because there will
// be millions of instances of this object.
private short id;
private short data;
private CompoundTag nbtData;
/**
* Construct a block with the given ID and a data value of 0.
*
* @param id ID value
* @see #setId(int)
*/
public BaseBlock(int id) {
internalSetId(id);
internalSetData(0);
}
/**
* Construct the block with its type and data.
* Construct a block with the given ID and data value.
*
* @param type type ID of block
* @param id ID value
* @param data data value
* @see #setId(int)
* @see #setData(int)
*/
public BaseBlock(int type, int data) {
super(type, data);
public BaseBlock(int id, int data) {
internalSetId(id);
internalSetData(data);
}
/**
* Construct a block with the given ID, data value, and NBT data structure.
*
* @param id ID value
* @param data data value
* @param nbtData NBT data
* @throws DataException if possibly the data is invalid
* @see #setId(int)
* @see #setData(int)
* @see #setNbtData(CompoundTag)
*/
public BaseBlock(int id, int data, CompoundTag nbtData) throws DataException {
setId(id);
setData(data);
setNbtData(nbtData);
}
/**
* Get the ID of the block.
*
* @return ID (between 0 and {@link #MAX_ID})
*/
public int getId() {
return id;
}
/**
* Set the block ID.
*
* @param id block id (between 0 and {@link #MAX_ID}).
*/
protected final void internalSetId(int id) {
if (id > MAX_ID) {
throw new IllegalArgumentException("Can't have a block ID above "
+ MAX_ID + " (" + id + " given)");
}
if (id < 0) {
throw new IllegalArgumentException("Can't have a block ID below 0");
}
this.id = (short) id;
}
/**
* Set the block ID.
*
* @param id block id (between 0 and {@link #MAX_ID}).
*/
public void setId(int id) {
internalSetId(id);
}
/**
* Get the block's data value.
*
* @return data value (0-15)
*/
public int getData() {
return data;
}
/**
* Set the block's data value.
*
* @param data block data value (between 0 and {@link #MAX_DATA}).
*/
protected final void internalSetData(int data) {
if (data > MAX_DATA) {
throw new IllegalArgumentException(
"Can't have a block data value above " + MAX_DATA + " ("
+ data + " given)");
}
if (data < -1) {
throw new IllegalArgumentException("Can't have a block data value below -1");
}
this.data = (short) data;
}
/**
* Set the block's data value.
*
* @param data block data value (between 0 and {@link #MAX_DATA}).
*/
public void setData(int data) {
internalSetData(data);
}
/**
* Set both the block's ID and data value.
*
* @param id ID value
* @param data data value
* @see #setId(int)
* @see #setData(int)
*/
public void setIdAndData(int id, int data) {
setId(id);
setData(data);
}
/**
* Returns whether the data value is -1, indicating that this block is to be
* used as a wildcard matching block.
*
* @return true if the data value is -1
*/
public boolean hasWildcardData() {
return getData() == -1;
}
@Override
public boolean hasNbtData() {
return getNbtData() != null;
}
@Override
public String getNbtId() {
CompoundTag nbtData = getNbtData();
if (nbtData == null) {
return "";
}
Tag idTag = nbtData.getValue().get("id");
if (idTag != null && idTag instanceof StringTag) {
return ((StringTag) idTag).getValue();
} else {
return "";
}
}
@Override
public CompoundTag getNbtData() {
return nbtData;
}
@Override
public void setNbtData(CompoundTag nbtData) throws DataException {
this.nbtData = nbtData;
}
/**
@ -184,4 +364,17 @@ public class BaseBlock extends Block {
}
return false;
}
@Override
public int hashCode() {
int ret = getId() << 3;
if (getData() != (byte) -1) ret |= getData();
return ret;
}
@Override
public String toString() {
return "Block{ID:" + getId() + ", Data: " + getData() + "}";
}
}

View File

@ -19,16 +19,10 @@
package com.sk89q.worldedit.blocks;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.PlayerDirection;
import com.sk89q.worldedit.foundation.Block;
import java.util.*;
/**
* Block types.
@ -552,7 +546,7 @@ public enum BlockType {
* @param block
* @return
*/
public static boolean canPassThrough(Block block) {
public static boolean canPassThrough(BaseBlock block) {
return canPassThrough(block.getId(), block.getData());
}
@ -649,7 +643,7 @@ public enum BlockType {
* @param block
* @return
*/
public static double centralTopLimit(Block block) {
public static double centralTopLimit(BaseBlock block) {
return centralTopLimit(block.getId(), block.getData());
}
@ -1053,7 +1047,7 @@ public enum BlockType {
* @param block The block
* @return true if the block type is naturally occuring
*/
public static boolean isNaturalTerrainBlock(Block block) {
public static boolean isNaturalTerrainBlock(BaseBlock block) {
return isNaturalTerrainBlock(block.getId(), block.getData());
}

View File

@ -19,7 +19,7 @@
package com.sk89q.worldedit.blocks;
import com.sk89q.worldedit.foundation.NbtValued;
import com.sk89q.worldedit.world.NbtValued;
/**
* Indicates a block that contains extra data identified as an NBT structure. Compared