From 0afae082c201268b52de7816e484878ac8c3c032 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 6 Apr 2019 03:34:11 +1100 Subject: [PATCH] Remove string switches for BlockType --- .../voxelsniper/brush/OverlayBrush.java | 14 +- .../com/boydti/fawe/bukkit/FaweBukkit.java | 19 +- .../fawe/bukkit/wrapper/AsyncBlock.java | 11 +- .../boydti/fawe/jnbt/SchematicStreamer.java | 94 +++---- .../fawe/jnbt/anvil/HeightMapMCADrawer.java | 18 +- .../jnbt/anvil/HeightMapMCAGenerator.java | 45 ++-- .../fawe/jnbt/anvil/generator/CavesGen.java | 22 +- .../java/com/sk89q/worldedit/EditSession.java | 26 +- .../worldedit/command/BrushCommands.java | 8 +- .../SignCompatibilityHandler.java | 9 +- .../function/generator/ForestGenerator.java | 37 +-- .../worldedit/world/block/BlockTypeUtil.java | 234 +++++++++--------- 12 files changed, 293 insertions(+), 244 deletions(-) diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java index e8a3b9ea7..749da9714 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/brush/OverlayBrush.java @@ -1,6 +1,7 @@ package com.thevoxelbox.voxelsniper.brush; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.BlockMaterial; @@ -70,12 +71,15 @@ public class OverlayBrush extends PerformBrush { @SuppressWarnings("deprecation") private boolean isIgnoredBlock(int materialId) { BlockType type = BlockTypes.get(materialId); - String s = type.getResource().toUpperCase(); - if (type == BlockTypes.WATER || type == BlockTypes.LAVA || type == BlockTypes.CACTUS) { - return true; + switch (type.getInternalId()) { + case BlockID.WATER: + case BlockID.LAVA: + case BlockID.CACTUS: + return true; + default: + BlockMaterial mat = type.getMaterial(); + return mat.isTranslucent(); } - BlockMaterial mat = type.getMaterial(); - return mat.isTranslucent(); } @SuppressWarnings("deprecation") private boolean isOverrideableMaterial(int materialId) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index 550a1fe8e..d758a8b64 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -3,8 +3,21 @@ package com.boydti.fawe.bukkit; import com.boydti.fawe.Fawe; import com.boydti.fawe.IFawe; import com.boydti.fawe.bukkit.chat.BukkitChatManager; -import com.boydti.fawe.bukkit.listener.*; -import com.boydti.fawe.bukkit.regions.*; +import com.boydti.fawe.bukkit.listener.BrushListener; +import com.boydti.fawe.bukkit.listener.BukkitImageListener; +import com.boydti.fawe.bukkit.listener.CFIPacketListener; +import com.boydti.fawe.bukkit.listener.RenderListener; +import com.boydti.fawe.bukkit.regions.ASkyBlockHook; +import com.boydti.fawe.bukkit.regions.FactionsFeature; +import com.boydti.fawe.bukkit.regions.FactionsOneFeature; +import com.boydti.fawe.bukkit.regions.FactionsUUIDFeature; +import com.boydti.fawe.bukkit.regions.FreeBuildRegion; +import com.boydti.fawe.bukkit.regions.GriefPreventionFeature; +import com.boydti.fawe.bukkit.regions.PreciousStonesFeature; +import com.boydti.fawe.bukkit.regions.ResidenceFeature; +import com.boydti.fawe.bukkit.regions.TownyFeature; +import com.boydti.fawe.bukkit.regions.Worldguard; +import com.boydti.fawe.bukkit.regions.WorldguardFlag; import com.boydti.fawe.bukkit.util.BukkitReflectionUtils; import com.boydti.fawe.bukkit.util.BukkitTaskMan; import com.boydti.fawe.bukkit.util.ItemUtil; @@ -40,7 +53,6 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; import java.io.File; import java.io.FileOutputStream; @@ -48,7 +60,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.UUID; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java index 604c656b0..c23ee06d0 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java @@ -10,6 +10,7 @@ import java.util.List; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -219,11 +220,13 @@ public class AsyncBlock implements Block { public AsyncBlockState getState() { int combined = queue.getCombinedId4Data(x, y, z, 0); BlockType type = BlockTypes.getFromStateId(combined); - String s = type.getResource().toUpperCase(); - if (type == BlockTypes.SIGN || type == BlockTypes.WALL_SIGN) { - return new AsyncSign(this, combined); + switch (type.getInternalId()) { + case BlockID.SIGN: + case BlockID.WALL_SIGN: + return new AsyncSign(this, combined); + default: + return new AsyncBlockState(this, combined); } - return new AsyncBlockState(this, combined); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java index f5c14a526..2b8297c42 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java @@ -197,24 +197,24 @@ public class SchematicStreamer extends NBTStreamer { @Override public > void run(int x, int y, int z, B block) { BlockType type = block.getBlockType(); - switch (type.getResource().toUpperCase()) { - case "ACACIA_STAIRS": - case "BIRCH_STAIRS": - case "BRICK_STAIRS": - case "COBBLESTONE_STAIRS": - case "DARK_OAK_STAIRS": - case "DARK_PRISMARINE_STAIRS": - case "JUNGLE_STAIRS": - case "NETHER_BRICK_STAIRS": - case "OAK_STAIRS": - case "PRISMARINE_BRICK_STAIRS": - case "PRISMARINE_STAIRS": - case "PURPUR_STAIRS": - case "QUARTZ_STAIRS": - case "RED_SANDSTONE_STAIRS": - case "SANDSTONE_STAIRS": - case "SPRUCE_STAIRS": - case "STONE_BRICK_STAIRS": + switch (type.getInternalId()) { + case BlockID.ACACIA_STAIRS: + case BlockID.BIRCH_STAIRS: + case BlockID.BRICK_STAIRS: + case BlockID.COBBLESTONE_STAIRS: + case BlockID.DARK_OAK_STAIRS: + case BlockID.DARK_PRISMARINE_STAIRS: + case BlockID.JUNGLE_STAIRS: + case BlockID.NETHER_BRICK_STAIRS: + case BlockID.OAK_STAIRS: + case BlockID.PRISMARINE_BRICK_STAIRS: + case BlockID.PRISMARINE_STAIRS: + case BlockID.PURPUR_STAIRS: + case BlockID.QUARTZ_STAIRS: + case BlockID.RED_SANDSTONE_STAIRS: + case BlockID.SANDSTONE_STAIRS: + case BlockID.SPRUCE_STAIRS: + case BlockID.STONE_BRICK_STAIRS: Object half = block.getState(PropertyKey.HALF); Direction facing = block.getState(PropertyKey.FACING); @@ -301,38 +301,38 @@ public class SchematicStreamer extends NBTStreamer { } private int group(BlockType type) { - switch (type.getResource().toUpperCase()) { - case "ACACIA_FENCE": - case "BIRCH_FENCE": - case "DARK_OAK_FENCE": - case "JUNGLE_FENCE": - case "OAK_FENCE": - case "SPRUCE_FENCE": + switch (type.getInternalId()) { + case BlockID.ACACIA_FENCE: + case BlockID.BIRCH_FENCE: + case BlockID.DARK_OAK_FENCE: + case BlockID.JUNGLE_FENCE: + case BlockID.OAK_FENCE: + case BlockID.SPRUCE_FENCE: return 0; - case "NETHER_BRICK_FENCE": + case BlockID.NETHER_BRICK_FENCE: return 1; - case "COBBLESTONE_WALL": - case "MOSSY_COBBLESTONE_WALL": + case BlockID.COBBLESTONE_WALL: + case BlockID.MOSSY_COBBLESTONE_WALL: return 2; - case "IRON_BARS": - case "BLACK_STAINED_GLASS_PANE": - case "BLUE_STAINED_GLASS_PANE": - case "BROWN_MUSHROOM_BLOCK": - case "BROWN_STAINED_GLASS_PANE": - case "CYAN_STAINED_GLASS_PANE": - case "GLASS_PANE": - case "GRAY_STAINED_GLASS_PANE": - case "GREEN_STAINED_GLASS_PANE": - case "LIGHT_BLUE_STAINED_GLASS_PANE": - case "LIGHT_GRAY_STAINED_GLASS_PANE": - case "LIME_STAINED_GLASS_PANE": - case "MAGENTA_STAINED_GLASS_PANE": - case "ORANGE_STAINED_GLASS_PANE": - case "PINK_STAINED_GLASS_PANE": - case "PURPLE_STAINED_GLASS_PANE": - case "RED_STAINED_GLASS_PANE": - case "WHITE_STAINED_GLASS_PANE": - case "YELLOW_STAINED_GLASS_PANE": + case BlockID.IRON_BARS: + case BlockID.BLACK_STAINED_GLASS_PANE: + case BlockID.BLUE_STAINED_GLASS_PANE: + case BlockID.BROWN_MUSHROOM_BLOCK: + case BlockID.BROWN_STAINED_GLASS_PANE: + case BlockID.CYAN_STAINED_GLASS_PANE: + case BlockID.GLASS_PANE: + case BlockID.GRAY_STAINED_GLASS_PANE: + case BlockID.GREEN_STAINED_GLASS_PANE: + case BlockID.LIGHT_BLUE_STAINED_GLASS_PANE: + case BlockID.LIGHT_GRAY_STAINED_GLASS_PANE: + case BlockID.LIME_STAINED_GLASS_PANE: + case BlockID.MAGENTA_STAINED_GLASS_PANE: + case BlockID.ORANGE_STAINED_GLASS_PANE: + case BlockID.PINK_STAINED_GLASS_PANE: + case BlockID.PURPLE_STAINED_GLASS_PANE: + case BlockID.RED_STAINED_GLASS_PANE: + case BlockID.WHITE_STAINED_GLASS_PANE: + case BlockID.YELLOW_STAINED_GLASS_PANE: return 3; default: return -1; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCADrawer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCADrawer.java index 4e79230d7..22f1bdd5e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCADrawer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCADrawer.java @@ -4,6 +4,7 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.TextureUtil; +import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -82,13 +83,16 @@ public final class HeightMapMCADrawer { int waterId = gen.primtives.waterId; int waterColor = 0; BlockType waterType = BlockTypes.get(waterId); - String s = waterType.getResource().toUpperCase(); - if (waterType == BlockTypes.WATER) { - color = tu.averageColor((0x11 << 16) + (0x66 << 8) + (0xCC), color); - } else if (waterType == BlockTypes.LAVA) { - color = (0xCC << 16) + (0x33 << 8) + (0); - } else { - color = tu.getColor(waterType); + switch (waterType.getInternalId()) { + case BlockID.WATER: + color = tu.averageColor((0x11 << 16) + (0x66 << 8) + (0xCC), color); + break; + case BlockID.LAVA: + color = (0xCC << 16) + (0x33 << 8) + (0); + break; + default: + color = tu.getColor(waterType); + break; } } raw[index] = color; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java index 4f40c6ae0..8f6bf65fb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java @@ -17,6 +17,7 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.*; import com.sk89q.worldedit.math.MutableBlockVector3; import com.sk89q.worldedit.world.biome.BiomeTypes; +import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -446,16 +447,20 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr private final void setLayerHeight(int index, int blockHeight, int layerHeight) { int floorState = floor.get()[index]; BlockType type = BlockTypes.getFromStateId(floorState); - if (type == BlockTypes.SNOW || type == BlockTypes.SNOW_BLOCK) { - if (layerHeight != 0) { - this.heights.setByte(index, (byte) (blockHeight + 1)); - this.floor.setInt(index, (BlockTypes.SNOW.getInternalId() + layerHeight)); - } else { + switch (type.getInternalId()) { + case BlockID.SNOW: + case BlockID.SNOW_BLOCK: + if (layerHeight != 0) { + this.heights.setByte(index, (byte) (blockHeight + 1)); + this.floor.setInt(index, (BlockTypes.SNOW.getInternalId() + layerHeight)); + } else { + this.heights.setByte(index, (byte) (blockHeight)); + this.floor.setInt(index, (BlockTypes.SNOW_BLOCK.getInternalId())); + } + break; + default: this.heights.setByte(index, (byte) (blockHeight)); - this.floor.setInt(index, (BlockTypes.SNOW_BLOCK.getInternalId())); - } - } else { - this.heights.setByte(index, (byte) (blockHeight)); + break; } } @@ -468,16 +473,20 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr private final void setLayerHeightRaw(int index, int blockHeight, int layerHeight) { int floorState = floor.get()[index]; BlockType type = BlockTypes.getFromStateId(floorState); - if (type == BlockTypes.SNOW || type == BlockTypes.SNOW_BLOCK) { - if (layerHeight != 0) { - this.heights.getByteArray()[index] = (byte) (blockHeight + 1); - this.floor.getIntArray()[index] = (BlockTypes.SNOW.getInternalId() + layerHeight); - } else { + switch (type.getInternalId()) { + case BlockID.SNOW: + case BlockID.SNOW_BLOCK: + if (layerHeight != 0) { + this.heights.getByteArray()[index] = (byte) (blockHeight + 1); + this.floor.getIntArray()[index] = (BlockTypes.SNOW.getInternalId() + layerHeight); + } else { + this.heights.getByteArray()[index] = (byte) (blockHeight); + this.floor.getIntArray()[index] = (BlockTypes.SNOW_BLOCK.getInternalId()); + } + break; + default: this.heights.getByteArray()[index] = (byte) (blockHeight); - this.floor.getIntArray()[index] = (BlockTypes.SNOW_BLOCK.getInternalId()); - } - } else { - this.heights.getByteArray()[index] = (byte) (blockHeight); + break; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/CavesGen.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/CavesGen.java index 3d87e2f07..76cbdb05f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/CavesGen.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/CavesGen.java @@ -5,6 +5,7 @@ import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -176,8 +177,11 @@ public class CavesGen extends GenBase { BlockStateHolder material = chunk.getLazyBlock(bx + local_x, local_y, bz + local_z); BlockStateHolder materialAbove = chunk.getLazyBlock(bx + local_x, local_y + 1, bz + local_z); BlockType blockType = material.getBlockType(); - if (blockType == BlockTypes.MYCELIUM || blockType == BlockTypes.GRASS) { - grassFound = true; + switch (blockType.getInternalId()) { + case BlockID.MYCELIUM: + case BlockID.GRASS: + grassFound = true; + } if (this.isSuitableBlock(material, materialAbove)) { if (local_y - 1 < 10) { @@ -206,13 +210,13 @@ public class CavesGen extends GenBase { } protected boolean isSuitableBlock(BlockStateHolder material, BlockStateHolder materialAbove) { - switch (material.getBlockType().getResource().toUpperCase()) { - case "AIR": - case "CAVE_AIR": - case "VOID_AIR": - case "WATER": - case "LAVA": - case "BEDROCK": + switch (material.getBlockType().getInternalId()) { + case BlockID.AIR: + case BlockID.CAVE_AIR: + case BlockID.VOID_AIR: + case BlockID.WATER: + case BlockID.LAVA: + case BlockID.BEDROCK: return false; default: return true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index d71e2e42e..ee865680e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2731,13 +2731,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, loop: for (int y = maxY; y >= 1; --y) { BlockType block = getBlockType(x, y, z); - switch (block.getResource().toUpperCase()) { - // TODO onlyNormalDirt - case "DIRT": + switch (block.getInternalId()) { + case BlockID.DIRT: this.setBlock(x, y, z, BlockTypes.GRASS_BLOCK.getDefaultState()); break loop; - case "WATER": - case "LAVA": + case BlockID.WATER: + case BlockID.LAVA: break loop; default: if (block.getMaterial().isMovementBlocker()) { @@ -2812,14 +2811,15 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, this.changes++; for (int y = basePosition.getBlockY(); y >= (basePosition.getBlockY() - 10); --y) { BlockType type = getBlockType(x, y, z); - String s = type.getResource().toUpperCase(); - if (type == BlockTypes.GRASS || type == BlockTypes.DIRT) { - treeType.generate(this, BlockVector3.at(x, y + 1, z)); - this.changes++; - } else if (type == BlockTypes.SNOW) { - setBlock(BlockVector3.at(x, y, z), BlockTypes.AIR.getDefaultState()); - } else if (type.getMaterial().isAir()) { - continue; + switch (type.getInternalId()) { + case BlockID.GRASS: + case BlockID.DIRT: + treeType.generate(this, BlockVector3.at(x, y + 1, z)); + this.changes++; + break; + case BlockID.SNOW: + setBlock(BlockVector3.at(x, y, z), BlockTypes.AIR.getDefaultState()); + break; } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 5d9139ae5..ea7d83b2b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -311,9 +311,11 @@ public class BrushCommands extends BrushProcessor { } else { if (fill instanceof BlockStateHolder) { BlockType type = ((BlockStateHolder) fill).getBlockType(); - if (type == BlockTypes.SAND || type == BlockTypes.GRAVEL) { - BBC.BRUSH_TRY_OTHER.send(player); - falling = true; + switch (type.getInternalId()) { + case BlockID.SAND: + case BlockID.GRAVEL: + BBC.BRUSH_TRY_OTHER.send(player); + falling = true; } } if (falling) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java index af78a4d36..791b46495 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/legacycompat/SignCompatibilityHandler.java @@ -26,6 +26,7 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSyntaxException; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; +import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -36,7 +37,13 @@ public class SignCompatibilityHandler implements NBTCompatibilityHandler { @Override public > boolean isAffectedBlock(B block) { - return block.getBlockType() == BlockTypes.SIGN || block.getBlockType() == BlockTypes.WALL_SIGN; + switch (block.getBlockType().getInternalId()) { + case BlockID.SIGN: + case BlockID.WALL_SIGN: + return true; + default: + return false; + } } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java index f6ddf7086..ea2c71a96 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java @@ -24,6 +24,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.TreeGenerator; +import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -52,22 +53,26 @@ public class ForestGenerator implements RegionFunction { public boolean apply(BlockVector3 position) throws WorldEditException { BlockState block = editSession.getBlock(position); BlockType t = block.getBlockType(); - - if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) { - treeType.generate(editSession, position.add(0, 1, 0)); - return true; - } else if (t == BlockTypes.TALL_GRASS || t == BlockTypes.DEAD_BUSH || t == BlockTypes.POPPY || t == BlockTypes.DANDELION) { // TODO: This list needs to be moved - editSession.setBlock(position, BlockTypes.AIR.getDefaultState()); - // and then trick the generator here by directly setting into the world - editSession.getWorld().setBlock(position, BlockTypes.AIR.getDefaultState()); - // so that now the generator can generate the tree - boolean success = treeType.generate(editSession, position); - if (!success) { - editSession.setBlock(position, block); // restore on failure - } - return success; - } else { // Trees won't grow on this! - return false; + switch (t.getInternalId()) { + case BlockID.GRASS_BLOCK: + case BlockID.DIRT: + treeType.generate(editSession, position.add(0, 1, 0)); + return true; + case BlockID.TALL_GRASS: // TODO: This list needs to be moved + case BlockID.DEAD_BUSH: + case BlockID.POPPY: + case BlockID.DANDELION: + editSession.setBlock(position, BlockTypes.AIR.getDefaultState()); + // and then trick the generator here by directly setting into the world + editSession.getWorld().setBlock(position, BlockTypes.AIR.getDefaultState()); + // so that now the generator can generate the tree + boolean success = treeType.generate(editSession, position); + if (!success) { + editSession.setBlock(position, block); // restore on failure + } + return success; + default: // Trees won't grow on this! + return false; } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeUtil.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeUtil.java index 864a53bcb..3c85aae3f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeUtil.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypeUtil.java @@ -36,30 +36,30 @@ public class BlockTypeUtil { public static double centralBottomLimit(BlockStateHolder block) { checkNotNull(block); BlockType type = block.getBlockType(); - switch (type.getResource().toUpperCase()) { - case "CREEPER_WALL_HEAD": - case "DRAGON_WALL_HEAD": - case "PLAYER_WALL_HEAD": - case "ZOMBIE_WALL_HEAD": return 0.25; - case "ACACIA_SLAB": - case "BIRCH_SLAB": - case "BRICK_SLAB": - case "COBBLESTONE_SLAB": - case "DARK_OAK_SLAB": - case "DARK_PRISMARINE_SLAB": - case "JUNGLE_SLAB": - case "NETHER_BRICK_SLAB": - case "OAK_SLAB": - case "PETRIFIED_OAK_SLAB": - case "PRISMARINE_BRICK_SLAB": - case "PRISMARINE_SLAB": - case "PURPUR_SLAB": - case "QUARTZ_SLAB": - case "RED_SANDSTONE_SLAB": - case "SANDSTONE_SLAB": - case "SPRUCE_SLAB": - case "STONE_BRICK_SLAB": - case "STONE_SLAB": { + switch (type.getInternalId()) { + case BlockID.CREEPER_WALL_HEAD: + case BlockID.DRAGON_WALL_HEAD: + case BlockID.PLAYER_WALL_HEAD: + case BlockID.ZOMBIE_WALL_HEAD: return 0.25; + case BlockID.ACACIA_SLAB: + case BlockID.BIRCH_SLAB: + case BlockID.BRICK_SLAB: + case BlockID.COBBLESTONE_SLAB: + case BlockID.DARK_OAK_SLAB: + case BlockID.DARK_PRISMARINE_SLAB: + case BlockID.JUNGLE_SLAB: + case BlockID.NETHER_BRICK_SLAB: + case BlockID.OAK_SLAB: + case BlockID.PETRIFIED_OAK_SLAB: + case BlockID.PRISMARINE_BRICK_SLAB: + case BlockID.PRISMARINE_SLAB: + case BlockID.PURPUR_SLAB: + case BlockID.QUARTZ_SLAB: + case BlockID.RED_SANDSTONE_SLAB: + case BlockID.SANDSTONE_SLAB: + case BlockID.SPRUCE_SLAB: + case BlockID.STONE_BRICK_SLAB: + case BlockID.STONE_SLAB: { String state = (String) block.getState(PropertyKey.TYPE); if (state == null) return 0; switch (state) { @@ -70,13 +70,13 @@ public class BlockTypeUtil { return 0.5; } } - case "ACACIA_TRAPDOOR": - case "BIRCH_TRAPDOOR": - case "DARK_OAK_TRAPDOOR": - case "IRON_TRAPDOOR": - case "JUNGLE_TRAPDOOR": - case "OAK_TRAPDOOR": - case "SPRUCE_TRAPDOOR": + case BlockID.ACACIA_TRAPDOOR: + case BlockID.BIRCH_TRAPDOOR: + case BlockID.DARK_OAK_TRAPDOOR: + case BlockID.IRON_TRAPDOOR: + case BlockID.JUNGLE_TRAPDOOR: + case BlockID.OAK_TRAPDOOR: + case BlockID.SPRUCE_TRAPDOOR: if (block.getState(PropertyKey.OPEN) == Boolean.TRUE) { return 1; } else if ("bottom".equals(block.getState(PropertyKey.HALF))) { @@ -84,12 +84,12 @@ public class BlockTypeUtil { } else { return 0; } - case "ACACIA_FENCE_GATE": - case "BIRCH_FENCE_GATE": - case "DARK_OAK_FENCE_GATE": - case "JUNGLE_FENCE_GATE": - case "OAK_FENCE_GATE": - case "SPRUCE_FENCE_GATE": return block.getState(PropertyKey.OPEN) == Boolean.TRUE ? 1 : 0; + case BlockID.ACACIA_FENCE_GATE: + case BlockID.BIRCH_FENCE_GATE: + case BlockID.DARK_OAK_FENCE_GATE: + case BlockID.JUNGLE_FENCE_GATE: + case BlockID.OAK_FENCE_GATE: + case BlockID.SPRUCE_FENCE_GATE: return block.getState(PropertyKey.OPEN) == Boolean.TRUE ? 1 : 0; default: if (type.getMaterial().isMovementBlocker()) return 0; return 1; @@ -105,64 +105,64 @@ public class BlockTypeUtil { public static double centralTopLimit(BlockStateHolder block) { checkNotNull(block); BlockType type = block.getBlockType(); - switch (type.getResource().toUpperCase()) { - case "BLACK_BED": - case "BLUE_BED": - case "BROWN_BED": - case "CYAN_BED": - case "GRAY_BED": - case "GREEN_BED": - case "LIGHT_BLUE_BED": - case "LIGHT_GRAY_BED": - case "LIME_BED": - case "MAGENTA_BED": - case "ORANGE_BED": - case "PINK_BED": - case "PURPLE_BED": - case "RED_BED": - case "WHITE_BED": - case "YELLOW_BED": return 0.5625; - case "BREWING_STAND": return 0.875; - case "CAKE": return (block.getState(PropertyKey.BITES) == (Integer) 6) ? 0 : 0.4375; - case "CAULDRON": return 0.3125; - case "COCOA": return 0.750; - case "ENCHANTING_TABLE": return 0.75; - case "END_PORTAL_FRAME": return block.getState(PropertyKey.EYE) == Boolean.TRUE ? 1 : 0.8125; - case "CREEPER_HEAD": - case "DRAGON_HEAD": - case "PISTON_HEAD": - case "PLAYER_HEAD": - case "ZOMBIE_HEAD": return 0.5; - case "CREEPER_WALL_HEAD": - case "DRAGON_WALL_HEAD": - case "PLAYER_WALL_HEAD": - case "ZOMBIE_WALL_HEAD": return 0.75; - case "ACACIA_FENCE": - case "BIRCH_FENCE": - case "DARK_OAK_FENCE": - case "JUNGLE_FENCE": - case "NETHER_BRICK_FENCE": - case "OAK_FENCE": - case "SPRUCE_FENCE": return 1.5; - case "ACACIA_SLAB": - case "BIRCH_SLAB": - case "BRICK_SLAB": - case "COBBLESTONE_SLAB": - case "DARK_OAK_SLAB": - case "DARK_PRISMARINE_SLAB": - case "JUNGLE_SLAB": - case "NETHER_BRICK_SLAB": - case "OAK_SLAB": - case "PETRIFIED_OAK_SLAB": - case "PRISMARINE_BRICK_SLAB": - case "PRISMARINE_SLAB": - case "PURPUR_SLAB": - case "QUARTZ_SLAB": - case "RED_SANDSTONE_SLAB": - case "SANDSTONE_SLAB": - case "SPRUCE_SLAB": - case "STONE_BRICK_SLAB": - case "STONE_SLAB": { + switch (type.getInternalId()) { + case BlockID.BLACK_BED: + case BlockID.BLUE_BED: + case BlockID.BROWN_BED: + case BlockID.CYAN_BED: + case BlockID.GRAY_BED: + case BlockID.GREEN_BED: + case BlockID.LIGHT_BLUE_BED: + case BlockID.LIGHT_GRAY_BED: + case BlockID.LIME_BED: + case BlockID.MAGENTA_BED: + case BlockID.ORANGE_BED: + case BlockID.PINK_BED: + case BlockID.PURPLE_BED: + case BlockID.RED_BED: + case BlockID.WHITE_BED: + case BlockID.YELLOW_BED: return 0.5625; + case BlockID.BREWING_STAND: return 0.875; + case BlockID.CAKE: return (block.getState(PropertyKey.BITES) == (Integer) 6) ? 0 : 0.4375; + case BlockID.CAULDRON: return 0.3125; + case BlockID.COCOA: return 0.750; + case BlockID.ENCHANTING_TABLE: return 0.75; + case BlockID.END_PORTAL_FRAME: return block.getState(PropertyKey.EYE) == Boolean.TRUE ? 1 : 0.8125; + case BlockID.CREEPER_HEAD: + case BlockID.DRAGON_HEAD: + case BlockID.PISTON_HEAD: + case BlockID.PLAYER_HEAD: + case BlockID.ZOMBIE_HEAD: return 0.5; + case BlockID.CREEPER_WALL_HEAD: + case BlockID.DRAGON_WALL_HEAD: + case BlockID.PLAYER_WALL_HEAD: + case BlockID.ZOMBIE_WALL_HEAD: return 0.75; + case BlockID.ACACIA_FENCE: + case BlockID.BIRCH_FENCE: + case BlockID.DARK_OAK_FENCE: + case BlockID.JUNGLE_FENCE: + case BlockID.NETHER_BRICK_FENCE: + case BlockID.OAK_FENCE: + case BlockID.SPRUCE_FENCE: return 1.5; + case BlockID.ACACIA_SLAB: + case BlockID.BIRCH_SLAB: + case BlockID.BRICK_SLAB: + case BlockID.COBBLESTONE_SLAB: + case BlockID.DARK_OAK_SLAB: + case BlockID.DARK_PRISMARINE_SLAB: + case BlockID.JUNGLE_SLAB: + case BlockID.NETHER_BRICK_SLAB: + case BlockID.OAK_SLAB: + case BlockID.PETRIFIED_OAK_SLAB: + case BlockID.PRISMARINE_BRICK_SLAB: + case BlockID.PRISMARINE_SLAB: + case BlockID.PURPUR_SLAB: + case BlockID.QUARTZ_SLAB: + case BlockID.RED_SANDSTONE_SLAB: + case BlockID.SANDSTONE_SLAB: + case BlockID.SPRUCE_SLAB: + case BlockID.STONE_BRICK_SLAB: + case BlockID.STONE_SLAB: { String state = (String) block.getState(PropertyKey.TYPE); if (state == null) return 0.5; switch (state) { @@ -173,22 +173,22 @@ public class BlockTypeUtil { return 1; } } - case "LILY_PAD": return 0.015625; - case "REPEATER": return 0.125; - case "SOUL_SAND": return 0.875; - case "COBBLESTONE_WALL": - case "MOSSY_COBBLESTONE_WALL": return 1.5; - case "FLOWER_POT": return 0.375; - case "COMPARATOR": return 0.125; - case "DAYLIGHT_DETECTOR": return 0.375; - case "HOPPER": return 0.625; - case "ACACIA_TRAPDOOR": - case "BIRCH_TRAPDOOR": - case "DARK_OAK_TRAPDOOR": - case "IRON_TRAPDOOR": - case "JUNGLE_TRAPDOOR": - case "OAK_TRAPDOOR": - case "SPRUCE_TRAPDOOR": + case BlockID.LILY_PAD: return 0.015625; + case BlockID.REPEATER: return 0.125; + case BlockID.SOUL_SAND: return 0.875; + case BlockID.COBBLESTONE_WALL: + case BlockID.MOSSY_COBBLESTONE_WALL: return 1.5; + case BlockID.FLOWER_POT: return 0.375; + case BlockID.COMPARATOR: return 0.125; + case BlockID.DAYLIGHT_DETECTOR: return 0.375; + case BlockID.HOPPER: return 0.625; + case BlockID.ACACIA_TRAPDOOR: + case BlockID.BIRCH_TRAPDOOR: + case BlockID.DARK_OAK_TRAPDOOR: + case BlockID.IRON_TRAPDOOR: + case BlockID.JUNGLE_TRAPDOOR: + case BlockID.OAK_TRAPDOOR: + case BlockID.SPRUCE_TRAPDOOR: if (block.getState(PropertyKey.OPEN) == Boolean.TRUE) { return 0; } else if ("top".equals(block.getState(PropertyKey.HALF))) { @@ -196,12 +196,12 @@ public class BlockTypeUtil { } else { return 0.1875; } - case "ACACIA_FENCE_GATE": - case "BIRCH_FENCE_GATE": - case "DARK_OAK_FENCE_GATE": - case "JUNGLE_FENCE_GATE": - case "OAK_FENCE_GATE": - case "SPRUCE_FENCE_GATE": return block.getState(PropertyKey.OPEN) == Boolean.TRUE ? 0 : 1.5; + case BlockID.ACACIA_FENCE_GATE: + case BlockID.BIRCH_FENCE_GATE: + case BlockID.DARK_OAK_FENCE_GATE: + case BlockID.JUNGLE_FENCE_GATE: + case BlockID.OAK_FENCE_GATE: + case BlockID.SPRUCE_FENCE_GATE: return block.getState(PropertyKey.OPEN) == Boolean.TRUE ? 0 : 1.5; default: if (type.hasProperty(PropertyKey.LAYERS)) { return PropertyGroup.LEVEL.get(block) * 0.0625;