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

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