mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 10:48:34 +00:00
Working now
This commit is contained in:
@ -34,6 +34,7 @@ import java.util.Set;
|
||||
public class ItemCategory extends Category<ItemType> {
|
||||
|
||||
public static final NamespacedRegistry<ItemCategory> REGISTRY = new NamespacedRegistry<>("item tag");
|
||||
private int internalId;
|
||||
|
||||
public ItemCategory(final String id) {
|
||||
super(id);
|
||||
@ -56,4 +57,5 @@ public class ItemCategory extends Category<ItemType> {
|
||||
public boolean contains(BaseItem baseItem) {
|
||||
return this.getAll().contains(baseItem.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,40 +22,44 @@ 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.RegistryItem;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ItemType {
|
||||
public class ItemType implements RegistryItem {
|
||||
|
||||
public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>("item type");
|
||||
|
||||
private String id;
|
||||
private BlockType blockType;
|
||||
private int internalId;
|
||||
private boolean initBlockType;
|
||||
private BaseItem defaultState;
|
||||
|
||||
protected ItemType(String id) {
|
||||
public ItemType(String id) {
|
||||
// If it has no namespace, assume minecraft.
|
||||
if (!id.contains(":")) {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
this.id = id;
|
||||
this.blockType = BlockTypes.get(this.id);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public int getInternalId() {
|
||||
return this.internalId;
|
||||
}
|
||||
|
||||
|
||||
private int internalId;
|
||||
|
||||
@Override
|
||||
public void setInternalId(int internalId) {
|
||||
this.internalId = internalId;
|
||||
this.internalId = internalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInternalId() {
|
||||
return internalId;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,6 +97,10 @@ public class ItemType {
|
||||
}
|
||||
|
||||
public void setBlockType(BlockType blockType) {
|
||||
if (!initBlockType) {
|
||||
initBlockType = true;
|
||||
this.blockType = BlockTypes.get(this.id);
|
||||
}
|
||||
this.blockType = blockType;
|
||||
}
|
||||
|
||||
|
@ -19,22 +19,12 @@
|
||||
|
||||
package com.sk89q.worldedit.world.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
public final class ItemTypes {
|
||||
|
||||
@Nullable public static final ItemType ACACIA_BOAT = get("minecraft:acacia_boat");
|
||||
@ -831,24 +821,6 @@ public final class ItemTypes {
|
||||
private ItemTypes() {
|
||||
}
|
||||
|
||||
private static ItemType register(final String id) {
|
||||
return register(new ItemType(id));
|
||||
}
|
||||
|
||||
public static ItemType register(final ItemType item) {
|
||||
if(sortedRegistry == null)
|
||||
sortedRegistry = new ArrayList<>();
|
||||
if(!sortedRegistry.contains(item))sortedRegistry.add(item);
|
||||
// return ItemType.REGISTRY.register(item.getId(), item);
|
||||
return internalRegister(item);
|
||||
}
|
||||
|
||||
private static ArrayList<ItemType> sortedRegistry;
|
||||
|
||||
public static ItemType[] values() {
|
||||
return sortedRegistry.toArray(new ItemType[sortedRegistry.size()]);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ItemType parse(String input) {
|
||||
input = input.toLowerCase();
|
||||
@ -866,30 +838,20 @@ public final class ItemTypes {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ItemType internalRegister(final ItemType type) {
|
||||
type.setInternalId(sortedRegistry.indexOf(type));
|
||||
type.setDefaultState(new BaseItemStack(type, 1));
|
||||
return ItemType.REGISTRY.register(type.getId(), type);
|
||||
}
|
||||
|
||||
public static final @Nullable ItemType get(String id) {
|
||||
return ItemType.REGISTRY.get(id);
|
||||
}
|
||||
|
||||
public static final @Nullable ItemType get(BlockType type) {
|
||||
ItemType item = get(type.getId());
|
||||
if (item != null && item.getBlockType() == null) {
|
||||
item.setBlockType(type);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static final ItemType get(final int ordinal) {
|
||||
return values()[ordinal];
|
||||
return ItemType.REGISTRY.getByInternalId(ordinal);
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
return values().length;
|
||||
return ItemType.REGISTRY.size();
|
||||
}
|
||||
|
||||
public static Collection<ItemType> values() {
|
||||
return ItemType.REGISTRY.values();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user