From 57c13ef8f4b3e5aa77b0dd455a36fb6e98d7804c Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Mon, 2 Jul 2018 13:45:46 +1000 Subject: [PATCH] Continue moving out of legacy BlockType --- .../sk89q/worldedit/bukkit/BukkitWorld.java | 7 +- .../java/com/sk89q/worldedit/EditSession.java | 2 +- .../com/sk89q/worldedit/blocks/BaseBlock.java | 23 --- .../com/sk89q/worldedit/blocks/BlockID.java | 30 --- .../sk89q/worldedit/blocks/BlockMaterial.java | 13 ++ .../com/sk89q/worldedit/blocks/BlockType.java | 180 ------------------ .../validation/DataValidatorExtent.java | 1 - .../extent/world/BlockQuirkExtent.java | 13 +- .../extent/world/SurvivalModeExtent.java | 5 +- .../shape/WorldEditExpressionEnvironment.java | 6 +- .../com/sk89q/worldedit/util/TargetBlock.java | 3 +- .../sk89q/worldedit/world/AbstractWorld.java | 7 +- .../world/registry/SimpleBlockMaterial.java | 20 ++ .../com/sk89q/worldedit/forge/ForgeWorld.java | 15 +- 14 files changed, 57 insertions(+), 268 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 56654dc07..cf98f41d9 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -379,9 +379,7 @@ public class BukkitWorld extends AbstractWorld { @Override public LazyBlock getLazyBlock(Vector position) { - World world = getWorld(); - Block bukkitBlock = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); - return new LazyBlock(bukkitBlock.getTypeId(), bukkitBlock.getData(), this, position); + return new LazyBlock(getBlock(position), this, position); } @Override @@ -390,8 +388,7 @@ public class BukkitWorld extends AbstractWorld { if (adapter != null) { return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)); } else { - Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); - return new BaseBlock(bukkitBlock.getTypeId(), bukkitBlock.getData()); + return new BaseBlock(getBlock(position)); } } 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 5f733b086..d69a558ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -1529,7 +1529,7 @@ public class EditSession implements Extent { } // Snow should not cover these blocks - if (BlockType.isTranslucent(id.getLegacyId())) { + if (id.getMaterial().isTranslucent()) { // Add snow on leaves if (BlockCategories.LEAVES.contains(id)) { break; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java index 00a2832d4..df35b3043 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java @@ -114,19 +114,6 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { this(id); } - /** - * 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, which may be null - */ - @Deprecated - public BaseBlock(int id, int data, @Nullable CompoundTag nbtData) { - this(id); - this.nbtData = nbtData; - } - /** * Create a clone of another block. * @@ -136,16 +123,6 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { this(other.toImmutableState(), other.getNbtData()); } - /** - * Get the legacy numerical ID of the block. - * - * @return legacy numerical ID - */ - @Deprecated - public int getId() { - return this.blockState.getBlockType().getLegacyId(); - } - /** * Get the block's data value. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockID.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockID.java index b396728c3..a92eae5f3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockID.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockID.java @@ -32,23 +32,18 @@ public final class BlockID { public static final int DIRT = 3; public static final int SAPLING = 6; public static final int BEDROCK = 7; - public static final int WATER = 8; // FLOWING_WATER - public static final int STATIONARY_WATER = 9; // WATER public static final int SAND = 12; public static final int GRAVEL = 13; public static final int GOLD_ORE = 14; public static final int IRON_ORE = 15; public static final int COAL_ORE = 16; public static final int LOG = 17; - public static final int LEAVES = 18; - public static final int GLASS = 20; public static final int LAPIS_LAZULI_ORE = 21; // LAPIS_ORE public static final int DISPENSER = 23; public static final int BED = 26; public static final int POWERED_RAIL = 27; // GOLDEN_RAIL public static final int DETECTOR_RAIL = 28; public static final int PISTON_STICKY_BASE = 29; // STICKY_PISTON - public static final int WEB = 30; public static final int LONG_GRASS = 31; // TALLGRASS public static final int DEAD_BUSH = 32; // DEADBUSH public static final int PISTON_BASE = 33; // PISTON @@ -62,7 +57,6 @@ public final class BlockID { public static final int TNT = 46; public static final int TORCH = 50; public static final int FIRE = 51; - public static final int MOB_SPAWNER = 52; @Deprecated public static final int WOODEN_STAIRS = 53; public static final int OAK_WOOD_STAIRS = 53; // OAK_STAIRS @@ -88,7 +82,6 @@ public final class BlockID { public static final int REDSTONE_TORCH_ON = 76; // LIT_REDSTONE_TORCH public static final int STONE_BUTTON = 77; public static final int SNOW = 78; // SNOW_LAYER - public static final int ICE = 79; public static final int CACTUS = 81; public static final int CLAY = 82; public static final int REED = 83; // REEDS @@ -109,8 +102,6 @@ public final class BlockID { public static final int TRAP_DOOR = 96; // TRAPDOOR public static final int BROWN_MUSHROOM_CAP = 99; // BROWN_MUSHROOM_BLOCK public static final int RED_MUSHROOM_CAP = 100; // RED_MUSHROOM_BLOCK - public static final int IRON_BARS = 101; - public static final int GLASS_PANE = 102; public static final int PUMPKIN_STEM = 104; public static final int MELON_STEM = 105; public static final int VINE = 106; @@ -119,7 +110,6 @@ public final class BlockID { public static final int STONE_BRICK_STAIRS = 109; public static final int MYCELIUM = 110; public static final int LILY_PAD = 111; // WATERLILY - public static final int NETHER_BRICK_FENCE = 113; public static final int NETHER_BRICK_STAIRS = 114; public static final int NETHER_WART = 115; public static final int ENCHANTMENT_TABLE = 116; // ENCHANTING_TABLE @@ -155,12 +145,9 @@ public final class BlockID { public static final int ACTIVATOR_RAIL = 157; public static final int DROPPER = 158; public static final int STAINED_CLAY = 159; // STAINED_HARDENED_CLAY - public static final int STAINED_GLASS_PANE = 160; - public static final int LEAVES2 = 161; public static final int LOG2 = 162; public static final int ACACIA_STAIRS = 163; public static final int DARK_OAK_STAIRS = 164; - public static final int BARRIER = 166; public static final int IRON_TRAP_DOOR = 167; public static final int HAY_BLOCK = 170; public static final int CARPET = 171; @@ -169,29 +156,12 @@ public final class BlockID { public static final int STANDING_BANNER = 176; public static final int WALL_BANNER = 177; public static final int DAYLIGHT_SENSOR_INVERTED = 178; - public static final int RED_SANDSTONE_STAIRS = 180; public static final int STEP2 = 182; - public static final int SPRUCE_FENCE_GATE = 183; - public static final int BIRCH_FENCE_GATE = 184; - public static final int JUNGLE_FENCE_GATE = 185; - public static final int DARK_OAK_FENCE_GATE = 186; - public static final int ACACIA_FENCE_GATE = 187; - public static final int SPRUCE_FENCE = 188; - public static final int BIRCH_FENCE = 189; - public static final int JUNGLE_FENCE = 190; - public static final int DARK_OAK_FENCE = 191; - public static final int ACACIA_FENCE = 192; public static final int SPRUCE_DOOR = 193; public static final int BIRCH_DOOR = 194; public static final int JUNGLE_DOOR = 195; public static final int ACACIA_DOOR = 196; public static final int DARK_OAK_DOOR = 197; - public static final int END_ROD = 198; - public static final int CHORUS_PLANT = 199; - public static final int CHORUS_FLOWER = 200; - public static final int PURPUR_STAIRS = 203; - public static final int PURPUR_SLAB = 205; - public static final int BEETROOTS = 207; private BlockID() { } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockMaterial.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockMaterial.java index bf9e3abb0..c894136da 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockMaterial.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockMaterial.java @@ -180,4 +180,17 @@ public interface BlockMaterial { */ boolean isReplacedDuringPlacement(); + /** + * Get whether this block is translucent. + * + * @return true if the block is translucent + */ + boolean isTranslucent(); + + /** + * Gets whether the block has a container (Item container) + * + * @return If it has a container + */ + boolean hasContainer(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java index 44ccf731c..a01569bcf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java @@ -232,32 +232,6 @@ public enum BlockType { return centralTopLimit(block.getBlockType().getLegacyId(), 0); } - /** - * HashSet for isContainerBlock. - */ - private static final Set isContainerBlock = new HashSet<>(); - static { - isContainerBlock.add(BlockID.DISPENSER); - isContainerBlock.add(BlockID.FURNACE); - isContainerBlock.add(BlockID.BURNING_FURNACE); - isContainerBlock.add(BlockID.CHEST); - isContainerBlock.add(BlockID.BREWING_STAND); - isContainerBlock.add(BlockID.TRAPPED_CHEST); - isContainerBlock.add(BlockID.HOPPER); - isContainerBlock.add(BlockID.DROPPER); - //isContainerBlock.add(BlockID.ENDER_CHEST); // ender chest has no own inventory, don't add this here - } - - /** - * Returns true if the block is a container block. - * - * @param id the block ID - * @return true if the block is a container - */ - public static boolean isContainerBlock(int id) { - return isContainerBlock.contains(id); - } - /** * HashSet for isNaturalBlock. */ @@ -292,18 +266,6 @@ public enum BlockType { isNaturalTerrainBlock.add(BlockID.EMERALD_ORE); } - /** - * Checks if the block type is naturally occurring. - * - * @param id the type ID of the block - * @return true if the block type is naturally occurring - * @deprecated Use {@link #isNaturalTerrainBlock(int, int)} - */ - @Deprecated - public static boolean isNaturalTerrainBlock(int id) { - return isNaturalTerrainBlock.contains(id); - } - /** * Checks if the block type is naturally occurring * @@ -315,148 +277,6 @@ public enum BlockType { return isNaturalTerrainBlock.contains(-16*id-data) || isNaturalTerrainBlock.contains(id); } - /** - * HashSet for isTranslucent. - */ - private static final Set isTranslucent = new HashSet<>(); - static { - isTranslucent.add(BlockID.AIR); - isTranslucent.add(BlockID.SAPLING); - isTranslucent.add(BlockID.WATER); - isTranslucent.add(BlockID.STATIONARY_WATER); - isTranslucent.add(BlockID.LEAVES); - isTranslucent.add(BlockID.GLASS); - isTranslucent.add(BlockID.BED); - isTranslucent.add(BlockID.POWERED_RAIL); - isTranslucent.add(BlockID.DETECTOR_RAIL); - //isTranslucent.add(BlockID.PISTON_STICKY_BASE); - isTranslucent.add(BlockID.WEB); - isTranslucent.add(BlockID.LONG_GRASS); - isTranslucent.add(BlockID.DEAD_BUSH); - //isTranslucent.add(BlockID.PISTON_BASE); - isTranslucent.add(BlockID.PISTON_EXTENSION); - //isTranslucent.add(BlockID.PISTON_MOVING_PIECE); - isTranslucent.add(BlockID.YELLOW_FLOWER); - isTranslucent.add(BlockID.RED_FLOWER); - isTranslucent.add(BlockID.BROWN_MUSHROOM); - isTranslucent.add(BlockID.RED_MUSHROOM); - isTranslucent.add(BlockID.STEP); - isTranslucent.add(BlockID.TORCH); - isTranslucent.add(BlockID.FIRE); - isTranslucent.add(BlockID.MOB_SPAWNER); - isTranslucent.add(BlockID.OAK_WOOD_STAIRS); - isTranslucent.add(BlockID.CHEST); - isTranslucent.add(BlockID.REDSTONE_WIRE); - isTranslucent.add(BlockID.CROPS); - isTranslucent.add(BlockID.SIGN_POST); - isTranslucent.add(BlockID.WOODEN_DOOR); - isTranslucent.add(BlockID.LADDER); - isTranslucent.add(BlockID.MINECART_TRACKS); - isTranslucent.add(BlockID.COBBLESTONE_STAIRS); - isTranslucent.add(BlockID.WALL_SIGN); - isTranslucent.add(BlockID.LEVER); - isTranslucent.add(BlockID.STONE_PRESSURE_PLATE); - isTranslucent.add(BlockID.IRON_DOOR); - isTranslucent.add(BlockID.WOODEN_PRESSURE_PLATE); - isTranslucent.add(BlockID.REDSTONE_TORCH_OFF); - isTranslucent.add(BlockID.REDSTONE_TORCH_ON); - isTranslucent.add(BlockID.STONE_BUTTON); - isTranslucent.add(BlockID.SNOW); - isTranslucent.add(BlockID.ICE); - isTranslucent.add(BlockID.CACTUS); - isTranslucent.add(BlockID.REED); - isTranslucent.add(BlockID.FENCE); - isTranslucent.add(BlockID.PORTAL); - isTranslucent.add(BlockID.CAKE_BLOCK); - isTranslucent.add(BlockID.REDSTONE_REPEATER_OFF); - isTranslucent.add(BlockID.REDSTONE_REPEATER_ON); - isTranslucent.add(BlockID.TRAP_DOOR); - isTranslucent.add(BlockID.IRON_BARS); - isTranslucent.add(BlockID.GLASS_PANE); - isTranslucent.add(BlockID.PUMPKIN_STEM); - isTranslucent.add(BlockID.MELON_STEM); - isTranslucent.add(BlockID.VINE); - isTranslucent.add(BlockID.FENCE_GATE); - isTranslucent.add(BlockID.BRICK_STAIRS); - isTranslucent.add(BlockID.STONE_BRICK_STAIRS); - isTranslucent.add(BlockID.LILY_PAD); - isTranslucent.add(BlockID.NETHER_BRICK_FENCE); - isTranslucent.add(BlockID.NETHER_BRICK_STAIRS); - isTranslucent.add(BlockID.NETHER_WART); - isTranslucent.add(BlockID.ENCHANTMENT_TABLE); - isTranslucent.add(BlockID.BREWING_STAND); - isTranslucent.add(BlockID.CAULDRON); - isTranslucent.add(BlockID.WOODEN_STEP); - isTranslucent.add(BlockID.COCOA_PLANT); - isTranslucent.add(BlockID.SANDSTONE_STAIRS); - isTranslucent.add(BlockID.ENDER_CHEST); - isTranslucent.add(BlockID.TRIPWIRE_HOOK); - isTranslucent.add(BlockID.TRIPWIRE); - isTranslucent.add(BlockID.SPRUCE_WOOD_STAIRS); - isTranslucent.add(BlockID.BIRCH_WOOD_STAIRS); - isTranslucent.add(BlockID.JUNGLE_WOOD_STAIRS); - isTranslucent.add(BlockID.COBBLESTONE_WALL); - isTranslucent.add(BlockID.FLOWER_POT); - isTranslucent.add(BlockID.CARROTS); - isTranslucent.add(BlockID.POTATOES); - isTranslucent.add(BlockID.WOODEN_BUTTON); - isTranslucent.add(BlockID.HEAD); - isTranslucent.add(BlockID.ANVIL); - isTranslucent.add(BlockID.TRAPPED_CHEST); - isTranslucent.add(BlockID.PRESSURE_PLATE_LIGHT); - isTranslucent.add(BlockID.PRESSURE_PLATE_HEAVY); - isTranslucent.add(BlockID.COMPARATOR_OFF); - isTranslucent.add(BlockID.COMPARATOR_ON); - isTranslucent.add(BlockID.DAYLIGHT_SENSOR); - isTranslucent.add(BlockID.HOPPER); - isTranslucent.add(BlockID.QUARTZ_STAIRS); - isTranslucent.add(BlockID.ACTIVATOR_RAIL); - isTranslucent.add(BlockID.ACACIA_STAIRS); - isTranslucent.add(BlockID.DARK_OAK_STAIRS); - isTranslucent.add(BlockID.BARRIER); - isTranslucent.add(BlockID.IRON_TRAP_DOOR); - isTranslucent.add(BlockID.CARPET); - isTranslucent.add(BlockID.LEAVES2); - isTranslucent.add(BlockID.STAINED_GLASS_PANE); - isTranslucent.add(BlockID.DOUBLE_PLANT); - isTranslucent.add(BlockID.STANDING_BANNER); - isTranslucent.add(BlockID.WALL_BANNER); - isTranslucent.add(BlockID.DAYLIGHT_SENSOR_INVERTED); - isTranslucent.add(BlockID.RED_SANDSTONE_STAIRS); - isTranslucent.add(BlockID.STEP2); - isTranslucent.add(BlockID.SPRUCE_FENCE_GATE); - isTranslucent.add(BlockID.BIRCH_FENCE_GATE); - isTranslucent.add(BlockID.JUNGLE_FENCE_GATE); - isTranslucent.add(BlockID.DARK_OAK_FENCE_GATE); - isTranslucent.add(BlockID.ACACIA_FENCE_GATE); - isTranslucent.add(BlockID.SPRUCE_FENCE); - isTranslucent.add(BlockID.BIRCH_FENCE); - isTranslucent.add(BlockID.JUNGLE_FENCE); - isTranslucent.add(BlockID.DARK_OAK_FENCE); - isTranslucent.add(BlockID.ACACIA_FENCE); - isTranslucent.add(BlockID.SPRUCE_DOOR); - isTranslucent.add(BlockID.BIRCH_DOOR); - isTranslucent.add(BlockID.JUNGLE_DOOR); - isTranslucent.add(BlockID.ACACIA_DOOR); - isTranslucent.add(BlockID.DARK_OAK_DOOR); - isTranslucent.add(BlockID.END_ROD); - isTranslucent.add(BlockID.CHORUS_PLANT); - isTranslucent.add(BlockID.CHORUS_FLOWER); - isTranslucent.add(BlockID.PURPUR_STAIRS); - isTranslucent.add(BlockID.PURPUR_SLAB); - isTranslucent.add(BlockID.BEETROOTS); - } - - /** - * Checks if the block type lets light through. - * - * @param id the type ID of the block - * @return true if the block type lets light through - */ - public static boolean isTranslucent(int id) { - return isTranslucent.contains(id); - } - private static final Map dataAttachments = new HashMap<>(); private static final Map nonDataAttachments = new HashMap<>(); static { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/DataValidatorExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/DataValidatorExtent.java index 8356ef15e..3fcd53287 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/DataValidatorExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/DataValidatorExtent.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.extent.validation; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.type.BlockStateHolder; import com.sk89q.worldedit.blocks.type.BlockType; import com.sk89q.worldedit.extent.AbstractDelegateExtent; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/BlockQuirkExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/BlockQuirkExtent.java index 9f306fc5d..254dbbf34 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/BlockQuirkExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/BlockQuirkExtent.java @@ -19,19 +19,17 @@ package com.sk89q.worldedit.extent.world; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.blocks.BlockID; -import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.blocks.type.BlockStateHolder; +import com.sk89q.worldedit.blocks.type.BlockType; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.world.World; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Handles various quirks when setting blocks, such as ice turning * into water or containers dropping their contents. @@ -54,10 +52,9 @@ public class BlockQuirkExtent extends AbstractDelegateExtent { @Override public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { - BaseBlock lazyBlock = getExtent().getLazyBlock(position); - com.sk89q.worldedit.blocks.type.BlockType existing = lazyBlock.getBlockType(); + BlockType existing = getExtent().getBlock(position).getBlockType(); - if (BlockType.isContainerBlock(existing.getLegacyId())) { + if (existing.getMaterial().hasContainer()) { world.clearContainerBlockContents(position); // Clear the container block so that it doesn't drop items } else if (existing == BlockTypes.ICE) { world.setBlock(position, BlockTypes.AIR.getDefaultState()); // Ice turns until water so this has to be done first diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java index 3090cb972..68878d352 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java @@ -19,17 +19,16 @@ package com.sk89q.worldedit.extent.world; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.type.BlockStateHolder; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.world.World; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Makes changes to the world as if a player had done so during survival mode. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java index 8dffdba77..6f5cb958a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java @@ -48,7 +48,7 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment { @Override public int getBlockType(double x, double y, double z) { - return editSession.getLazyBlock(toWorld(x, y, z)).getId(); + return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId(); } @Override @@ -58,7 +58,7 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment { @Override public int getBlockTypeAbs(double x, double y, double z) { - return editSession.getLazyBlock(new Vector(x, y, z)).getId(); + return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId(); } @Override @@ -68,7 +68,7 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment { @Override public int getBlockTypeRel(double x, double y, double z) { - return editSession.getLazyBlock(toWorldRel(x, y, z)).getId(); + return editSession.getBlock(toWorld(x, y, z)).getBlockType().getLegacyId(); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java index 8caecc3f2..f37229886 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java @@ -19,8 +19,7 @@ package com.sk89q.worldedit.util; -import com.sk89q.worldedit.*; -import com.sk89q.worldedit.blocks.BlockType; +import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.world.World; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java index ce5b6fc8d..aa01cd230 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java @@ -26,6 +26,7 @@ import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.type.BlockState; import com.sk89q.worldedit.blocks.type.BlockStateHolder; +import com.sk89q.worldedit.blocks.type.BlockType; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.function.mask.BlockMask; @@ -93,7 +94,7 @@ public abstract class AbstractWorld implements World { } @Override - public boolean queueBlockBreakEffect(Platform server, Vector position, com.sk89q.worldedit.blocks.type.BlockType blockType, double priority) { + public boolean queueBlockBreakEffect(Platform server, Vector position, BlockType blockType, double priority) { if (taskId == -1) { taskId = server.schedule(0, 1, () -> { int max = Math.max(1, Math.min(30, effectQueue.size() / 3)); @@ -131,10 +132,10 @@ public abstract class AbstractWorld implements World { private class QueuedEffect implements Comparable { private final Vector position; - private final com.sk89q.worldedit.blocks.type.BlockType blockType; + private final BlockType blockType; private final double priority; - private QueuedEffect(Vector position, com.sk89q.worldedit.blocks.type.BlockType blockType, double priority) { + private QueuedEffect(Vector position, BlockType blockType, double priority) { this.position = position; this.blockType = blockType; this.priority = priority; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleBlockMaterial.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleBlockMaterial.java index 7b190c740..9ad54acf6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleBlockMaterial.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleBlockMaterial.java @@ -45,6 +45,8 @@ class SimpleBlockMaterial implements BlockMaterial { private boolean burnable; private boolean toolRequired; private boolean replacedDuringPlacement; + private boolean isTranslucent; + private boolean hasContainer; @Override public boolean isRenderedAsNormalBlock() { @@ -240,7 +242,25 @@ class SimpleBlockMaterial implements BlockMaterial { return replacedDuringPlacement; } + public void setTranslucent(boolean isTranslucent) { + this.isTranslucent = isTranslucent; + } + + @Override + public boolean isTranslucent() { + return this.isTranslucent; + } + public void setReplacedDuringPlacement(boolean replacedDuringPlacement) { this.replacedDuringPlacement = replacedDuringPlacement; } + + @Override + public boolean hasContainer() { + return this.hasContainer; + } + + public void setHasContainer(boolean hasContainer) { + this.hasContainer = hasContainer; + } } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java index 2e30ab7f3..04b900d06 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -35,7 +35,6 @@ import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.LazyBlock; import com.sk89q.worldedit.blocks.type.BlockState; import com.sk89q.worldedit.blocks.type.BlockStateHolder; -import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.blocks.type.ItemTypes; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -47,6 +46,7 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.TreeGenerator.TreeType; import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.biome.BaseBiome; +import com.sk89q.worldedit.world.registry.LegacyMapper; import net.minecraft.block.Block; import net.minecraft.block.BlockLeaves; import net.minecraft.block.BlockOldLeaf; @@ -356,15 +356,12 @@ public class ForgeWorld extends AbstractWorld { BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()); IBlockState state = world.getBlockState(pos); - return BlockTypes.getBlockType(net.minecraftforge.fml.common.registry.ForgeRegistries.BLOCKS.getKey(state.getBlock()).toString()).getDefaultState(); // TODO Data + return LegacyMapper.getInstance().getBlockFromLegacy(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state)); } @Override public LazyBlock getLazyBlock(Vector position) { - World world = getWorld(); - BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()); - IBlockState state = world.getBlockState(pos); - return new LazyBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state), this, position); + return new LazyBlock(getBlock(position), this, position); } @Override @@ -377,7 +374,7 @@ public class ForgeWorld extends AbstractWorld { if (tile != null) { return new TileEntityBaseBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state), tile); } else { - return new BaseBlock(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state)); + return new BaseBlock(getBlock(position)); } } @@ -404,7 +401,7 @@ public class ForgeWorld extends AbstractWorld { @Override public List getEntities(Region region) { - List entities = new ArrayList(); + List entities = new ArrayList<>(); for (net.minecraft.entity.Entity entity : getWorld().loadedEntityList) { if (region.contains(new Vector(entity.posX, entity.posY, entity.posZ))) { entities.add(new ForgeEntity(entity)); @@ -415,7 +412,7 @@ public class ForgeWorld extends AbstractWorld { @Override public List getEntities() { - List entities = new ArrayList(); + List entities = new ArrayList<>(); for (net.minecraft.entity.Entity entity : getWorld().loadedEntityList) { entities.add(new ForgeEntity(entity)); }