From 282eca766367c3ce5f263d98643be17f0f4a74b6 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Tue, 19 Jun 2018 10:53:15 +1000 Subject: [PATCH] Added a category system and refactored registries --- ...itWorldData.java => BukkitRegistries.java} | 10 +- .../bukkit/BukkitServerInterface.java | 9 +- .../sk89q/worldedit/bukkit/BukkitWorld.java | 11 +- .../java/com/sk89q/worldedit/EditSession.java | 12 +- .../com/sk89q/worldedit/blocks/BaseBlock.java | 90 +-------------- .../blocks/type/BlockCategories.java | 108 ++++++++++++++++++ .../worldedit/blocks/type/BlockCategory.java | 70 ++++++++++++ .../worldedit/blocks/type/ItemCategories.java | 102 +++++++++++++++++ .../worldedit/blocks/type/ItemCategory.java | 73 ++++++++++++ .../worldedit/command/BiomeCommands.java | 7 +- .../worldedit/command/ClipboardCommands.java | 6 +- .../command/FlattenedClipboardTransform.java | 18 +-- .../worldedit/command/SchematicCommands.java | 11 +- .../worldedit/command/UtilityCommands.java | 8 +- .../worldedit/command/tool/AreaPickaxe.java | 10 +- .../command/tool/FloatingTreeRemover.java | 24 ++-- .../command/tool/brush/ButcherBrush.java | 2 +- .../command/tool/brush/ClipboardBrush.java | 2 +- .../command/util/CreatureButcher.java | 5 +- .../worldedit/command/util/EntityRemover.java | 10 +- .../extension/factory/DefaultItemParser.java | 4 +- .../extension/factory/DefaultMaskParser.java | 4 +- .../extension/platform/Platform.java | 8 +- .../extent/clipboard/io/ClipboardReader.java | 5 +- .../extent/clipboard/io/ClipboardWriter.java | 4 +- .../extent/clipboard/io/SchematicReader.java | 8 +- .../transform/BlockTransformExtent.java | 23 ++-- .../function/mask/ExistingBlockMask.java | 3 +- .../internal/command/WorldEditBinding.java | 4 +- .../worldedit/session/ClipboardHolder.java | 24 +--- .../sk89q/worldedit/session/PasteBuilder.java | 14 +-- .../com/sk89q/worldedit/world/NullWorld.java | 10 +- .../java/com/sk89q/worldedit/world/World.java | 10 +- .../world/registry/BlockCategoryRegistry.java | 29 +++++ ...dWorldData.java => BundledRegistries.java} | 22 +++- .../world/registry/CategoryRegistry.java | 44 +++++++ .../world/registry/ItemCategoryRegistry.java | 29 +++++ .../registry/NullBlockCategoryRegistry.java | 38 ++++++ .../registry/NullItemCategoryRegistry.java | 38 ++++++ .../{WorldData.java => Registries.java} | 19 ++- .../transform/BlockTransformExtentTest.java | 4 +- .../sk89q/worldedit/forge/ForgePlatform.java | 34 +----- ...rgeWorldData.java => ForgeRegistries.java} | 8 +- .../com/sk89q/worldedit/forge/ForgeWorld.java | 10 +- .../worldedit/sponge/SpongePlatform.java | 29 ++--- ...geWorldData.java => SpongeRegistries.java} | 8 +- .../sk89q/worldedit/sponge/SpongeWorld.java | 10 +- 47 files changed, 715 insertions(+), 316 deletions(-) rename worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/{BukkitWorldData.java => BukkitRegistries.java} (83%) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockCategories.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockCategory.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/ItemCategories.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/ItemCategory.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockCategoryRegistry.java rename worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/{BundledWorldData.java => BundledRegistries.java} (70%) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/CategoryRegistry.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemCategoryRegistry.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBlockCategoryRegistry.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullItemCategoryRegistry.java rename worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/{WorldData.java => Registries.java} (77%) rename worldedit-forge/src/main/java/com/sk89q/worldedit/forge/{ForgeWorldData.java => ForgeRegistries.java} (86%) rename worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/{SpongeWorldData.java => SpongeRegistries.java} (83%) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorldData.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java similarity index 83% rename from worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorldData.java rename to worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java index c6bd94a54..65346d683 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorldData.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java @@ -20,20 +20,20 @@ package com.sk89q.worldedit.bukkit; import com.sk89q.worldedit.world.registry.BiomeRegistry; -import com.sk89q.worldedit.world.registry.BundledWorldData; +import com.sk89q.worldedit.world.registry.BundledRegistries; /** * World data for the Bukkit platform. */ -class BukkitWorldData extends BundledWorldData { +class BukkitRegistries extends BundledRegistries { - private static final BukkitWorldData INSTANCE = new BukkitWorldData(); + private static final BukkitRegistries INSTANCE = new BukkitRegistries(); private final BiomeRegistry biomeRegistry = new BukkitBiomeRegistry(); /** * Create a new instance. */ - BukkitWorldData() { + BukkitRegistries() { } @Override @@ -46,7 +46,7 @@ class BukkitWorldData extends BundledWorldData { * * @return an instance */ - public static BukkitWorldData getInstance() { + public static BukkitRegistries getInstance() { return INSTANCE; } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index 91db498b7..8c125dc9b 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -30,8 +30,8 @@ import com.sk89q.worldedit.extension.platform.Preference; import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.Description; import com.sk89q.worldedit.util.command.Dispatcher; +import com.sk89q.worldedit.world.registry.Registries; import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.World; import org.bukkit.entity.EntityType; @@ -48,13 +48,11 @@ public class BukkitServerInterface implements MultiUserPlatform { public Server server; public WorldEditPlugin plugin; private CommandRegistration dynamicCommands; - private BukkitBiomeRegistry biomes; private boolean hookingEvents; public BukkitServerInterface(WorldEditPlugin plugin, Server server) { this.plugin = plugin; this.server = server; - this.biomes = new BukkitBiomeRegistry(); dynamicCommands = new CommandRegistration(plugin); } @@ -63,9 +61,8 @@ public class BukkitServerInterface implements MultiUserPlatform { } @Override - public int resolveItem(String name) { - Material mat = Material.matchMaterial(name); - return mat == null ? 0 : mat.getId(); + public Registries getRegistries() { + return BukkitRegistries.getInstance(); } @Override 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 df412f695..eac643e49 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 @@ -40,7 +40,7 @@ import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.registry.BundledBlockData; -import com.sk89q.worldedit.world.registry.WorldData; +import com.sk89q.worldedit.world.registry.Registries; import org.bukkit.Effect; import org.bukkit.TreeType; import org.bukkit.World; @@ -354,11 +354,6 @@ public class BukkitWorld extends AbstractWorld { return true; } - @Override - public WorldData getWorldData() { - return BukkitWorldData.getInstance(); - } - @Override public void simulateBlockMine(Vector pt) { getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).breakNaturally(); @@ -367,7 +362,9 @@ public class BukkitWorld extends AbstractWorld { @Override public com.sk89q.worldedit.blocks.type.BlockState getBlock(Vector position) { Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); - BlockType blockType = BlockTypes.getBlockType(BundledBlockData.getInstance().fromLegacyId(bukkitBlock.getTypeId())); + BlockType blockType = BlockTypes.getBlockType( + BundledBlockData.getInstance().fromLegacyId(bukkitBlock.getTypeId()) + ); return blockType.getDefaultState(); // TODO Data } 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 4287db4ff..543cda5a3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2165,12 +2165,12 @@ public class EditSession implements Extent { } private static final Vector[] recurseDirections = { - PlayerDirection.NORTH.vector(), - PlayerDirection.EAST.vector(), - PlayerDirection.SOUTH.vector(), - PlayerDirection.WEST.vector(), - PlayerDirection.UP.vector(), - PlayerDirection.DOWN.vector(), + Direction.NORTH.toVector(), + Direction.EAST.toVector(), + Direction.SOUTH.toVector(), + Direction.WEST.toVector(), + Direction.UP.toVector(), + Direction.DOWN.toVector(), }; private static double lengthSq(double x, double y, double z) { 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 9c5d227a7..45db309f8 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 @@ -22,7 +22,6 @@ package com.sk89q.worldedit.blocks; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.CuboidClipboard.FlipDirection; import com.sk89q.worldedit.blocks.type.BlockState; import com.sk89q.worldedit.blocks.type.BlockStateHolder; import com.sk89q.worldedit.blocks.type.BlockType; @@ -102,7 +101,7 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { */ public BaseBlock(BlockState state, @Nullable CompoundTag nbtData) { this.blockState = state; - setNbtData(nbtData); + this.nbtData = nbtData; } /** @@ -126,7 +125,7 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { @Deprecated public BaseBlock(int id, int data, @Nullable CompoundTag nbtData) { this(id); - setNbtData(nbtData); + this.nbtData = nbtData; } /** @@ -174,6 +173,7 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { * * @return The state map */ + @Override public Map getStates() { return this.blockState.getStates(); } @@ -194,19 +194,11 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { * @param state The state to get the value for * @return The state value */ + @Override public StateValue getState(State state) { return this.blockState.getState(state); } - /** - * Set the block's data value. - * - * @param data block data value - */ - @Deprecated - public void setData(int data) { - } - @Override public boolean hasNbtData() { return getNbtData() != null; @@ -237,80 +229,6 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { throw new UnsupportedOperationException("This class is immutable."); } - /** - * Returns true if it's air. - * - * @return if air - */ - public boolean isAir() { - return getBlockType() == BlockTypes.AIR; - } - - /** - * Rotate this block 90 degrees. - * - * @return new data value - * @deprecated Use {@link BlockData#rotate90(int, int)} - */ - @Deprecated - public int rotate90() { - int newData = BlockData.rotate90(getBlockType().getLegacyId(), getData()); - setData(newData); - return newData; - } - - /** - * Rotate this block -90 degrees. - * - * @return new data value - * @deprecated Use {@link BlockData#rotate90Reverse(int, int)} - */ - @Deprecated - public int rotate90Reverse() { - int newData = BlockData.rotate90Reverse(getBlockType().getLegacyId(), getData()); - setData((short) newData); - return newData; - } - - /** - * Cycle the damage value of the block forward or backward - * - * @param increment 1 for forward, -1 for backward - * @return new data value - * @deprecated Use {@link BlockData#cycle(int, int, int)} - */ - @Deprecated - public int cycleData(int increment) { - int newData = BlockData.cycle(getBlockType().getLegacyId(), getData(), increment); - setData((short) newData); - return newData; - } - - /** - * Flip this block. - * - * @return this block - * @deprecated Use {@link BlockData#flip(int, int)} - */ - @Deprecated - public BaseBlock flip() { - setData((short) BlockData.flip(getBlockType().getLegacyId(), getData())); - return this; - } - - /** - * Flip this block. - * - * @param direction direction to flip in - * @return this block - * @deprecated Use {@link BlockData#flip(int, int, FlipDirection)} - */ - @Deprecated - public BaseBlock flip(FlipDirection direction) { - setData((short) BlockData.flip(getBlockType().getLegacyId(), getData(), direction)); - return this; - } - /** * Checks whether the type ID and data value are equal. */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockCategories.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockCategories.java new file mode 100644 index 000000000..25b324cc0 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockCategories.java @@ -0,0 +1,108 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.blocks.type; + +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Nullable; + +/** + * Stores a list of categories of Block Types. + */ +public class BlockCategories { + + private BlockCategories() { + } + + public static final BlockCategory ACACIA_LOGS = new BlockCategory("minecraft:acacia_logs"); + public static final BlockCategory ANVIL = new BlockCategory("minecraft:anvil"); + public static final BlockCategory BANNERS = new BlockCategory("minecraft:banners"); + public static final BlockCategory BIRCH_LOGS = new BlockCategory("minecraft:birch_logs"); + public static final BlockCategory BUTTONS = new BlockCategory("minecraft:buttons"); + public static final BlockCategory CARPETS = new BlockCategory("minecraft:carpets"); + public static final BlockCategory CORAL = new BlockCategory("minecraft:coral"); + public static final BlockCategory CORAL_PLANTS = new BlockCategory("minecraft:coral_plants"); + public static final BlockCategory DARK_OAK_LOGS = new BlockCategory("minecraft:dark_oak_logs"); + public static final BlockCategory DOORS = new BlockCategory("minecraft:doors"); + public static final BlockCategory ENDERMAN_HOLDABLE = new BlockCategory("minecraft:enderman_holdable"); + public static final BlockCategory FLOWER_POTS = new BlockCategory("minecraft:flower_pots"); + public static final BlockCategory ICE = new BlockCategory("minecraft:ice"); + public static final BlockCategory JUNGLE_LOGS = new BlockCategory("minecraft:jungle_logs"); + public static final BlockCategory LEAVES = new BlockCategory("minecraft:leaves"); + public static final BlockCategory LOGS = new BlockCategory("minecraft:logs"); + public static final BlockCategory OAK_LOGS = new BlockCategory("minecraft:oak_logs"); + public static final BlockCategory PLANKS = new BlockCategory("minecraft:planks"); + public static final BlockCategory RAILS = new BlockCategory("minecraft:rails"); + public static final BlockCategory SAND = new BlockCategory("minecraft:sand"); + public static final BlockCategory SAPLINGS = new BlockCategory("minecraft:saplings"); + public static final BlockCategory SLABS = new BlockCategory("minecraft:slabs"); + public static final BlockCategory SPRUCE_LOGS = new BlockCategory("minecraft:spruce_logs"); + public static final BlockCategory STAIRS = new BlockCategory("minecraft:stairs"); + public static final BlockCategory STONE_BRICKS = new BlockCategory("minecraft:stone_bricks"); + public static final BlockCategory VALID_SPAWN = new BlockCategory("minecraft:valid_spawn"); + public static final BlockCategory WOODEN_BUTTONS = new BlockCategory("minecraft:wooden_buttons"); + public static final BlockCategory WOODEN_DOORS = new BlockCategory("minecraft:wooden_doors"); + public static final BlockCategory WOODEN_PRESSURE_PLATES = new BlockCategory("minecraft:wooden_pressure_plates"); + public static final BlockCategory WOODEN_SLABS = new BlockCategory("minecraft:wooden_slabs"); + public static final BlockCategory WOODEN_STAIRS = new BlockCategory("minecraft:wooden_stairs"); + public static final BlockCategory WOOL = new BlockCategory("minecraft:wool"); + + // Fluids + public static final BlockCategory LAVA = new BlockCategory("minecraft:lava"); + public static final BlockCategory WATER = new BlockCategory("minecraft:water"); + + private static final Map categoryMapping = new HashMap<>(); + + static { + for (Field field : BlockCategories.class.getFields()) { + if (field.getType() == BlockCategory.class) { + try { + registerCategory((BlockCategory) field.get(null)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + } + + public static void registerCategory(BlockCategory blockCategory) { + if (categoryMapping.containsKey(blockCategory.getId()) && !blockCategory.getId().startsWith("minecraft:")) { + throw new IllegalArgumentException("Existing category with this ID already registered"); + } + + categoryMapping.put(blockCategory.getId(), blockCategory); + } + + @Nullable + public static BlockCategory getBlockType(String id) { + // If it has no namespace, assume minecraft. + if (id != null && !id.contains(":")) { + id = "minecraft:" + id; + } + return categoryMapping.get(id); + } + + public static Collection values() { + return categoryMapping.values(); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockCategory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockCategory.java new file mode 100644 index 000000000..ca7831ef9 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockCategory.java @@ -0,0 +1,70 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.blocks.type; + +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Capability; + +import java.util.Set; + +/** + * A category of blocks. This is due to the splitting up of + * blocks such as wool into separate ids. + */ +public class BlockCategory { + + private final String id; + + public BlockCategory(String id) { + this.id = id; + } + + public String getId() { + return this.id; + } + + public Set getBlockTypes() { + return WorldEdit.getInstance().getPlatformManager() + .queryCapability(Capability.GAME_HOOKS).getRegistries() + .getBlockCategoryRegistry().getCategorisedByName(this.id); + } + + /** + * Checks whether the BlocKType is contained within + * this category. + * + * @param blockType The blocktype + * @return If it's a part of this category + */ + public boolean contains(BlockType blockType) { + return getBlockTypes().contains(blockType); + } + + /** + * Checks whether the BlockStateHolder is contained within + * this category. + * + * @param blockStateHolder The blockstateholder + * @return If it's a part of this category + */ + public boolean contains(BlockStateHolder blockStateHolder) { + return getBlockTypes().contains(blockStateHolder.getBlockType()); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/ItemCategories.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/ItemCategories.java new file mode 100644 index 000000000..2a6a35a70 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/ItemCategories.java @@ -0,0 +1,102 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.blocks.type; + +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Nullable; + +/** + * Stores a list of categories of Item Types. + */ +public class ItemCategories { + + private ItemCategories() { + } + + public static final ItemCategory ACACIA_LOGS = new ItemCategory("minecraft:acacia_logs"); + public static final ItemCategory ANVIL = new ItemCategory("minecraft:anvil"); + public static final ItemCategory BANNERS = new ItemCategory("minecraft:banners"); + public static final ItemCategory BIRCH_LOGS = new ItemCategory("minecraft:birch_logs"); + public static final ItemCategory BOATS = new ItemCategory("minecraft:boats"); + public static final ItemCategory BUTTONS = new ItemCategory("minecraft:buttons"); + public static final ItemCategory CARPETS = new ItemCategory("minecraft:carpets"); + public static final ItemCategory CORAL = new ItemCategory("minecraft:coral"); + public static final ItemCategory CORAL_PLANTS = new ItemCategory("minecraft:coral_plants"); + public static final ItemCategory DARK_OAK_LOGS = new ItemCategory("minecraft:dark_oak_logs"); + public static final ItemCategory DOORS = new ItemCategory("minecraft:doors"); + public static final ItemCategory FISHES = new ItemCategory("minecraft:fishes"); + public static final ItemCategory JUNGLE_LOGS = new ItemCategory("minecraft:jungle_logs"); + public static final ItemCategory LEAVES = new ItemCategory("minecraft:leaves"); + public static final ItemCategory LOGS = new ItemCategory("minecraft:logs"); + public static final ItemCategory OAK_LOGS = new ItemCategory("minecraft:oak_logs"); + public static final ItemCategory PLANKS = new ItemCategory("minecraft:planks"); + public static final ItemCategory RAILS = new ItemCategory("minecraft:rails"); + public static final ItemCategory SAND = new ItemCategory("minecraft:sand"); + public static final ItemCategory SAPLINGS = new ItemCategory("minecraft:saplings"); + public static final ItemCategory SLABS = new ItemCategory("minecraft:slabs"); + public static final ItemCategory SPRUCE_LOGS = new ItemCategory("minecraft:spruce_logs"); + public static final ItemCategory STAIRS = new ItemCategory("minecraft:stairs"); + public static final ItemCategory STONE_BRICKS = new ItemCategory("minecraft:stone_bricks"); + public static final ItemCategory WOODEN_BUTTONS = new ItemCategory("minecraft:wooden_buttons"); + public static final ItemCategory WOODEN_DOORS = new ItemCategory("minecraft:wooden_doors"); + public static final ItemCategory WOODEN_PRESSURE_PLATES = new ItemCategory("minecraft:wooden_pressure_plates"); + public static final ItemCategory WOODEN_SLABS = new ItemCategory("minecraft:wooden_slabs"); + public static final ItemCategory WOODEN_STAIRS = new ItemCategory("minecraft:wooden_stairs"); + public static final ItemCategory WOOL = new ItemCategory("minecraft:wool"); + + private static final Map categoryMapping = new HashMap<>(); + + static { + for (Field field : ItemCategories.class.getFields()) { + if (field.getType() == ItemCategory.class) { + try { + registerCategory((ItemCategory) field.get(null)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + } + + public static void registerCategory(ItemCategory itemCategory) { + if (categoryMapping.containsKey(itemCategory.getId()) && !itemCategory.getId().startsWith("minecraft:")) { + throw new IllegalArgumentException("Existing category with this ID already registered"); + } + + categoryMapping.put(itemCategory.getId(), itemCategory); + } + + @Nullable + public static ItemCategory getBlockType(String id) { + // If it has no namespace, assume minecraft. + if (id != null && !id.contains(":")) { + id = "minecraft:" + id; + } + return categoryMapping.get(id); + } + + public static Collection values() { + return categoryMapping.values(); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/ItemCategory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/ItemCategory.java new file mode 100644 index 000000000..6784be079 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/ItemCategory.java @@ -0,0 +1,73 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.blocks.type; + +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.blocks.BaseItem; +import com.sk89q.worldedit.extension.platform.Capability; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * A category of items. This is due to the splitting up of + * items such as wool into separate ids. + */ +public class ItemCategory { + + private final String id; + + public ItemCategory(String id) { + this.id = id; + } + + public String getId() { + return this.id; + } + + public Set getItemTypes() { + return WorldEdit.getInstance().getPlatformManager() + .queryCapability(Capability.GAME_HOOKS).getRegistries() + .getItemCategoryRegistry().getCategorisedByName(this.id); + } + + /** + * Checks whether the ItemType is contained within + * this category. + * + * @param itemType The itemType + * @return If it's a part of this category + */ + public boolean contains(ItemType itemType) { + return getItemTypes().contains(itemType); + } + + /** + * Checks whether the BaseItem is contained within + * this category. + * + * @param baseItem The item + * @return If it's a part of this category + */ + public boolean contains(BaseItem baseItem) { + return getItemTypes().contains(baseItem.getType()); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java index fdf4a39f5..94cd303ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java @@ -30,6 +30,7 @@ import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.function.FlatRegionFunction; import com.sk89q.worldedit.function.FlatRegionMaskingFilter; import com.sk89q.worldedit.function.biome.BiomeReplace; @@ -91,7 +92,8 @@ public class BiomeCommands { offset = (page - 1) * 19; } - BiomeRegistry biomeRegistry = player.getWorld().getWorldData().getBiomeRegistry(); + BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() + .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); List biomes = biomeRegistry.getBiomes(); int totalPages = biomes.size() / 19 + 1; player.print("Available Biomes (page " + page + "/" + totalPages + ") :"); @@ -125,7 +127,8 @@ public class BiomeCommands { ) @CommandPermissions("worldedit.biome.info") public void biomeInfo(Player player, LocalSession session, CommandContext args) throws WorldEditException { - BiomeRegistry biomeRegistry = player.getWorld().getWorldData().getBiomeRegistry(); + BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() + .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); Set biomes = new HashSet<>(); String qualifier; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 9d7cb265a..3feca48b5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -89,7 +89,7 @@ public class ClipboardCommands { copy.setSourceMask(mask); } Operations.completeLegacy(copy); - session.setClipboard(new ClipboardHolder(clipboard, editSession.getWorld().getWorldData())); + session.setClipboard(new ClipboardHolder(clipboard)); player.print(region.getArea() + " block(s) were copied."); } @@ -122,7 +122,7 @@ public class ClipboardCommands { copy.setSourceMask(mask); } Operations.completeLegacy(copy); - session.setClipboard(new ClipboardHolder(clipboard, editSession.getWorld().getWorldData())); + session.setClipboard(new ClipboardHolder(clipboard)); player.print(region.getArea() + " block(s) were copied."); } @@ -153,7 +153,7 @@ public class ClipboardCommands { Vector to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player); Operation operation = holder - .createPaste(editSession, editSession.getWorld().getWorldData()) + .createPaste(editSession) .to(to) .ignoreAirBlocks(ignoreAirBlocks) .build(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java index 70adc7803..b15d444d9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.command; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -30,9 +32,6 @@ import com.sk89q.worldedit.math.transform.CombinedTransform; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.world.registry.WorldData; - -import static com.google.common.base.Preconditions.checkNotNull; /** * Helper class to 'bake' a transform into a clipboard. @@ -46,22 +45,18 @@ class FlattenedClipboardTransform { private final Clipboard original; private final Transform transform; - private final WorldData worldData; /** * Create a new instance. * * @param original the original clipboard * @param transform the transform - * @param worldData the world data instance */ - private FlattenedClipboardTransform(Clipboard original, Transform transform, WorldData worldData) { + private FlattenedClipboardTransform(Clipboard original, Transform transform) { checkNotNull(original); checkNotNull(transform); - checkNotNull(worldData); this.original = original; this.transform = transform; - this.worldData = worldData; } /** @@ -122,7 +117,7 @@ class FlattenedClipboardTransform { * @return the operation */ public Operation copyTo(Extent target) { - BlockTransformExtent extent = new BlockTransformExtent(original, transform, worldData.getBlockRegistry()); + BlockTransformExtent extent = new BlockTransformExtent(original, transform); ForwardExtentCopy copy = new ForwardExtentCopy(extent, original.getRegion(), original.getOrigin(), target, original.getOrigin()); copy.setTransform(transform); return copy; @@ -133,11 +128,10 @@ class FlattenedClipboardTransform { * * @param original the original clipboard * @param transform the transform - * @param worldData the world data instance * @return a builder */ - public static FlattenedClipboardTransform transform(Clipboard original, Transform transform, WorldData worldData) { - return new FlattenedClipboardTransform(original, transform, worldData); + public static FlattenedClipboardTransform transform(Clipboard original, Transform transform) { + return new FlattenedClipboardTransform(original, transform); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index 9d14467a6..f3744bcb5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -44,7 +44,7 @@ import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.parametric.Optional; import com.sk89q.worldedit.util.io.Closer; import com.sk89q.worldedit.util.io.file.FilenameException; -import com.sk89q.worldedit.world.registry.WorldData; +import com.sk89q.worldedit.world.registry.Registries; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -111,9 +111,8 @@ public class SchematicCommands { BufferedInputStream bis = closer.register(new BufferedInputStream(fis)); ClipboardReader reader = format.getReader(bis); - WorldData worldData = player.getWorld().getWorldData(); - Clipboard clipboard = reader.read(player.getWorld().getWorldData()); - session.setClipboard(new ClipboardHolder(clipboard, worldData)); + Clipboard clipboard = reader.read(); + session.setClipboard(new ClipboardHolder(clipboard)); log.info(player.getName() + " loaded " + f.getCanonicalPath()); player.print(filename + " loaded. Paste it with //paste"); @@ -150,7 +149,7 @@ public class SchematicCommands { // If we have a transform, bake it into the copy if (!transform.isIdentity()) { - FlattenedClipboardTransform result = FlattenedClipboardTransform.transform(clipboard, transform, holder.getWorldData()); + FlattenedClipboardTransform result = FlattenedClipboardTransform.transform(clipboard, transform); target = new BlockArrayClipboard(result.getTransformedRegion()); target.setOrigin(clipboard.getOrigin()); Operations.completeLegacy(result.copyTo(target)); @@ -170,7 +169,7 @@ public class SchematicCommands { FileOutputStream fos = closer.register(new FileOutputStream(f)); BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos)); ClipboardWriter writer = closer.register(format.getWriter(bos)); - writer.write(target, holder.getWorldData()); + writer.write(target); log.info(player.getName() + " saved " + f.getCanonicalPath()); player.print(filename + " saved."); } catch (IOException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index a46e803da..447e42c7b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -448,12 +448,12 @@ public class UtilityCommands { } else { entities = editSession.getEntities(); } - visitors.add(new EntityVisitor(entities.iterator(), flags.createFunction(editSession.getWorld().getWorldData().getEntityRegistry()))); + visitors.add(new EntityVisitor(entities.iterator(), flags.createFunction())); } else { Platform platform = we.getPlatformManager().queryCapability(Capability.WORLD_EDITING); for (World world : platform.getWorlds()) { List entities = world.getEntities(); - visitors.add(new EntityVisitor(entities.iterator(), flags.createFunction(world.getWorldData().getEntityRegistry()))); + visitors.add(new EntityVisitor(entities.iterator(), flags.createFunction())); } } @@ -508,12 +508,12 @@ public class UtilityCommands { } else { entities = editSession.getEntities(); } - visitors.add(new EntityVisitor(entities.iterator(), remover.createFunction(editSession.getWorld().getWorldData().getEntityRegistry()))); + visitors.add(new EntityVisitor(entities.iterator(), remover.createFunction())); } else { Platform platform = we.getPlatformManager().queryCapability(Capability.WORLD_EDITING); for (World world : platform.getWorlds()) { List entities = world.getEntities(); - visitors.add(new EntityVisitor(entities.iterator(), remover.createFunction(world.getWorldData().getEntityRegistry()))); + visitors.add(new EntityVisitor(entities.iterator(), remover.createFunction())); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java index fef394793..f5bde5bf2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java @@ -19,8 +19,12 @@ package com.sk89q.worldedit.command.tool; -import com.sk89q.worldedit.*; -import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.type.BlockState; import com.sk89q.worldedit.blocks.type.BlockType; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.entity.Player; @@ -33,7 +37,7 @@ import com.sk89q.worldedit.world.World; */ public class AreaPickaxe implements BlockTool { - private static final BaseBlock air = new BaseBlock(BlockTypes.AIR); + private static final BlockState air = BlockTypes.AIR.getDefaultState(); private int range; public AreaPickaxe(int range) { 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 b5ea93730..a6f766bd3 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 @@ -19,13 +19,18 @@ package com.sk89q.worldedit.command.tool; -import com.sk89q.worldedit.*; -import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BlockID; +import com.sk89q.worldedit.blocks.type.BlockState; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; @@ -38,7 +43,7 @@ import java.util.Set; * to anything else) */ public class FloatingTreeRemover implements BlockTool { - private static final BaseBlock AIR = new BaseBlock(BlockTypes.AIR); + private static final BlockState AIR = BlockTypes.AIR.getDefaultState(); private int rangeSq; public FloatingTreeRemover() { @@ -55,6 +60,7 @@ public class FloatingTreeRemover implements BlockTool { Player player, LocalSession session, Location clicked) { final World world = (World) clicked.getExtent(); + final BlockState state = world.getBlock(clicked.toVector()); switch (world.getLazyBlock(clicked.toVector()).getId()) { case BlockID.LOG: @@ -103,12 +109,12 @@ public class FloatingTreeRemover implements BlockTool { } private Vector[] recurseDirections = { - PlayerDirection.NORTH.vector(), - PlayerDirection.EAST.vector(), - PlayerDirection.SOUTH.vector(), - PlayerDirection.WEST.vector(), - PlayerDirection.UP.vector(), - PlayerDirection.DOWN.vector(), + Direction.NORTH.toVector(), + Direction.EAST.toVector(), + Direction.SOUTH.toVector(), + Direction.WEST.toVector(), + Direction.UP.toVector(), + Direction.DOWN.toVector(), }; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ButcherBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ButcherBrush.java index b949d6b0e..175cc32ae 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ButcherBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ButcherBrush.java @@ -43,7 +43,7 @@ public class ButcherBrush implements Brush { public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { CylinderRegion region = CylinderRegion.createRadius(editSession, position, size); List entities = editSession.getEntities(region); - Operations.completeLegacy(new EntityVisitor(entities.iterator(), flags.createFunction(editSession.getWorld().getWorldData().getEntityRegistry()))); + Operations.completeLegacy(new EntityVisitor(entities.iterator(), flags.createFunction())); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ClipboardBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ClipboardBrush.java index 4417d1a35..184480787 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ClipboardBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ClipboardBrush.java @@ -48,7 +48,7 @@ public class ClipboardBrush implements Brush { Vector centerOffset = region.getCenter().subtract(clipboard.getOrigin()); Operation operation = holder - .createPaste(editSession, editSession.getWorld().getWorldData()) + .createPaste(editSession) .to(usingOrigin ? position : position.subtract(centerOffset)) .ignoreAirBlocks(ignoreAirBlocks) .build(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java index 96545811a..c672257f5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/CreatureButcher.java @@ -20,12 +20,9 @@ package com.sk89q.worldedit.command.util; import com.sk89q.minecraft.util.commands.CommandContext; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.metadata.EntityType; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.function.EntityFunction; -import com.sk89q.worldedit.world.registry.EntityRegistry; /** * The implementation of /butcher. @@ -80,7 +77,7 @@ public class CreatureButcher { or(Flags.WITH_LIGHTNING, args.hasFlag('l'), "worldedit.butcher.lightning"); } - public EntityFunction createFunction(final EntityRegistry entityRegistry) { + public EntityFunction createFunction() { return entity -> { boolean killPets = (flags & Flags.PETS) != 0; boolean killNPCs = (flags & Flags.NPCS) != 0; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java index d336eda71..1d8de101a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/EntityRemover.java @@ -19,17 +19,15 @@ package com.sk89q.worldedit.command.util; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.minecraft.util.commands.CommandException; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.metadata.EntityType; import com.sk89q.worldedit.function.EntityFunction; -import com.sk89q.worldedit.world.registry.EntityRegistry; -import javax.annotation.Nullable; import java.util.regex.Pattern; -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nullable; /** * The implementation of /remove. @@ -138,7 +136,7 @@ public class EntityRemover { } } - public EntityFunction createFunction(final EntityRegistry entityRegistry) { + public EntityFunction createFunction() { final Type type = this.type; checkNotNull(type, "type can't be null"); return entity -> { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultItemParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultItemParser.java index b146382e9..d39356cbe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultItemParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultItemParser.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.internal.registry.InputParser; public class DefaultItemParser extends InputParser { @@ -33,7 +34,8 @@ public class DefaultItemParser extends InputParser { @Override public BaseItem parseFromInput(String input, ParserContext context) throws InputParseException { - BaseItem item = context.requireWorld().getWorldData().getItemRegistry().createFromId(input); + BaseItem item = WorldEdit.getInstance().getPlatformManager() + .queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().createFromId(input); if (item == null) { throw new InputParseException("'" + input + "' did not match any item"); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java index bdba0c924..cf0565739 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java @@ -25,6 +25,7 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.BiomeMask2D; import com.sk89q.worldedit.function.mask.BlockMask; @@ -128,7 +129,8 @@ class DefaultMaskParser extends InputParser { case '$': Set biomes = new HashSet<>(); String[] biomesList = component.substring(1).split(","); - BiomeRegistry biomeRegistry = context.requireWorld().getWorldData().getBiomeRegistry(); + BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() + .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); List knownBiomes = biomeRegistry.getBiomes(); for (String biomeName : biomesList) { BaseBiome biome = Biomes.findBiomeByName(knownBiomes, biomeName, biomeRegistry); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java index 03d4812a9..517c98e93 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Platform.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.world.registry.Registries; import javax.annotation.Nullable; import java.util.List; @@ -37,12 +38,11 @@ import java.util.Map; public interface Platform { /** - * Resolves an item name to its ID. + * Gets the registry holder. * - * @param name The name to look up - * @return The id that corresponds to the name, or -1 if no such ID exists + * @return The registry holder */ - int resolveItem(String name); + Registries getRegistries(); /** * Checks if a mob type is valid. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardReader.java index ccb74ee5b..40808d755 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardReader.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.extent.clipboard.io; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.world.registry.WorldData; +import com.sk89q.worldedit.world.registry.Registries; import java.io.IOException; @@ -34,10 +34,9 @@ public interface ClipboardReader { /** * Read a {@code Clipboard}. * - * @param data the world data space to convert the blocks to * @return the read clipboard * @throws IOException thrown on I/O error */ - Clipboard read(WorldData data) throws IOException; + Clipboard read() throws IOException; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardWriter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardWriter.java index 9f5dc307b..1407f579e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardWriter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardWriter.java @@ -20,7 +20,6 @@ package com.sk89q.worldedit.extent.clipboard.io; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.world.registry.WorldData; import java.io.Closeable; import java.io.IOException; @@ -36,9 +35,8 @@ public interface ClipboardWriter extends Closeable { * Writes a clipboard. * * @param clipboard the clipboard - * @param data the world data instance * @throws IOException thrown on I/O error */ - void write(Clipboard clipboard, WorldData data) throws IOException; + void write(Clipboard clipboard) throws IOException; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java index 92f05f9d9..29f2b3a1a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.extent.clipboard.io; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.jnbt.ByteArrayTag; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; @@ -40,10 +42,8 @@ import com.sk89q.worldedit.extent.clipboard.io.legacycompat.SignCompatibilityHan import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.world.registry.WorldData; import com.sk89q.worldedit.world.storage.NBTConversions; -import javax.annotation.Nullable; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -52,7 +52,7 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import static com.google.common.base.Preconditions.checkNotNull; +import javax.annotation.Nullable; /** * Reads schematic files based that are compatible with MCEdit and other editors. @@ -79,7 +79,7 @@ public class SchematicReader implements ClipboardReader { } @Override - public Clipboard read(WorldData data) throws IOException { + public Clipboard read() throws IOException { // Schematic tag NamedTag rootTag = inputStream.readNamedTag(); if (!rootTag.getName().equals("Schematic")) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java index 886e18aa8..224b1b220 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java @@ -22,15 +22,16 @@ package com.sk89q.worldedit.extent.transform; import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.LazyBlock; import com.sk89q.worldedit.blocks.type.BlockState; import com.sk89q.worldedit.blocks.type.BlockStateHolder; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.transform.Transform; -import com.sk89q.worldedit.world.registry.BlockRegistry; import com.sk89q.worldedit.world.registry.state.DirectionalState; import com.sk89q.worldedit.world.registry.state.State; import com.sk89q.worldedit.world.registry.state.value.DirectionalStateValue; @@ -48,20 +49,16 @@ public class BlockTransformExtent extends AbstractDelegateExtent { private static final double RIGHT_ANGLE = Math.toRadians(90); private final Transform transform; - private final BlockRegistry blockRegistry; /** * Create a new instance. * * @param extent the extent - * @param blockRegistry the block registry used for block direction data */ - public BlockTransformExtent(Extent extent, Transform transform, BlockRegistry blockRegistry) { + public BlockTransformExtent(Extent extent, Transform transform) { super(extent); checkNotNull(transform); - checkNotNull(blockRegistry); this.transform = transform; - this.blockRegistry = blockRegistry; } /** @@ -81,7 +78,7 @@ public class BlockTransformExtent extends AbstractDelegateExtent { * @return the same block */ private T transformBlock(T block, boolean reverse) { - transform(block, reverse ? transform.inverse() : transform, blockRegistry); + transform(block, reverse ? transform.inverse() : transform); return block; } @@ -113,11 +110,10 @@ public class BlockTransformExtent extends AbstractDelegateExtent { * * @param block the block * @param transform the transform - * @param registry the registry * @return the same block */ - public static T transform(T block, Transform transform, BlockRegistry registry) { - return transform(block, transform, registry, block); + public static T transform(T block, Transform transform) { + return transform(block, transform, block); } /** @@ -125,16 +121,15 @@ public class BlockTransformExtent extends AbstractDelegateExtent { * * @param block the block * @param transform the transform - * @param registry the registry * @param changedBlock the block to change * @return the changed block */ - private static T transform(T block, Transform transform, BlockRegistry registry, T changedBlock) { + private static T transform(T block, Transform transform, T changedBlock) { checkNotNull(block); checkNotNull(transform); - checkNotNull(registry); - Map states = registry.getStates(block); + Map states = WorldEdit.getInstance().getPlatformManager() + .queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getStates(block); if (states == null) { return changedBlock; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java index 20c417ca1..15d7c9067 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.function.mask; +import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.Vector; @@ -41,7 +42,7 @@ public class ExistingBlockMask extends AbstractExtentMask { @Override public boolean test(Vector vector) { - return !getExtent().getLazyBlock(vector).isAir(); + return getExtent().getBlock(vector).getBlockType() != BlockTypes.AIR; } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java index c2788cf7d..59d5f33b9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java @@ -33,6 +33,7 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.Pattern; @@ -318,7 +319,8 @@ public class WorldEditBinding extends BindingHelper { throw new ParameterException("An entity is required."); } - BiomeRegistry biomeRegistry = world.getWorldData().getBiomeRegistry(); + BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() + .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); List knownBiomes = biomeRegistry.getBiomes(); BaseBiome biome = Biomes.findBiomeByName(knownBiomes, input, biomeRegistry); if (biome != null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java index 37bb50de8..097c05cf6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/ClipboardHolder.java @@ -19,20 +19,18 @@ package com.sk89q.worldedit.session; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.math.transform.Identity; import com.sk89q.worldedit.math.transform.Transform; -import com.sk89q.worldedit.world.registry.WorldData; - -import static com.google.common.base.Preconditions.checkNotNull; /** * Holds the clipboard and the current transform on the clipboard. */ public class ClipboardHolder { - private final WorldData worldData; private final Clipboard clipboard; private Transform transform = new Identity(); @@ -40,22 +38,10 @@ public class ClipboardHolder { * Create a new instance with the given clipboard. * * @param clipboard the clipboard - * @param worldData the mapping of blocks, entities, and so on */ - public ClipboardHolder(Clipboard clipboard, WorldData worldData) { + public ClipboardHolder(Clipboard clipboard) { checkNotNull(clipboard); - checkNotNull(worldData); this.clipboard = clipboard; - this.worldData = worldData; - } - - /** - * Get the mapping used for blocks, entities, and so on. - * - * @return the mapping - */ - public WorldData getWorldData() { - return worldData; } /** @@ -94,8 +80,8 @@ public class ClipboardHolder { * * @return a builder */ - public PasteBuilder createPaste(Extent targetExtent, WorldData targetWorldData) { - return new PasteBuilder(this, targetExtent, targetWorldData); + public PasteBuilder createPaste(Extent targetExtent) { + return new PasteBuilder(this, targetExtent); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java index 5abe2e5f6..3fcce7100 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java @@ -20,6 +20,8 @@ package com.sk89q.worldedit.session; import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.transform.BlockTransformExtent; @@ -27,7 +29,7 @@ import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.math.transform.Transform; -import com.sk89q.worldedit.world.registry.WorldData; +import com.sk89q.worldedit.world.registry.Registries; import static com.google.common.base.Preconditions.checkNotNull; @@ -37,10 +39,8 @@ import static com.google.common.base.Preconditions.checkNotNull; public class PasteBuilder { private final Clipboard clipboard; - private final WorldData worldData; private final Transform transform; private final Extent targetExtent; - private final WorldData targetWorldData; private Vector to = new Vector(); private boolean ignoreAirBlocks; @@ -50,17 +50,13 @@ public class PasteBuilder { * * @param holder the clipboard holder * @param targetExtent an extent - * @param targetWorldData world data of the target */ - PasteBuilder(ClipboardHolder holder, Extent targetExtent, WorldData targetWorldData) { + PasteBuilder(ClipboardHolder holder, Extent targetExtent) { checkNotNull(holder); checkNotNull(targetExtent); - checkNotNull(targetWorldData); this.clipboard = holder.getClipboard(); - this.worldData = holder.getWorldData(); this.transform = holder.getTransform(); this.targetExtent = targetExtent; - this.targetWorldData = targetWorldData; } /** @@ -90,7 +86,7 @@ public class PasteBuilder { * @return the operation */ public Operation build() { - BlockTransformExtent extent = new BlockTransformExtent(clipboard, transform, targetWorldData.getBlockRegistry()); + BlockTransformExtent extent = new BlockTransformExtent(clipboard, transform); ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), targetExtent, to); copy.setTransform(transform); if (ignoreAirBlocks) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java index 9a254c658..9bfaa02fe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java @@ -36,13 +36,12 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.TreeGenerator.TreeType; import com.sk89q.worldedit.world.biome.BaseBiome; -import com.sk89q.worldedit.world.registry.BundledWorldData; -import com.sk89q.worldedit.world.registry.WorldData; -import javax.annotation.Nullable; import java.util.Collections; import java.util.List; +import javax.annotation.Nullable; + /** * A null implementation of {@link World} that drops all changes and * returns dummy data. @@ -98,11 +97,6 @@ public class NullWorld extends AbstractWorld { return false; } - @Override - public WorldData getWorldData() { - return BundledWorldData.getInstance(); - } - @Override public BlockState getBlock(Vector position) { return BlockTypes.AIR.getDefaultState(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java index 61dee0838..4bd434a78 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java @@ -24,7 +24,6 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.type.BlockStateHolder; @@ -35,7 +34,7 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.TreeGenerator; -import com.sk89q.worldedit.world.registry.WorldData; +import com.sk89q.worldedit.world.registry.Registries; /** * Represents a world (dimension). @@ -204,13 +203,6 @@ public interface World extends Extent { */ boolean queueBlockBreakEffect(Platform server, Vector position, BlockType blockType, double priority); - /** - * Get the data for blocks and so on for this world. - * - * @return the world data - */ - WorldData getWorldData(); - @Override boolean equals(Object other); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockCategoryRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockCategoryRegistry.java new file mode 100644 index 000000000..9b08915c4 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockCategoryRegistry.java @@ -0,0 +1,29 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.world.registry; + +import com.sk89q.worldedit.blocks.type.BlockType; + +/** + * A registry for BlockType categories. + */ +public interface BlockCategoryRegistry extends CategoryRegistry { + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledWorldData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledRegistries.java similarity index 70% rename from worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledWorldData.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledRegistries.java index 27147e2b5..7c6abc390 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledWorldData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledRegistries.java @@ -20,21 +20,23 @@ package com.sk89q.worldedit.world.registry; /** - * An implementation of {@link WorldData} that converts legacy numeric IDs and + * An implementation of {@link Registries} that converts legacy numeric IDs and * a contains a built-in block and item database. */ -public class BundledWorldData implements WorldData { +public class BundledRegistries implements Registries { - private static final BundledWorldData INSTANCE = new BundledWorldData(); + private static final BundledRegistries INSTANCE = new BundledRegistries(); private final BundledBlockRegistry blockRegistry = new BundledBlockRegistry(); private final BundledItemRegistry itemRegistry = new BundledItemRegistry(); private final NullEntityRegistry entityRegistry = new NullEntityRegistry(); private final NullBiomeRegistry biomeRegistry = new NullBiomeRegistry(); + private final NullBlockCategoryRegistry blockCategoryRegistry = new NullBlockCategoryRegistry(); + private final NullItemCategoryRegistry itemCategoryRegistry = new NullItemCategoryRegistry(); /** * Create a new instance. */ - protected BundledWorldData() { + protected BundledRegistries() { } @Override @@ -57,12 +59,22 @@ public class BundledWorldData implements WorldData { return biomeRegistry; } + @Override + public BlockCategoryRegistry getBlockCategoryRegistry() { + return blockCategoryRegistry; + } + + @Override + public ItemCategoryRegistry getItemCategoryRegistry() { + return itemCategoryRegistry; + } + /** * Get a singleton instance. * * @return an instance */ - public static BundledWorldData getInstance() { + public static BundledRegistries getInstance() { return INSTANCE; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/CategoryRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/CategoryRegistry.java new file mode 100644 index 000000000..066231d17 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/CategoryRegistry.java @@ -0,0 +1,44 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.world.registry; + +import java.util.Set; + +/** + * A registry of categories. Minecraft internally calls these 'Tags'. + */ +public interface CategoryRegistry { + + /** + * Gets a set of values with a given category. + * + * @param category The category + * @return A set of values + */ + Set getCategorisedByName(String category); + + /** + * Gets a list of categories given to a value. + * + * @param categorised The value + * @return A set of categories + */ + Set getCategories(T categorised); +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemCategoryRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemCategoryRegistry.java new file mode 100644 index 000000000..c80aea96a --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemCategoryRegistry.java @@ -0,0 +1,29 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.world.registry; + +import com.sk89q.worldedit.blocks.type.ItemType; + +/** + * A registry for ItemType categories. + */ +public interface ItemCategoryRegistry extends CategoryRegistry { + +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBlockCategoryRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBlockCategoryRegistry.java new file mode 100644 index 000000000..3a45304e2 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBlockCategoryRegistry.java @@ -0,0 +1,38 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.world.registry; + +import com.sk89q.worldedit.blocks.type.BlockType; + +import java.util.Collections; +import java.util.Set; + +public class NullBlockCategoryRegistry implements BlockCategoryRegistry { + + @Override + public Set getCategorisedByName(String category) { + return Collections.emptySet(); + } + + @Override + public Set getCategories(BlockType categorised) { + return Collections.emptySet(); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullItemCategoryRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullItemCategoryRegistry.java new file mode 100644 index 000000000..c116e46cc --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullItemCategoryRegistry.java @@ -0,0 +1,38 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.world.registry; + +import com.sk89q.worldedit.blocks.type.ItemType; + +import java.util.Collections; +import java.util.Set; + +public class NullItemCategoryRegistry implements ItemCategoryRegistry { + + @Override + public Set getCategorisedByName(String category) { + return Collections.emptySet(); + } + + @Override + public Set getCategories(ItemType categorised) { + return Collections.emptySet(); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/WorldData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/Registries.java similarity index 77% rename from worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/WorldData.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/Registries.java index ada70dd3c..aea32e09a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/WorldData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/Registries.java @@ -20,10 +20,9 @@ package com.sk89q.worldedit.world.registry; /** - * Describes the necessary data for blocks, entities, and other objects - * on a world. + * Contains getters for the various registries. */ -public interface WorldData { +public interface Registries { /** * Get the block registry. @@ -53,4 +52,18 @@ public interface WorldData { */ BiomeRegistry getBiomeRegistry(); + /** + * Get the block category registry. + * + * @return the block category registry + */ + BlockCategoryRegistry getBlockCategoryRegistry(); + + /** + * Get the item category registry. + * + * @return the item category registry + */ + ItemCategoryRegistry getItemCategoryRegistry(); + } diff --git a/worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java index 70e795a2f..f949710d4 100644 --- a/worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java +++ b/worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java @@ -71,7 +71,7 @@ public class BlockTransformExtentTest { BaseBlock orig = new BaseBlock(type); for (int i = 1; i < 4; i++) { - BaseBlock rotated = BlockTransformExtent.transform(new BaseBlock(orig), ROTATE_90, blockRegistry); + BaseBlock rotated = BlockTransformExtent.transform(new BaseBlock(orig), ROTATE_90); BaseBlock reference = new BaseBlock(orig.getBlockType().getLegacyId(), BlockData.rotate90(orig.getBlockType().getLegacyId(), orig.getData())); assertThat(type + "#" + type.getId() + " rotated " + (90 * i) + " degrees did not match BlockData.rotate90()'s expected result", rotated, equalTo(reference)); @@ -80,7 +80,7 @@ public class BlockTransformExtentTest { orig = new BaseBlock(type); for (int i = 0; i < 4; i++) { - BaseBlock rotated = BlockTransformExtent.transform(new BaseBlock(orig), ROTATE_NEG_90, blockRegistry); + BaseBlock rotated = BlockTransformExtent.transform(new BaseBlock(orig), ROTATE_NEG_90); BaseBlock reference = new BaseBlock(orig.getBlockType().getLegacyId(), BlockData.rotate90Reverse(orig.getBlockType().getLegacyId(), orig.getData())); assertThat(type + "#" + type.getId() + " rotated " + (-90 * i) + " degrees did not match BlockData.rotate90Reverse()'s expected result", rotated, equalTo(reference)); orig = rotated; diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlatform.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlatform.java index 2ddf75c51..2c0b8e234 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlatform.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlatform.java @@ -28,12 +28,10 @@ import com.sk89q.worldedit.extension.platform.Preference; import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.world.World; - -import net.minecraft.block.Block; +import com.sk89q.worldedit.world.registry.Registries; import net.minecraft.command.ServerCommandManager; import net.minecraft.entity.EntityList; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.Item; import net.minecraft.server.MinecraftServer; import net.minecraft.server.management.PlayerList; import net.minecraft.util.ResourceLocation; @@ -41,14 +39,14 @@ import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.fml.common.FMLCommonHandler; -import javax.annotation.Nullable; - import java.util.ArrayList; import java.util.Collection; import java.util.EnumMap; import java.util.List; import java.util.Map; +import javax.annotation.Nullable; + class ForgePlatform extends AbstractPlatform implements MultiUserPlatform { private final ForgeWorldEdit mod; @@ -65,30 +63,8 @@ class ForgePlatform extends AbstractPlatform implements MultiUserPlatform { } @Override - public int resolveItem(String name) { - if (name == null) return 0; - - int index = name.indexOf(':'); - - if (index != 0 && index != name.length() - 1) { - Block block = Block.getBlockFromName(name); - if (block != null) { - return Block.getIdFromBlock(block); - } - } - - for (Item item : Item.REGISTRY) { - if (item == null) continue; - if (item.getUnlocalizedName() == null) continue; - if (item.getUnlocalizedName().startsWith("item.")) { - if (item.getUnlocalizedName().equalsIgnoreCase("item." + name)) return Item.getIdFromItem(item); - } - if (item.getUnlocalizedName().startsWith("tile.")) { - if (item.getUnlocalizedName().equalsIgnoreCase("tile." + name)) return Item.getIdFromItem(item); - } - if (item.getUnlocalizedName().equalsIgnoreCase(name)) return Item.getIdFromItem(item); - } - return -1; + public Registries getRegistries() { + return ForgeRegistries.getInstance(); } @Override diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldData.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeRegistries.java similarity index 86% rename from worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldData.java rename to worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeRegistries.java index 0a6784727..bbdde9048 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldData.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeRegistries.java @@ -21,14 +21,14 @@ package com.sk89q.worldedit.forge; import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.ItemRegistry; -import com.sk89q.worldedit.world.registry.BundledWorldData; +import com.sk89q.worldedit.world.registry.BundledRegistries; /** * World data for the Forge platform. */ -class ForgeWorldData extends BundledWorldData { +class ForgeRegistries extends BundledRegistries { - private static final ForgeWorldData INSTANCE = new ForgeWorldData(); + private static final ForgeRegistries INSTANCE = new ForgeRegistries(); private final BiomeRegistry biomeRegistry = new ForgeBiomeRegistry(); private final ItemRegistry itemRegistry = new ForgeItemRegistry(); @@ -47,7 +47,7 @@ class ForgeWorldData extends BundledWorldData { * * @return an instance */ - public static ForgeWorldData getInstance() { + public static ForgeRegistries getInstance() { return INSTANCE; } 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 bd9512688..f086e171d 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 @@ -45,7 +45,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.WorldData; +import com.sk89q.worldedit.world.registry.Registries; import net.minecraft.block.Block; import net.minecraft.block.BlockLeaves; @@ -87,7 +87,6 @@ import net.minecraft.world.gen.feature.WorldGenTaiga2; import net.minecraft.world.gen.feature.WorldGenTrees; import net.minecraft.world.gen.feature.WorldGenerator; import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.fml.common.registry.ForgeRegistries; import javax.annotation.Nullable; @@ -345,18 +344,13 @@ public class ForgeWorld extends AbstractWorld { return generator != null && generator.generate(getWorld(), random, ForgeAdapter.toBlockPos(position)); } - @Override - public WorldData getWorldData() { - return ForgeWorldData.getInstance(); - } - @Override public BlockState getBlock(Vector position) { World world = getWorld(); BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()); IBlockState state = world.getBlockState(pos); - return BlockTypes.getBlockType(ForgeRegistries.BLOCKS.getKey(state.getBlock()).toString()).getDefaultState(); // TODO Data + return BlockTypes.getBlockType(net.minecraftforge.fml.common.registry.ForgeRegistries.BLOCKS.getKey(state.getBlock()).toString()).getDefaultState(); // TODO Data } @Override diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlatform.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlatform.java index a0be01208..774347645 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlatform.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlatform.java @@ -20,26 +20,35 @@ package com.sk89q.worldedit.sponge; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.event.platform.CommandSuggestionEvent; -import com.sk89q.worldedit.extension.platform.*; +import com.sk89q.worldedit.extension.platform.AbstractPlatform; +import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.extension.platform.Capability; +import com.sk89q.worldedit.extension.platform.MultiUserPlatform; +import com.sk89q.worldedit.extension.platform.Preference; import com.sk89q.worldedit.sponge.config.SpongeConfiguration; import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.world.registry.Registries; import org.spongepowered.api.Sponge; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.EntityType; -import org.spongepowered.api.item.ItemType; import org.spongepowered.api.scheduler.Task; import org.spongepowered.api.world.Location; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + import javax.annotation.Nullable; -import java.util.*; class SpongePlatform extends AbstractPlatform implements MultiUserPlatform { @@ -55,16 +64,8 @@ class SpongePlatform extends AbstractPlatform implements MultiUserPlatform { } @Override - public int resolveItem(String name) { - if (name == null) return 0; - - Optional optBlock = Sponge.getRegistry().getType(org.spongepowered.api.block.BlockType.class, name); - if (optBlock.isPresent()) { - return optBlock.map(blockType -> SpongeWorldEdit.inst().getAdapter().resolve(blockType)).orElse(0); - } else { - Optional optType = Sponge.getRegistry().getType(ItemType.class, name); - return optType.map(itemType -> SpongeWorldEdit.inst().getAdapter().resolve(itemType)).orElse(0); - } + public Registries getRegistries() { + return SpongeRegistries.getInstance(); } @Override diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldData.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeRegistries.java similarity index 83% rename from worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldData.java rename to worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeRegistries.java index 752342c1e..6e2777b7e 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldData.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeRegistries.java @@ -20,14 +20,14 @@ package com.sk89q.worldedit.sponge; import com.sk89q.worldedit.world.registry.BiomeRegistry; -import com.sk89q.worldedit.world.registry.BundledWorldData; +import com.sk89q.worldedit.world.registry.BundledRegistries; /** * World data for the Sponge platform. */ -class SpongeWorldData extends BundledWorldData { +class SpongeRegistries extends BundledRegistries { - private static final SpongeWorldData INSTANCE = new SpongeWorldData(); + private static final SpongeRegistries INSTANCE = new SpongeRegistries(); private final BiomeRegistry biomeRegistry = new SpongeBiomeRegistry(); @Override @@ -40,7 +40,7 @@ class SpongeWorldData extends BundledWorldData { * * @return an instance */ - public static SpongeWorldData getInstance() { + public static SpongeRegistries getInstance() { return INSTANCE; } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java index 54c523843..a0eb80ed9 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java @@ -35,7 +35,7 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.biome.BaseBiome; -import com.sk89q.worldedit.world.registry.WorldData; +import com.sk89q.worldedit.world.registry.Registries; import com.sk89q.worldedit.world.registry.state.State; import com.sk89q.worldedit.world.registry.state.value.StateValue; import org.spongepowered.api.Sponge; @@ -44,7 +44,6 @@ import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockType; import org.spongepowered.api.block.BlockTypes; import org.spongepowered.api.block.tileentity.TileEntity; -import org.spongepowered.api.block.trait.BlockTrait; import org.spongepowered.api.data.key.Keys; import org.spongepowered.api.data.property.block.GroundLuminanceProperty; import org.spongepowered.api.data.property.block.SkyLuminanceProperty; @@ -59,8 +58,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkNotNull; @@ -218,11 +215,6 @@ public abstract class SpongeWorld extends AbstractWorld { getWorld().spawnEntity(entity); } - @Override - public WorldData getWorldData() { - return SpongeWorldData.getInstance(); - } - @Override public int hashCode() { return getWorld().hashCode();