Permalink
Browse files

I guarantee this is broken. Start some form of string ID for blocks

  • Loading branch information...
me4502 committed Jan 3, 2018
1 parent 50f60da commit 644d5761de2476060329835f46294c8e22b1fa34
Showing with 348 additions and 117 deletions.
  1. +1 −1 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
  2. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java
  3. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java
  4. +83 −46 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java
  5. +3 −1 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java
  6. +66 −0 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockType.java
  7. +59 −0 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockTypes.java
  8. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java
  9. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java
  10. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java
  11. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java
  12. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java
  13. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java
  14. +3 −2 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java
  15. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java
  16. +2 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java
  17. +4 −4 worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java
  18. +1 −1 .../src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java
  19. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java
  20. +4 −4 worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java
  21. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/DataValidatorExtent.java
  22. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/BlockQuirkExtent.java
  23. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java
  24. +3 −2 worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java
  25. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java
  26. +3 −2 worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java
  27. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java
  28. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java
  29. +3 −2 worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java
  30. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryShape.java
  31. +4 −4 worldedit-core/src/main/java/com/sk89q/worldedit/schematic/MCEditSchematicFormat.java
  32. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java
  33. +1 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java
  34. +1 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java
  35. +50 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java
  36. +11 −10 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyBlockRegistry.java
  37. +17 −13 worldedit-core/src/test/java/com/sk89q/worldedit/CuboidClipboardTest.java
  38. +2 −2 worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java
  39. +5 −0 worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java
@@ -416,7 +416,7 @@ public boolean setBlock(Vector position, BaseBlock block, boolean notifyAndLight
return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight);
} else {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return bukkitBlock.setTypeIdAndData(block.getType(), (byte) block.getData(), notifyAndLight);
return bukkitBlock.setTypeIdAndData(block.getType().getLegacyId(), (byte) block.getData(), notifyAndLight);
}
}
@@ -1811,7 +1811,7 @@ public int makeForest(Vector basePosition, int size, double density, TreeGenerat
for (int y = basePosition.getBlockY(); y >= basePosition.getBlockY() - 10; --y) {
// Check if we hit the ground
int t = getBlock(new Vector(x, y, z)).getType();
int t = getBlock(new Vector(x, y, z)).getType().getLegacyId();
if (t == BlockID.GRASS || t == BlockID.DIRT) {
treeGenerator.generate(this, new Vector(x, y + 1, z));
++affected;
@@ -1963,7 +1963,7 @@ protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial)
final Vector scaled = current.subtract(zero).divide(unit);
try {
if (expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ(), defaultMaterial.getType(), defaultMaterial.getData()) <= 0) {
if (expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ(), defaultMaterial.getType().getLegacyId(), defaultMaterial.getData()) <= 0) {
return null;
}
@@ -308,7 +308,7 @@ public BaseBlock getBlock(Player player, String id) throws WorldEditException {
String[] items = list.split(",");
Set<Integer> blocks = new HashSet<Integer>();
for (String s : items) {
blocks.add(getBlock(player, s, allBlocksAllowed).getType());
blocks.add(getBlock(player, s, allBlocksAllowed).getType().getLegacyId());
}
return blocks;
}
@@ -23,8 +23,11 @@
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
import com.sk89q.worldedit.blocks.type.BlockType;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.foundation.Block;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.world.registry.BundledBlockData;
import com.sk89q.worldedit.world.registry.WorldData;
import javax.annotation.Nullable;
@@ -56,15 +59,6 @@
@SuppressWarnings("deprecation")
public class BaseBlock extends 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.7.
*/
public static final int MAX_ID = 4095;
/**
* Indicates the maximum data value (inclusive) that can be used. A future
* version of Minecraft may abolish block data values.
@@ -74,7 +68,7 @@
// Instances of this class should be _as small as possible_ because there will
// be millions of instances of this object.
private short id;
private BlockType blockType;
private short data;
@Nullable
private CompoundTag nbtData;
@@ -85,11 +79,21 @@
* @param id ID value
* @see #setId(int)
*/
@Deprecated
public BaseBlock(int id) {
internalSetId(id);
setId(id);
internalSetData(0);
}
/**
* Construct a block with the given type and default data.
*
* @param blockType The block type
*/
public BaseBlock(BlockType blockType) {
internalSetType(blockType);
}
/**
* Construct a block with the given ID and data value.
*
@@ -98,8 +102,25 @@ public BaseBlock(int id) {
* @see #setId(int)
* @see #setData(int)
*/
@Deprecated
public BaseBlock(int id, int data) {
internalSetId(id);
setId(id);
internalSetData(data);
}
/**
* Construct a block with the given ID and data value.
*
* THIS WILL GET REMOVED SOON.
*
* @param blockType The block type
* @param data data value
* @see #setId(int)
* @see #setData(int)
*/
@Deprecated
public BaseBlock(BlockType blockType, int data) {
internalSetType(blockType);
internalSetData(data);
}
@@ -110,12 +131,29 @@ public BaseBlock(int id, int data) {
* @param data data value
* @param nbtData NBT data, which may be null
*/
@Deprecated
public BaseBlock(int id, int data, @Nullable CompoundTag nbtData) {
setId(id);
setData(data);
setNbtData(nbtData);
}
/**
* Construct a block with the given ID, data value and NBT data structure.
*
* THIS WILL GET REMOVED SOON.
*
* @param blockType The block type
* @param data data value
* @param nbtData NBT data, which may be null
*/
@Deprecated
public BaseBlock(BlockType blockType, int data, @Nullable CompoundTag nbtData) {
setType(blockType);
setData(data);
setNbtData(nbtData);
}
/**
* Create a clone of another block.
*
@@ -126,41 +164,48 @@ public BaseBlock(BaseBlock other) {
}
/**
* Get the ID of the block.
* Get the legacy numerical ID of the block.
*
* @return ID (between 0 and {@link #MAX_ID})
* @return legacy numerical ID
*/
@Override
@Deprecated
public int getId() {
return id;
return this.blockType.getLegacyId();
}
/**
* Set the block ID.
*
* @param id block id (between 0 and {@link #MAX_ID}).
* @param type block type
*/
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");
protected final void internalSetType(BlockType type) {
if (type == null) {
throw new IllegalArgumentException("You must provide a BlockType");
}
this.id = (short) id;
this.blockType = type;
}
/**
* Set the block ID.
*
* @param id block id (between 0 and {@link #MAX_ID}).
* @param id block id
*/
@Override
@Deprecated
public void setId(int id) {
internalSetId(id);
BlockType type = BlockTypes.getBlockType(BundledBlockData.getInstance().fromLegacyId(id));
internalSetType(type);
}
/**
* Set the block type.
*
* @param type block type
*/
public void setType(BlockType type) {
internalSetType(type);
}
/**
@@ -211,6 +256,7 @@ public void setData(int data) {
* @see #setData(int)
*/
@Override
@Deprecated
public void setIdAndData(int id, int data) {
setId(id);
setData(data);
@@ -262,17 +308,8 @@ public void setNbtData(@Nullable CompoundTag nbtData) {
*
* @return the type
*/
public int getType() {
return getId();
}
/**
* Set the type of block.
*
* @param type the type to set
*/
public void setType(int type) {
setId(type);
public BlockType getType() {
return this.blockType;
}
/**
@@ -281,7 +318,7 @@ public void setType(int type) {
* @return if air
*/
public boolean isAir() {
return getType() == BlockID.AIR;
return getType().getId().equals(BlockTypes.AIR);
}
/**
@@ -292,7 +329,7 @@ public boolean isAir() {
*/
@Deprecated
public int rotate90() {
int newData = BlockData.rotate90(getType(), getData());
int newData = BlockData.rotate90(getType().getLegacyId(), getData());
setData(newData);
return newData;
}
@@ -305,7 +342,7 @@ public int rotate90() {
*/
@Deprecated
public int rotate90Reverse() {
int newData = BlockData.rotate90Reverse(getType(), getData());
int newData = BlockData.rotate90Reverse(getType().getLegacyId(), getData());
setData((short) newData);
return newData;
}
@@ -319,7 +356,7 @@ public int rotate90Reverse() {
*/
@Deprecated
public int cycleData(int increment) {
int newData = BlockData.cycle(getType(), getData(), increment);
int newData = BlockData.cycle(getType().getLegacyId(), getData(), increment);
setData((short) newData);
return newData;
}
@@ -332,7 +369,7 @@ public int cycleData(int increment) {
*/
@Deprecated
public BaseBlock flip() {
setData((short) BlockData.flip(getType(), getData()));
setData((short) BlockData.flip(getType().getLegacyId(), getData()));
return this;
}
@@ -345,7 +382,7 @@ public BaseBlock flip() {
*/
@Deprecated
public BaseBlock flip(FlipDirection direction) {
setData((short) BlockData.flip(getType(), getData(), direction));
setData((short) BlockData.flip(getType().getLegacyId(), getData(), direction));
return this;
}
@@ -397,14 +434,14 @@ public static boolean containsFuzzy(Collection<BaseBlock> collection, BaseBlock
@Override
public int hashCode() {
int ret = getId() << 3;
int ret = getType().hashCode() << 3;
if (getData() != (byte) -1) ret |= getData();
return ret;
}
@Override
public String toString() {
return "Block{ID:" + getId() + ", Data: " + getData() + "}";
return "Block{Type:" + getType().getId() + ", Data: " + getData() + "}";
}
}
@@ -35,7 +35,10 @@
/**
* Block types.
*
* {@Deprecated Please use {@link com.sk89q.worldedit.blocks.type.BlockType}}
*/
@Deprecated
public enum BlockType {
AIR(BlockID.AIR, "Air", "air"),
@@ -477,7 +480,6 @@ public String getName() {
shouldPlaceLast.add(BlockID.DETECTOR_RAIL);
shouldPlaceLast.add(BlockID.LONG_GRASS);
shouldPlaceLast.add(BlockID.DEAD_BUSH);
shouldPlaceLast.add(BlockID.PISTON_EXTENSION);
shouldPlaceLast.add(BlockID.YELLOW_FLOWER);
shouldPlaceLast.add(BlockID.RED_FLOWER);
shouldPlaceLast.add(BlockID.BROWN_MUSHROOM);
Oops, something went wrong.

0 comments on commit 644d576

Please sign in to comment.