Added a category system and refactored registries

This commit is contained in:
Matthew Miller 2018-06-19 10:53:15 +10:00
parent 484687a49d
commit 282eca7663
47 changed files with 715 additions and 316 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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
}

View File

@ -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) {

View File

@ -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<BaseBlock>, 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<BaseBlock>, 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<BaseBlock>, TileEntityBlock {
*
* @return The state map
*/
@Override
public Map<State, StateValue> getStates() {
return this.blockState.getStates();
}
@ -194,19 +194,11 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, 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<BaseBlock>, 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.
*/

View File

@ -0,0 +1,108 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<String, BlockCategory> 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<BlockCategory> values() {
return categoryMapping.values();
}
}

View File

@ -0,0 +1,70 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<BlockType> 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());
}
}

View File

@ -0,0 +1,102 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<String, ItemCategory> 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<ItemCategory> values() {
return categoryMapping.values();
}
}

View File

@ -0,0 +1,73 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<ItemType> 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());
}
}

View File

@ -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<BaseBiome> 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<BaseBiome> biomes = new HashSet<>();
String qualifier;

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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<? extends Entity> 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<? extends Entity> entities = world.getEntities();
visitors.add(new EntityVisitor(entities.iterator(), remover.createFunction(world.getWorldData().getEntityRegistry())));
visitors.add(new EntityVisitor(entities.iterator(), remover.createFunction()));
}
}

View File

@ -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) {

View File

@ -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(),
};
/**

View File

@ -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<? extends Entity> entities = editSession.getEntities(region);
Operations.completeLegacy(new EntityVisitor(entities.iterator(), flags.createFunction(editSession.getWorld().getWorldData().getEntityRegistry())));
Operations.completeLegacy(new EntityVisitor(entities.iterator(), flags.createFunction()));
}
}

View File

@ -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();

View File

@ -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;

View File

@ -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 -> {

View File

@ -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<BaseItem> {
@ -33,7 +34,8 @@ public class DefaultItemParser extends InputParser<BaseItem> {
@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");

View File

@ -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<Mask> {
case '$':
Set<BaseBiome> 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<BaseBiome> knownBiomes = biomeRegistry.getBiomes();
for (String biomeName : biomesList) {
BaseBiome biome = Biomes.findBiomeByName(knownBiomes, biomeName, biomeRegistry);

View File

@ -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.

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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")) {

View File

@ -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 extends BlockStateHolder> 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 extends BlockStateHolder> T transform(T block, Transform transform, BlockRegistry registry) {
return transform(block, transform, registry, block);
public static <T extends BlockStateHolder> 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 extends BlockStateHolder> T transform(T block, Transform transform, BlockRegistry registry, T changedBlock) {
private static <T extends BlockStateHolder> T transform(T block, Transform transform, T changedBlock) {
checkNotNull(block);
checkNotNull(transform);
checkNotNull(registry);
Map<String, ? extends State> states = registry.getStates(block);
Map<String, ? extends State> states = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getStates(block);
if (states == null) {
return changedBlock;

View File

@ -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

View File

@ -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<BaseBiome> knownBiomes = biomeRegistry.getBiomes();
BaseBiome biome = Biomes.findBiomeByName(knownBiomes, input, biomeRegistry);
if (biome != null) {

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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();

View File

@ -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);

View File

@ -0,0 +1,29 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.type.BlockType;
/**
* A registry for BlockType categories.
*/
public interface BlockCategoryRegistry extends CategoryRegistry<BlockType> {
}

View File

@ -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;
}

View File

@ -0,0 +1,44 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.world.registry;
import java.util.Set;
/**
* A registry of categories. Minecraft internally calls these 'Tags'.
*/
public interface CategoryRegistry<T> {
/**
* Gets a set of values with a given category.
*
* @param category The category
* @return A set of values
*/
Set<T> getCategorisedByName(String category);
/**
* Gets a list of categories given to a value.
*
* @param categorised The value
* @return A set of categories
*/
Set<String> getCategories(T categorised);
}

View File

@ -0,0 +1,29 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.type.ItemType;
/**
* A registry for ItemType categories.
*/
public interface ItemCategoryRegistry extends CategoryRegistry<ItemType> {
}

View File

@ -0,0 +1,38 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<BlockType> getCategorisedByName(String category) {
return Collections.emptySet();
}
@Override
public Set<String> getCategories(BlockType categorised) {
return Collections.emptySet();
}
}

View File

@ -0,0 +1,38 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
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<ItemType> getCategorisedByName(String category) {
return Collections.emptySet();
}
@Override
public Set<String> getCategories(ItemType categorised) {
return Collections.emptySet();
}
}

View File

@ -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();
}

View File

@ -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;

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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<org.spongepowered.api.block.BlockType> 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<ItemType> 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

View File

@ -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;
}

View File

@ -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();