From 142499832770a3652ba8595205c398204d644644 Mon Sep 17 00:00:00 2001 From: matt <4009945+MattBDev@users.noreply.github.com> Date: Wed, 27 Mar 2019 11:36:26 -0400 Subject: [PATCH] Simplified switch statements and minor formatting --- .../com/boydti/fawe/example/IntFaweChunk.java | 14 +++----- .../com/boydti/fawe/object/FaweQueue.java | 7 ++-- .../brush/visualization/VisualChunk.java | 17 ++++------ .../clipboard/CPUOptimizedClipboard.java | 9 ++--- .../clipboard/DiskOptimizedClipboard.java | 27 +++++++-------- .../clipboard/MemoryOptimizedClipboard.java | 16 +++------ .../object/schematic/StructureFormat.java | 33 +++++++++---------- .../command/tool/FloatingTreeRemover.java | 13 +++----- 8 files changed, 50 insertions(+), 86 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/example/IntFaweChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/example/IntFaweChunk.java index 2d6c7f7b9..6b924faaf 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/example/IntFaweChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/example/IntFaweChunk.java @@ -202,16 +202,12 @@ public abstract class IntFaweChunk extends FaweChunk } vs[j] = combinedId; this.count[i]++; - switch (BlockTypes.getFromStateId(combinedId).getResource().toUpperCase()) { - case "AIR": - case "CAVE_AIR": - case "VOID_AIR": - this.air[i]++; - return; - default: - heightMap[z << 4 | x] = (byte) y; - return; + if (BlockTypes.getFromStateId(combinedId).getMaterial().isAir()) { + this.air[i]++; + return; } + heightMap[z << 4 | x] = (byte) y; + return; } @Deprecated diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java index 347807f43..eb6dd406a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java @@ -284,11 +284,8 @@ public interface FaweQueue extends HasFaweQueue, Extent { int combined = getCombinedId4Data(xx, y, zz); BaseBlock block = BlockState.getFromInternalId(combined).toBaseBlock(); BlockType type = block.getBlockType(); - switch (type.getResource().toUpperCase()) { - case "AIR": - case "VOID_AIR": - case "CAVE_AIR": - continue; + if (type.getMaterial().isAir()) { + continue; } mutable.mutY(y); CompoundTag tile = getTileEntity(x, y, z); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualChunk.java index 1ce779754..3ab6dac36 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualChunk.java @@ -115,17 +115,12 @@ public class VisualChunk extends FaweChunk { public void setBlock(int x, int y, int z, int combinedId) { int index = getIndex(x, y, z); try { - switch (BlockTypes.getFromStateId(combinedId).getResource().toUpperCase()) { - case "AIR": - case "CAVE_AIR": - case "VOID_AIR": - add.clear(index); - remove.set(index); - break; - default: - remove.clear(index); - add.set(index); - break; + if (BlockTypes.getFromStateId(combinedId).getMaterial().isAir()) { + add.clear(index); + remove.set(index); + } else { + remove.clear(index); + add.set(index); } } catch (Throwable e) { e.printStackTrace(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java index bc430a84f..fe51280d7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java @@ -175,13 +175,8 @@ public class CPUOptimizedClipboard extends FaweClipboard { for (int z = 0; z < length; z++) { for (int x = 0; x < width; x++, index++) { BaseBlock block = getBlock(index); - switch (block.getBlockType().getResource().toUpperCase()) { - case "AIR": - case "CAVE_AIR": - case "VOID_AIR": - continue; - default: - task.run(x, y, z, block); + if (!block.getMaterial().isAir()) { + task.run(x, y, z, block); } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index fc48c3b6a..ca74f0ab9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -404,23 +404,18 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { for (int x = 0; x < width; x++, pos += 4) { int combinedId = mbb.getInt(pos); BlockType type = BlockTypes.getFromStateId(combinedId); - switch (type.getResource().toUpperCase()) { - case "AIR": - case "CAVE_AIR": - case "VOID_AIR": - continue; - default: - BlockState state = type.withStateId(combinedId); - if (type.getMaterial().hasContainer()) { - trio.set(x, y, z); - CompoundTag nbt = nbtMap.get(trio); - if (nbt != null) { - BaseBlock block = new BaseBlock(state, nbt); - task.run(x, y, z, block); - continue; - } + if (!type.getMaterial().isAir()) { + BlockState state = type.withStateId(combinedId); + if (type.getMaterial().hasContainer()) { + trio.set(x, y, z); + CompoundTag nbt = nbtMap.get(trio); + if (nbt != null) { + BaseBlock block = new BaseBlock(state, nbt); + task.run(x, y, z, block); + continue; } - task.run(x, y, z, state); + } + task.run(x, y, z, state); } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java index 8f95ee6d1..4b44692a8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java @@ -205,11 +205,8 @@ public class MemoryOptimizedClipboard extends FaweClipboard { } if (lastCombinedIds == null) { BlockType bt = BlockTypes.getFromStateId(v); - switch (bt.getResource().toUpperCase()) { - case "AIR": - case "CAVE_AIR": - case "VOID_AIR": - return; + if (bt.getMaterial().isAir()) { + return; } lastCombinedIds = new byte[BLOCK_SIZE]; } @@ -299,13 +296,8 @@ public class MemoryOptimizedClipboard extends FaweClipboard { for (int z = 0; z < length; z++) { for (int x = 0; x < width; x++, index++) { BaseBlock block = getBlock(index); - switch (block.getBlockType().getResource().toUpperCase()) { - case "AIR": - case "CAVE_AIR": - case "VOID_AIR": - continue; - default: - task.run(x, y, z, block); + if (!block.getMaterial().isAir()) { + task.run(x, y, z, block); } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java index ca77bf03a..bdcf2b42c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/StructureFormat.java @@ -84,7 +84,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter { ListTag blocks = (ListTag) tags.get("blocks"); if (blocks != null) { // Palette - List palette = (List) (List) tags.get("palette").getValue(); + List palette = (List) tags.get("palette").getValue(); BlockState[] combinedArray = new BlockState[palette.size()]; for (int i = 0; i < palette.size(); i++) { CompoundTag compound = palette.get(i); @@ -108,7 +108,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter { combinedArray[i] = state; } // Populate blocks - List blocksList = (List) (List) tags.get("blocks").getValue(); + List blocksList = (List) tags.get("blocks").getValue(); try { for (CompoundTag compound : blocksList) { Map blockMap = compound.getValue(); @@ -184,7 +184,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter { continue; } - indexes.put((int) combined, (Integer) palette.size()); + indexes.put(combined, (Integer) palette.size()); HashMap paletteEntry = new HashMap<>(); paletteEntry.put("Name", type.getId()); if (block.getInternalId() != type.getInternalId()) { @@ -213,18 +213,17 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter { BlockVector3 min = region.getMinimumPoint(); for (BlockVector3 point : region) { BaseBlock block = clipboard.getFullBlock(point); - switch (block.getBlockType().getResource().toUpperCase()) { - case "STRUCTURE_VOID": - continue; - default: - int combined = block.getInternalId(); - int index = indexes.get(combined); - List pos = Arrays.asList((int) (point.getX() - min.getX()), (int) (point.getY() - min.getY()), (int) (point.getZ() - min.getZ())); - if (!block.hasNbtData()) { - blocks.add(FaweCache.asMap("state", index, "pos", pos)); - } else { - blocks.add(FaweCache.asMap("state", index, "pos", pos, "nbt", block.getNbtData())); - } + if (block.getBlockType() != BlockTypes.STRUCTURE_VOID) { + int combined = block.getInternalId(); + int index = indexes.get(combined); + List pos = Arrays.asList(point.getX() - min.getX(), + point.getY() - min.getY(), point.getZ() - min.getZ()); + if (!block.hasNbtData()) { + blocks.add(FaweCache.asMap("state", index, "pos", pos)); + } else { + blocks.add( + FaweCache.asMap("state", index, "pos", pos, "nbt", block.getNbtData())); + } } } if (!blocks.isEmpty()) { @@ -268,7 +267,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter { } private Tag writeVector(BlockVector3 vector, String name) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(new DoubleTag(vector.getX())); list.add(new DoubleTag(vector.getY())); list.add(new DoubleTag(vector.getZ())); @@ -276,7 +275,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter { } private Tag writeRotation(Location location, String name) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(new FloatTag(location.getYaw())); list.add(new FloatTag(location.getPitch())); return new ListTag(FloatTag.class, list); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java index 2703c195e..591bbe158 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java @@ -66,7 +66,7 @@ public class FloatingTreeRemover implements BlockTool { @Override public boolean actPrimary(Platform server, LocalConfiguration config, - Player player, LocalSession session, Location clicked) { + Player player, LocalSession session, Location clicked) { final World world = (World) clicked.getExtent(); final BlockState state = world.getBlock(clicked.toVector().toBlockPoint()); @@ -132,13 +132,8 @@ public class FloatingTreeRemover implements BlockTool { if (visited.add(next)) { BlockState state = world.getBlock(next); - BlockType type = state.getBlockType(); - switch (type.getResource().toUpperCase()) { - case "AIR": - case "CAVE_AIR": - case "VOID_AIR": - case "SNOW": - continue; + if (state.getBlockType().getMaterial().isAir() || state.getBlockType() == BlockTypes.SNOW) { + continue; } if (isTreeBlock(state.getBlockType())) { queue.addLast(next); @@ -156,4 +151,4 @@ public class FloatingTreeRemover implements BlockTool { return visited; } -} \ No newline at end of file +}