category changes

This commit is contained in:
kashike
2018-07-05 11:09:45 -07:00
committed by Matthew Miller
parent e1c2ea3a3b
commit 70208c38fd
19 changed files with 159 additions and 166 deletions

View File

@ -19,20 +19,12 @@
package com.sk89q.worldedit.world.item;
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 final class ItemCategories {
public static final ItemCategory ACACIA_LOGS = register("minecraft:acacia_logs");
public static final ItemCategory ANVIL = register("minecraft:anvil");
@ -65,6 +57,9 @@ public class ItemCategories {
public static final ItemCategory WOODEN_STAIRS = register("minecraft:wooden_stairs");
public static final ItemCategory WOOL = register("minecraft:wool");
private ItemCategories() {
}
private static ItemCategory register(final String id) {
return register(new ItemCategory(id));
}
@ -73,12 +68,7 @@ public class ItemCategories {
return ItemCategory.REGISTRY.register(tag.getId(), tag);
}
@Nullable
public static ItemCategory get(final String id) {
public static @Nullable ItemCategory get(final String id) {
return ItemCategory.REGISTRY.get(id);
}
public static Collection<ItemCategory> values() {
return ItemCategory.REGISTRY.values();
}
}

View File

@ -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.Category;
import com.sk89q.worldedit.registry.NamespacedRegistry;
import java.util.Set;
@ -30,35 +31,19 @@ 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 {
public class ItemCategory extends Category<ItemType> {
public static final NamespacedRegistry<ItemCategory> REGISTRY = new NamespacedRegistry<>();
public static final NamespacedRegistry<ItemCategory> REGISTRY = new NamespacedRegistry<>("item tag");
private final String id;
public ItemCategory(String id) {
this.id = id;
public ItemCategory(final String id) {
super(id);
}
public String getId() {
return this.id;
}
public Set<ItemType> getItemTypes() {
@Override
protected Set<ItemType> load() {
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);
.getItemCategoryRegistry().getAll(this);
}
/**
@ -69,6 +54,6 @@ public class ItemCategory {
* @return If it's a part of this category
*/
public boolean contains(BaseItem baseItem) {
return getItemTypes().contains(baseItem.getType());
return this.getAll().contains(baseItem.getType());
}
}

View File

@ -29,7 +29,7 @@ import javax.annotation.Nullable;
public class ItemType {
public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>();
public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>("item type");
private String id;

View File

@ -19,17 +19,9 @@
package com.sk89q.worldedit.world.item;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
public class ItemTypes {
private ItemTypes() {
}
public final class ItemTypes {
public static final ItemType ACACIA_BARK = register("minecraft:acacia_bark");
public static final ItemType ACACIA_BOAT = register("minecraft:acacia_boat");
@ -743,6 +735,9 @@ public class ItemTypes {
public static final ItemType ZOMBIE_SPAWN_EGG = register("minecraft:zombie_spawn_egg");
public static final ItemType ZOMBIE_VILLAGER_SPAWN_EGG = register("minecraft:zombie_villager_spawn_egg");
private ItemTypes() {
}
private static ItemType register(final String id) {
return register(new ItemType(id));
}
@ -751,12 +746,7 @@ public class ItemTypes {
return ItemType.REGISTRY.register(item.getId(), item);
}
@Nullable
public static ItemType get(final String id) {
public static @Nullable ItemType get(final String id) {
return ItemType.REGISTRY.get(id);
}
public static Collection<ItemType> values() {
return ItemType.REGISTRY.values();
}
}