mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
registry changes
This commit is contained in:
parent
a48c319e7e
commit
d33e2e98aa
@ -557,9 +557,9 @@ public class LocalSession {
|
||||
public void setTool(ItemType item, @Nullable Tool tool) throws InvalidToolBindException {
|
||||
if (item.hasBlockType()) {
|
||||
throw new InvalidToolBindException(item, "Blocks can't be used");
|
||||
} else if (item == ItemTypes.getItemType(config.wandItem)) {
|
||||
} else if (item == ItemTypes.get(config.wandItem)) {
|
||||
throw new InvalidToolBindException(item, "Already used for the wand");
|
||||
} else if (item == ItemTypes.getItemType(config.navigationWand)) {
|
||||
} else if (item == ItemTypes.get(config.navigationWand)) {
|
||||
throw new InvalidToolBindException(item, "Already used for the navigation wand");
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ public class GeneralCommands {
|
||||
boolean blocksOnly = args.hasFlag('b');
|
||||
boolean itemsOnly = args.hasFlag('i');
|
||||
|
||||
ItemType type = ItemTypes.getItemType(query);
|
||||
ItemType type = ItemTypes.get(query);
|
||||
|
||||
if (type != null) {
|
||||
actor.print(type.getId() + " (" + type.getName() + ")");
|
||||
|
@ -278,7 +278,7 @@ public class SelectionCommands {
|
||||
@CommandPermissions("worldedit.wand")
|
||||
public void wand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
|
||||
player.giveItem(new BaseItemStack(ItemTypes.getItemType(we.getConfiguration().wandItem), 1));
|
||||
player.giveItem(new BaseItemStack(ItemTypes.get(we.getConfiguration().wandItem), 1));
|
||||
player.print("Left click: select pos #1; Right click: select pos #2");
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ class DefaultBlockParser extends InputParser<BlockStateHolder> {
|
||||
blockStates = blockInHand.getStates();
|
||||
} else {
|
||||
// Attempt to lookup a block from ID or name.
|
||||
blockType = BlockTypes.getBlockType(typeString);
|
||||
blockType = BlockTypes.get(typeString);
|
||||
|
||||
if (blockType == null) {
|
||||
throw new NoMatchException("Does not match a valid block type: '" + input + "'");
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.registry;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public final class NamespacedRegistry<V> {
|
||||
private static final String MINECRAFT_NAMESPACE = "minecraft";
|
||||
private final Map<String, V> map = new HashMap<>();
|
||||
|
||||
public @Nullable V get(final String key) {
|
||||
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
|
||||
return this.map.get(this.orDefaultNamespace(key));
|
||||
}
|
||||
|
||||
public V register(final String key, final V value) {
|
||||
requireNonNull(key, "key");
|
||||
requireNonNull(value, "value");
|
||||
checkState(key.indexOf(':') > -1, "key is not namespaced");
|
||||
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
|
||||
checkState(!this.map.containsKey(key), "key %s already has an entry", key);
|
||||
this.map.put(key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public Set<String> keySet() {
|
||||
return Collections.unmodifiableSet(this.map.keySet());
|
||||
}
|
||||
|
||||
public Collection<V> values() {
|
||||
return Collections.unmodifiableCollection(this.map.values());
|
||||
}
|
||||
|
||||
private String orDefaultNamespace(final String key) {
|
||||
if (key.indexOf(':') == -1) {
|
||||
return MINECRAFT_NAMESPACE + ':' + key;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
}
|
@ -34,71 +34,53 @@ 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");
|
||||
public static final BlockCategory ACACIA_LOGS = register("minecraft:acacia_logs");
|
||||
public static final BlockCategory ANVIL = register("minecraft:anvil");
|
||||
public static final BlockCategory BANNERS = register("minecraft:banners");
|
||||
public static final BlockCategory BIRCH_LOGS = register("minecraft:birch_logs");
|
||||
public static final BlockCategory BUTTONS = register("minecraft:buttons");
|
||||
public static final BlockCategory CARPETS = register("minecraft:carpets");
|
||||
public static final BlockCategory CORAL = register("minecraft:coral");
|
||||
public static final BlockCategory CORAL_PLANTS = register("minecraft:coral_plants");
|
||||
public static final BlockCategory DARK_OAK_LOGS = register("minecraft:dark_oak_logs");
|
||||
public static final BlockCategory DOORS = register("minecraft:doors");
|
||||
public static final BlockCategory ENDERMAN_HOLDABLE = register("minecraft:enderman_holdable");
|
||||
public static final BlockCategory FLOWER_POTS = register("minecraft:flower_pots");
|
||||
public static final BlockCategory ICE = register("minecraft:ice");
|
||||
public static final BlockCategory JUNGLE_LOGS = register("minecraft:jungle_logs");
|
||||
public static final BlockCategory LEAVES = register("minecraft:leaves");
|
||||
public static final BlockCategory LOGS = register("minecraft:logs");
|
||||
public static final BlockCategory OAK_LOGS = register("minecraft:oak_logs");
|
||||
public static final BlockCategory PLANKS = register("minecraft:planks");
|
||||
public static final BlockCategory RAILS = register("minecraft:rails");
|
||||
public static final BlockCategory SAND = register("minecraft:sand");
|
||||
public static final BlockCategory SAPLINGS = register("minecraft:saplings");
|
||||
public static final BlockCategory SLABS = register("minecraft:slabs");
|
||||
public static final BlockCategory SPRUCE_LOGS = register("minecraft:spruce_logs");
|
||||
public static final BlockCategory STAIRS = register("minecraft:stairs");
|
||||
public static final BlockCategory STONE_BRICKS = register("minecraft:stone_bricks");
|
||||
public static final BlockCategory VALID_SPAWN = register("minecraft:valid_spawn");
|
||||
public static final BlockCategory WOODEN_BUTTONS = register("minecraft:wooden_buttons");
|
||||
public static final BlockCategory WOODEN_DOORS = register("minecraft:wooden_doors");
|
||||
public static final BlockCategory WOODEN_PRESSURE_PLATES = register("minecraft:wooden_pressure_plates");
|
||||
public static final BlockCategory WOODEN_SLABS = register("minecraft:wooden_slabs");
|
||||
public static final BlockCategory WOODEN_STAIRS = register("minecraft:wooden_stairs");
|
||||
public static final BlockCategory WOOL = register("minecraft:wool");
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
private static BlockCategory register(final String id) {
|
||||
return register(new BlockCategory(id));
|
||||
}
|
||||
|
||||
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);
|
||||
public static BlockCategory register(final BlockCategory tag) {
|
||||
return BlockCategory.REGISTRY.register(tag.getId(), tag);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BlockCategory getBlockCategory(String id) {
|
||||
// If it has no namespace, assume minecraft.
|
||||
if (id != null && !id.contains(":")) {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
return categoryMapping.get(id);
|
||||
public static BlockCategory get(final String id) {
|
||||
return BlockCategory.REGISTRY.get(id);
|
||||
}
|
||||
|
||||
public static Collection<BlockCategory> values() {
|
||||
return categoryMapping.values();
|
||||
return BlockCategory.REGISTRY.values();
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.block;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -30,6 +31,8 @@ import java.util.Set;
|
||||
*/
|
||||
public class BlockCategory {
|
||||
|
||||
public static final NamespacedRegistry<BlockCategory> REGISTRY = new NamespacedRegistry<>();
|
||||
|
||||
private final String id;
|
||||
|
||||
public BlockCategory(String id) {
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.world.block;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BlockMaterial;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
@ -33,6 +34,8 @@ import javax.annotation.Nullable;
|
||||
|
||||
public class BlockType {
|
||||
|
||||
public static final NamespacedRegistry<BlockType> REGISTRY = new NamespacedRegistry<>();
|
||||
|
||||
private String id;
|
||||
private BlockState defaultState;
|
||||
|
||||
@ -100,7 +103,7 @@ public class BlockType {
|
||||
*/
|
||||
@Nullable
|
||||
public ItemType getItemType() {
|
||||
return ItemTypes.getItemType(this.id);
|
||||
return ItemTypes.get(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -19,10 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.world.fluid;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -34,41 +31,23 @@ public class FluidCategories {
|
||||
private FluidCategories() {
|
||||
}
|
||||
|
||||
public static final FluidCategory LAVA = new FluidCategory("minecraft:lava");
|
||||
public static final FluidCategory WATER = new FluidCategory("minecraft:water");
|
||||
public static final FluidCategory LAVA = register("minecraft:lava");
|
||||
public static final FluidCategory WATER = register("minecraft:water");
|
||||
|
||||
private static final Map<String, FluidCategory> categoryMapping = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (Field field : FluidCategories.class.getFields()) {
|
||||
if (field.getType() == FluidCategory.class) {
|
||||
try {
|
||||
registerCategory((FluidCategory) field.get(null));
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
private static FluidCategory register(final String id) {
|
||||
return register(new FluidCategory(id));
|
||||
}
|
||||
|
||||
public static void registerCategory(FluidCategory fluidCategory) {
|
||||
if (categoryMapping.containsKey(fluidCategory.getId()) && !fluidCategory.getId().startsWith("minecraft:")) {
|
||||
throw new IllegalArgumentException("Existing category with this ID already registered");
|
||||
}
|
||||
|
||||
categoryMapping.put(fluidCategory.getId(), fluidCategory);
|
||||
public static FluidCategory register(final FluidCategory tag) {
|
||||
return FluidCategory.REGISTRY.register(tag.getId(), tag);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FluidCategory getFluidCategory(String id) {
|
||||
// If it has no namespace, assume minecraft.
|
||||
if (id != null && !id.contains(":")) {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
return categoryMapping.get(id);
|
||||
public static FluidCategory get(final String id) {
|
||||
return FluidCategory.REGISTRY.get(id);
|
||||
}
|
||||
|
||||
public static Collection<FluidCategory> values() {
|
||||
return categoryMapping.values();
|
||||
return FluidCategory.REGISTRY.values();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.world.fluid;
|
||||
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
@ -28,6 +30,8 @@ import java.util.Set;
|
||||
*/
|
||||
public class FluidCategory {
|
||||
|
||||
public static final NamespacedRegistry<FluidCategory> REGISTRY = new NamespacedRegistry<>();
|
||||
|
||||
private final String id;
|
||||
|
||||
public FluidCategory(String id) {
|
||||
|
@ -19,12 +19,16 @@
|
||||
|
||||
package com.sk89q.worldedit.world.fluid;
|
||||
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
|
||||
/**
|
||||
* Minecraft now has a 'fluid' system. This is a
|
||||
* stub class to represent what it may be in the future.
|
||||
*/
|
||||
public class FluidType {
|
||||
|
||||
public static final NamespacedRegistry<FluidType> REGISTRY = new NamespacedRegistry<>();
|
||||
|
||||
private String id;
|
||||
|
||||
public FluidType(String id) {
|
||||
|
@ -19,10 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.world.fluid;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -34,45 +31,26 @@ public class FluidTypes {
|
||||
private FluidTypes() {
|
||||
}
|
||||
|
||||
public static final FluidType EMPTY = new FluidType("minecraft:empty");
|
||||
public static final FluidType FLOWING_LAVA = new FluidType("minecraft:flowing_lava");
|
||||
public static final FluidType FLOWING_WATER = new FluidType("minecraft:flowing_water");
|
||||
public static final FluidType LAVA = new FluidType("minecraft:lava");
|
||||
public static final FluidType WATER = new FluidType("minecraft:water");
|
||||
public static final FluidType EMPTY = register("minecraft:empty");
|
||||
public static final FluidType FLOWING_LAVA = register("minecraft:flowing_lava");
|
||||
public static final FluidType FLOWING_WATER = register("minecraft:flowing_water");
|
||||
public static final FluidType LAVA = register("minecraft:lava");
|
||||
public static final FluidType WATER = register("minecraft:water");
|
||||
|
||||
|
||||
private static final Map<String, FluidType> fluidMapping = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (Field field : FluidTypes.class.getFields()) {
|
||||
if (field.getType() == FluidType.class) {
|
||||
try {
|
||||
registerFluid((FluidType) field.get(null));
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
private static FluidType register(final String id) {
|
||||
return register(new FluidType(id));
|
||||
}
|
||||
|
||||
public static void registerFluid(FluidType fluidType) {
|
||||
if (fluidMapping.containsKey(fluidType.getId()) && !fluidType.getId().startsWith("minecraft:")) {
|
||||
throw new IllegalArgumentException("Existing fluid with this ID already registered");
|
||||
}
|
||||
|
||||
fluidMapping.put(fluidType.getId(), fluidType);
|
||||
public static FluidType register(final FluidType fluid) {
|
||||
return FluidType.REGISTRY.register(fluid.getId(), fluid);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FluidType getFluidType(String id) {
|
||||
// If it has no namespace, assume minecraft.
|
||||
if (id != null && !id.contains(":")) {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
return fluidMapping.get(id);
|
||||
public static FluidType getFluidType(final String id) {
|
||||
return FluidType.REGISTRY.get(id);
|
||||
}
|
||||
|
||||
public static Collection<FluidType> values() {
|
||||
return fluidMapping.values();
|
||||
return FluidType.REGISTRY.values();
|
||||
}
|
||||
}
|
||||
|
@ -34,69 +34,51 @@ 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");
|
||||
public static final ItemCategory ACACIA_LOGS = register("minecraft:acacia_logs");
|
||||
public static final ItemCategory ANVIL = register("minecraft:anvil");
|
||||
public static final ItemCategory BANNERS = register("minecraft:banners");
|
||||
public static final ItemCategory BIRCH_LOGS = register("minecraft:birch_logs");
|
||||
public static final ItemCategory BOATS = register("minecraft:boats");
|
||||
public static final ItemCategory BUTTONS = register("minecraft:buttons");
|
||||
public static final ItemCategory CARPETS = register("minecraft:carpets");
|
||||
public static final ItemCategory CORAL = register("minecraft:coral");
|
||||
public static final ItemCategory CORAL_PLANTS = register("minecraft:coral_plants");
|
||||
public static final ItemCategory DARK_OAK_LOGS = register("minecraft:dark_oak_logs");
|
||||
public static final ItemCategory DOORS = register("minecraft:doors");
|
||||
public static final ItemCategory FISHES = register("minecraft:fishes");
|
||||
public static final ItemCategory JUNGLE_LOGS = register("minecraft:jungle_logs");
|
||||
public static final ItemCategory LEAVES = register("minecraft:leaves");
|
||||
public static final ItemCategory LOGS = register("minecraft:logs");
|
||||
public static final ItemCategory OAK_LOGS = register("minecraft:oak_logs");
|
||||
public static final ItemCategory PLANKS = register("minecraft:planks");
|
||||
public static final ItemCategory RAILS = register("minecraft:rails");
|
||||
public static final ItemCategory SAND = register("minecraft:sand");
|
||||
public static final ItemCategory SAPLINGS = register("minecraft:saplings");
|
||||
public static final ItemCategory SLABS = register("minecraft:slabs");
|
||||
public static final ItemCategory SPRUCE_LOGS = register("minecraft:spruce_logs");
|
||||
public static final ItemCategory STAIRS = register("minecraft:stairs");
|
||||
public static final ItemCategory STONE_BRICKS = register("minecraft:stone_bricks");
|
||||
public static final ItemCategory WOODEN_BUTTONS = register("minecraft:wooden_buttons");
|
||||
public static final ItemCategory WOODEN_DOORS = register("minecraft:wooden_doors");
|
||||
public static final ItemCategory WOODEN_PRESSURE_PLATES = register("minecraft:wooden_pressure_plates");
|
||||
public static final ItemCategory WOODEN_SLABS = register("minecraft:wooden_slabs");
|
||||
public static final ItemCategory WOODEN_STAIRS = register("minecraft:wooden_stairs");
|
||||
public static final ItemCategory WOOL = register("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();
|
||||
}
|
||||
}
|
||||
}
|
||||
private static ItemCategory register(final String id) {
|
||||
return register(new ItemCategory(id));
|
||||
}
|
||||
|
||||
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);
|
||||
public static ItemCategory register(final ItemCategory tag) {
|
||||
return ItemCategory.REGISTRY.register(tag.getId(), tag);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ItemCategory getItemCategory(String id) {
|
||||
// If it has no namespace, assume minecraft.
|
||||
if (id != null && !id.contains(":")) {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
return categoryMapping.get(id);
|
||||
public static ItemCategory get(final String id) {
|
||||
return ItemCategory.REGISTRY.get(id);
|
||||
}
|
||||
|
||||
public static Collection<ItemCategory> values() {
|
||||
return categoryMapping.values();
|
||||
return ItemCategory.REGISTRY.values();
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.world.item;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -31,6 +32,8 @@ import java.util.Set;
|
||||
*/
|
||||
public class ItemCategory {
|
||||
|
||||
public static final NamespacedRegistry<ItemCategory> REGISTRY = new NamespacedRegistry<>();
|
||||
|
||||
private final String id;
|
||||
|
||||
public ItemCategory(String id) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.world.item;
|
||||
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.BundledItemData;
|
||||
@ -28,6 +29,8 @@ import javax.annotation.Nullable;
|
||||
|
||||
public class ItemType {
|
||||
|
||||
public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>();
|
||||
|
||||
private String id;
|
||||
|
||||
public ItemType(String id) {
|
||||
@ -73,7 +76,7 @@ public class ItemType {
|
||||
*/
|
||||
@Nullable
|
||||
public BlockType getBlockType() {
|
||||
return BlockTypes.getBlockType(this.id);
|
||||
return BlockTypes.get(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -38,7 +38,7 @@ public class BundledBlockRegistry implements BlockRegistry {
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockState createFromId(String id) {
|
||||
return BlockTypes.getBlockType(id).getDefaultState();
|
||||
return BlockTypes.get(id).getDefaultState();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -33,6 +33,6 @@ public class BundledItemRegistry implements ItemRegistry {
|
||||
@Nullable
|
||||
@Override
|
||||
public BaseItem createFromId(String id) {
|
||||
return new BaseItem(ItemTypes.getItemType(id));
|
||||
return new BaseItem(ItemTypes.get(id));
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class LegacyMapper {
|
||||
|
||||
for (Map.Entry<String, String> itemEntry : dataFile.items.entrySet()) {
|
||||
try {
|
||||
itemMap.put(itemEntry.getKey(), ItemTypes.getItemType(itemEntry.getValue()));
|
||||
itemMap.put(itemEntry.getKey(), ItemTypes.get(itemEntry.getValue()));
|
||||
} catch (Exception e) {
|
||||
log.warning("Unknown item: " + itemEntry.getValue());
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class ForgeItemRegistry implements ItemRegistry {
|
||||
public BaseItem createFromId(String id) {
|
||||
Item match = Item.REGISTRY.getObject(new ResourceLocation(id));
|
||||
if (match != null) {
|
||||
return new BaseItem(ItemTypes.getItemType(id));
|
||||
return new BaseItem(ItemTypes.get(id));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class ForgePlayer extends AbstractPlayerActor {
|
||||
@Override
|
||||
public BaseItemStack getItemInHand(HandSide handSide) {
|
||||
ItemStack is = this.player.getHeldItem(handSide == HandSide.MAIN_HAND ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND);
|
||||
return new BaseItemStack(ItemTypes.getItemType(ForgeRegistries.ITEMS.getKey(is.getItem()).toString()));
|
||||
return new BaseItemStack(ItemTypes.get(ForgeRegistries.ITEMS.getKey(is.getItem()).toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -125,7 +125,7 @@ public class ForgeWorldEdit {
|
||||
}
|
||||
|
||||
for (Block block : REGISTRY) {
|
||||
BlockTypes.registerBlock(new BlockType(REGISTRY.getNameForObject(block).toString()));
|
||||
BlockTypes.register(new BlockType(REGISTRY.getNameForObject(block).toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class SpongePlayer extends AbstractPlayerActor {
|
||||
public BaseItemStack getItemInHand(HandSide handSide) {
|
||||
Optional<ItemStack> is = this.player.getItemInHand(handSide == HandSide.MAIN_HAND
|
||||
? HandTypes.MAIN_HAND : HandTypes.OFF_HAND);
|
||||
return is.map(itemStack -> new BaseItemStack(ItemTypes.getItemType(itemStack.getType().getId()))).orElse(null);
|
||||
return is.map(itemStack -> new BaseItemStack(ItemTypes.get(itemStack.getType().getId()))).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -135,11 +135,11 @@ public class SpongeWorldEdit {
|
||||
|
||||
for (BlockType blockType : Sponge.getRegistry().getAllOf(BlockType.class)) {
|
||||
// TODO Handle blockstate stuff
|
||||
com.sk89q.worldedit.world.block.BlockTypes.registerBlock(new com.sk89q.worldedit.world.block.BlockType(blockType.getId()));
|
||||
com.sk89q.worldedit.world.block.BlockTypes.register(new com.sk89q.worldedit.world.block.BlockType(blockType.getId()));
|
||||
}
|
||||
|
||||
for (ItemType itemType : Sponge.getRegistry().getAllOf(ItemType.class)) {
|
||||
ItemTypes.registerItem(new com.sk89q.worldedit.world.item.ItemType(itemType.getId()));
|
||||
ItemTypes.register(new com.sk89q.worldedit.world.item.ItemType(itemType.getId()));
|
||||
}
|
||||
|
||||
WorldEdit.getInstance().getPlatformManager().register(platform);
|
||||
|
Loading…
Reference in New Issue
Block a user