From 08900cbfc289d7880d5a21331b1008ac89487c79 Mon Sep 17 00:00:00 2001
From: sk89q
Date: Wed, 2 Apr 2014 21:23:14 -0700
Subject: [PATCH] Removed foundation.* package.
---
.../sk89q/worldedit/bukkit/BukkitWorld.java | 2 +-
.../com/sk89q/worldedit/foundation/Block.java | 41 +++
.../java/com/sk89q/worldedit/LocalWorld.java | 5 +-
.../com/sk89q/worldedit/blocks/BaseBlock.java | 223 ++++++++++++++--
.../com/sk89q/worldedit/blocks/BlockType.java | 16 +-
.../worldedit/blocks/TileEntityBlock.java | 2 +-
.../com/sk89q/worldedit/foundation/Block.java | 248 ------------------
.../{foundation => world}/NbtValued.java | 2 +-
.../{foundation => world}/World.java | 20 +-
9 files changed, 270 insertions(+), 289 deletions(-)
create mode 100644 src/legacy/java/com/sk89q/worldedit/foundation/Block.java
delete mode 100644 src/main/java/com/sk89q/worldedit/foundation/Block.java
rename src/main/java/com/sk89q/worldedit/{foundation => world}/NbtValued.java (98%)
rename src/main/java/com/sk89q/worldedit/{foundation => world}/World.java (84%)
diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
index 2ea7d9f3b..9471bcd71 100644
--- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
+++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
@@ -1313,7 +1313,7 @@ public class BukkitWorld extends LocalWorld {
}
@Override
- public boolean setBlock(Vector pt, com.sk89q.worldedit.foundation.Block block, boolean notifyAdjacent) {
+ public boolean setBlock(Vector pt, BaseBlock block, boolean notifyAdjacent) {
if (!skipNmsSafeSet) {
try {
return (Boolean) nmsSetSafeMethod.invoke(null, this, pt, block, notifyAdjacent);
diff --git a/src/legacy/java/com/sk89q/worldedit/foundation/Block.java b/src/legacy/java/com/sk89q/worldedit/foundation/Block.java
new file mode 100644
index 000000000..44085daea
--- /dev/null
+++ b/src/legacy/java/com/sk89q/worldedit/foundation/Block.java
@@ -0,0 +1,41 @@
+// $Id$
+/*
+ * This file is a part of WorldEdit.
+ * Copyright (c) sk89q
+ * Copyright (c) the WorldEdit team and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+*/
+
+package com.sk89q.worldedit.foundation;
+
+import com.sk89q.worldedit.blocks.BaseBlock;
+
+/**
+ * @deprecated Use {@link BaseBlock}
+ */
+@Deprecated
+public abstract class Block {
+
+ public abstract int getId();
+
+ public abstract void setId(int id);
+
+ public abstract int getData();
+
+ public abstract void setData(int data);
+
+ public abstract void setIdAndData(int id, int data);
+
+ public abstract boolean hasWildcardData();
+
+}
diff --git a/src/main/java/com/sk89q/worldedit/LocalWorld.java b/src/main/java/com/sk89q/worldedit/LocalWorld.java
index 3e4571bfc..8b6d63aef 100644
--- a/src/main/java/com/sk89q/worldedit/LocalWorld.java
+++ b/src/main/java/com/sk89q/worldedit/LocalWorld.java
@@ -21,8 +21,7 @@ package com.sk89q.worldedit;
import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.extent.Extent;
-import com.sk89q.worldedit.foundation.Block;
-import com.sk89q.worldedit.foundation.World;
+import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operation;
@@ -533,7 +532,7 @@ public abstract class LocalWorld implements World, Extent {
}
@Override
- public boolean setBlock(Vector pt, Block block, boolean notifyAdjacent) {
+ public boolean setBlock(Vector pt, BaseBlock block, boolean notifyAdjacent) {
boolean successful;
// Default implementation will call the old deprecated methods
diff --git a/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java b/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java
index b65314fc9..f7f73321c 100644
--- a/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java
+++ b/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java
@@ -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.
+ *
+ * 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() + "}";
+ }
+
}
diff --git a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java
index 5483f2ca6..10bc6c206 100644
--- a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java
+++ b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java
@@ -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());
}
diff --git a/src/main/java/com/sk89q/worldedit/blocks/TileEntityBlock.java b/src/main/java/com/sk89q/worldedit/blocks/TileEntityBlock.java
index 11d7fcc2f..d6e747eee 100644
--- a/src/main/java/com/sk89q/worldedit/blocks/TileEntityBlock.java
+++ b/src/main/java/com/sk89q/worldedit/blocks/TileEntityBlock.java
@@ -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
diff --git a/src/main/java/com/sk89q/worldedit/foundation/Block.java b/src/main/java/com/sk89q/worldedit/foundation/Block.java
deleted file mode 100644
index 35f922bd0..000000000
--- a/src/main/java/com/sk89q/worldedit/foundation/Block.java
+++ /dev/null
@@ -1,248 +0,0 @@
-// $Id$
-/*
- * This file is a part of WorldEdit.
- * Copyright (c) sk89q
- * Copyright (c) the WorldEdit team and contributors
- *
- * This program is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License along with
- * this program. If not, see .
-*/
-
-package com.sk89q.worldedit.foundation;
-
-import com.sk89q.jnbt.CompoundTag;
-import com.sk89q.jnbt.StringTag;
-import com.sk89q.jnbt.Tag;
-import com.sk89q.worldedit.blocks.BaseBlock;
-import com.sk89q.worldedit.blocks.TileEntityBlock;
-import com.sk89q.worldedit.world.DataException;
-
-/**
- * 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.
- *
- * 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.
- *
- * Currently, {@link BaseBlock} is used throughout WorldEdit and implementations, but
- * eventually an API-breaking transition will occur to switch to this object instead.
- * As-is, the definition of this class is complete, but may need changes in MC 1.4
- * because data values may be eradicated.
- */
-public class Block implements TileEntityBlock {
-
- /**
- * 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 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 Block(int id) {
- internalSetId(id);
- internalSetData(0);
- }
-
- /**
- * Construct a block with the given ID and data value.
- *
- * @param id ID value
- * @param data data value
- * @see #setId(int)
- * @see #setData(int)
- */
- public Block(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 Block(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;
- }
-
- @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() + "}";
- }
-
-}
diff --git a/src/main/java/com/sk89q/worldedit/foundation/NbtValued.java b/src/main/java/com/sk89q/worldedit/world/NbtValued.java
similarity index 98%
rename from src/main/java/com/sk89q/worldedit/foundation/NbtValued.java
rename to src/main/java/com/sk89q/worldedit/world/NbtValued.java
index b92d966d1..70410030f 100644
--- a/src/main/java/com/sk89q/worldedit/foundation/NbtValued.java
+++ b/src/main/java/com/sk89q/worldedit/world/NbtValued.java
@@ -16,7 +16,7 @@
* this program. If not, see .
*/
-package com.sk89q.worldedit.foundation;
+package com.sk89q.worldedit.world;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.DataException;
diff --git a/src/main/java/com/sk89q/worldedit/foundation/World.java b/src/main/java/com/sk89q/worldedit/world/World.java
similarity index 84%
rename from src/main/java/com/sk89q/worldedit/foundation/World.java
rename to src/main/java/com/sk89q/worldedit/world/World.java
index d01a0abad..c7f250730 100644
--- a/src/main/java/com/sk89q/worldedit/foundation/World.java
+++ b/src/main/java/com/sk89q/worldedit/world/World.java
@@ -16,10 +16,12 @@
* this program. If not, see .
*/
-package com.sk89q.worldedit.foundation;
+package com.sk89q.worldedit.world;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.blocks.BaseBlock;
+import com.sk89q.worldedit.foundation.Block;
/**
* Represents a world instance that can be modified. The world instance could be
@@ -33,8 +35,8 @@ public interface World {
/**
* Change the block at the given location to the given block. The operation may
- * not tie the given {@link Block} to the world, so future changes to the
- * {@link Block} do not affect the world until this method is called again.
+ * not tie the given {@link BaseBlock} to the world, so future changes to the
+ * {@link BaseBlock} do not affect the world until this method is called again.
*
* Implementations may or may not consider the value of the notifyAdjacent
* parameter, and implementations may to choose to either apply physics anyway or
@@ -47,23 +49,23 @@ public interface World {
* occur and 'false' should be returned. If possible, the return value should be
* accurate as possible, but implementations may choose to not provide an accurate
* value if it is not possible to know.
- *
+ *
* @param location location of the block
* @param block block to set
* @param notifyAdjacent true to to notify adjacent (perform physics)
* @return true if the block was successfully set (return value may not be accurate)
*/
- boolean setBlock(Vector location, Block block, boolean notifyAdjacent);
-
+ boolean setBlock(Vector location, BaseBlock block, boolean notifyAdjacent);
+
/**
* Get a copy of the block at the given location. May return null if the location
* given is out of bounds. The returned block must not be tied to any real block
* in the world, so changes to the returned {@link Block} have no effect until
- * {@link #setBlock(Vector, Block, boolean)} is called.
- *
+ * {@link #setBlock(Vector, BaseBlock, boolean)} is called.
+ *
* @param location location of the block
* @return the block, or null if the block does not exist
*/
- Block getBlock(Vector location);
+ BaseBlock getBlock(Vector location);
}