From b612de342993897cd4f243acf7568763009efcd1 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 23 Jun 2013 20:27:11 +0200 Subject: [PATCH] Added Block and id/data overloads to canPassThrough, centralTopLimit and isNaturalTerrainBlock. --- .../com/sk89q/worldedit/blocks/BlockType.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java index 96c22df77..8f9e2f53b 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java @@ -28,6 +28,7 @@ import java.util.Set; import com.sk89q.util.StringUtil; import com.sk89q.worldedit.PlayerDirection; +import com.sk89q.worldedit.foundation.Block; /** * Block types. @@ -460,16 +461,40 @@ public enum BlockType { canPassThrough.add(BlockID.CARPET); } + /** * Checks whether a block can be passed through. * * @param id * @return + * @deprecated Use {@link #canPassThrough(int,int)} instead */ + @Deprecated public static boolean canPassThrough(int id) { return canPassThrough.contains(id); } + /** + * Checks whether a block can be passed through. + * + * @param id + * @param data + * @return + */ + public static boolean canPassThrough(int id, int data) { + return canPassThrough.contains(-16*id-data) || canPassThrough.contains(id); + } + + /** + * Checks whether a block can be passed through. + * + * @param block + * @return + */ + public static boolean canPassThrough(Block block) { + return canPassThrough(block.getId(), block.getData()); + } + /** * Checks whether a block can be passed through. * @@ -541,6 +566,16 @@ public enum BlockType { return canPassThrough(id) ? 0 : 1; } + /** + * Returns the y offset a player falls to when falling onto the top of a block at xp+0.5/zp+0.5. + * + * @param block + * @return + */ + public static double centralTopLimit(Block block) { + return centralTopLimit(block.getId(), block.getData()); + } + /** * Returns the y offset a player falls to when falling onto the top of a block at xp+0.5/zp+0.5. * @@ -912,6 +947,26 @@ public enum BlockType { return isNaturalTerrainBlock.contains(id); } + /** + * Checks if the block type is naturally occuring + * + * @param block + * @return + */ + public static boolean isNaturalTerrainBlock(int id, int data) { + return isNaturalTerrainBlock.contains(-16*id-data) || isNaturalTerrainBlock.contains(id); + } + + /** + * Checks if the block type is naturally occuring + * + * @param block + * @return + */ + public static boolean isNaturalTerrainBlock(Block block) { + return isNaturalTerrainBlock(block.getId(), block.getData()); + } + /** * Checks if the block type is naturally occuring *