geforkt von Mirrors/FastAsyncWorldEdit
Working now
Dieser Commit ist enthalten in:
Ursprung
95c819684c
Commit
140809c903
@ -34,17 +34,26 @@ import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
|
||||
import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
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.extension.platform.NoCapablePlatformException;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockCategory;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.FuzzyBlockState;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.item.ItemCategory;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -149,6 +158,7 @@ public class WorldEditPlugin extends JavaPlugin //implements TabCompleter
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
if (INSTANCE != null) return;
|
||||
rename();
|
||||
this.INSTANCE = this;
|
||||
FaweBukkit imp = new FaweBukkit(this);
|
||||
@ -162,11 +172,9 @@ public class WorldEditPlugin extends JavaPlugin //implements TabCompleter
|
||||
server = new BukkitServerInterface(this, getServer());
|
||||
worldEdit.getPlatformManager().register(server);
|
||||
loadAdapter(); // Need an adapter to work with special blocks with NBT data
|
||||
worldEdit.loadMappings();
|
||||
|
||||
loadConfig(); // Load configuration
|
||||
fail(() -> PermissionsResolverManager.initialize(INSTANCE), "Failed to initialize permissions resolver");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,7 +182,11 @@ public class WorldEditPlugin extends JavaPlugin //implements TabCompleter
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (INSTANCE != null) return;
|
||||
onLoad();
|
||||
setupTags(); // these have to be done post-world since they rely on MC registries. the other ones just use Bukkit enums
|
||||
setupRegistries();
|
||||
WorldEdit.getInstance().loadMappings();
|
||||
|
||||
PermissionsResolverManager.initialize(this); // Setup permission resolver
|
||||
|
||||
@ -202,6 +214,48 @@ public class WorldEditPlugin extends JavaPlugin //implements TabCompleter
|
||||
}
|
||||
}
|
||||
|
||||
public void setupRegistries() {
|
||||
// Biome
|
||||
for (Biome biome : Biome.values()) {
|
||||
BiomeType.REGISTRY.register("minecraft:" + biome.name().toLowerCase(), new BiomeType("minecraft:" + biome.name().toLowerCase()));
|
||||
}
|
||||
// Block & Item
|
||||
for (Material material : Material.values()) {
|
||||
// if (material.isBlock() && !material.isLegacy()) {
|
||||
// BlockType.REGISTRY.register(material.getKey().toString(), new BlockType(material.getKey().toString(), blockState -> {
|
||||
// // TODO Use something way less hacky than this.
|
||||
// ParserContext context = new ParserContext();
|
||||
// context.setPreferringWildcard(true);
|
||||
// context.setTryLegacy(false);
|
||||
// context.setRestricted(false);
|
||||
// try {
|
||||
// FuzzyBlockState state = (FuzzyBlockState) WorldEdit.getInstance().getBlockFactory().parseFromInput(
|
||||
// BukkitAdapter.adapt(blockState.getBlockType()).createBlockData().getAsString(), context
|
||||
// ).toImmutableState();
|
||||
// BlockState defaultState = blockState.getBlockType().getAllStates().get(0);
|
||||
// for (Map.Entry<Property<?>, Object> propertyObjectEntry : state.getStates().entrySet()) {
|
||||
// defaultState = defaultState.with((Property) propertyObjectEntry.getKey(), propertyObjectEntry.getValue());
|
||||
// }
|
||||
// return defaultState;
|
||||
// } catch (InputParseException e) {
|
||||
// e.printStackTrace();
|
||||
// return blockState;
|
||||
// }
|
||||
// }));
|
||||
// }
|
||||
if (material.isItem() && !material.isLegacy()) {
|
||||
ItemType.REGISTRY.register(material.getKey().toString(), new ItemType(material.getKey().toString()));
|
||||
}
|
||||
}
|
||||
// Entity
|
||||
for (org.bukkit.entity.EntityType entityType : org.bukkit.entity.EntityType.values()) {
|
||||
String mcid = entityType.getName();
|
||||
if (mcid != null) {
|
||||
EntityType.REGISTRY.register("minecraft:" + mcid.toLowerCase(), new EntityType("minecraft:" + mcid.toLowerCase()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupTags() {
|
||||
// Tags
|
||||
try {
|
||||
@ -245,18 +299,18 @@ public class WorldEditPlugin extends JavaPlugin //implements TabCompleter
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
java.util.logging.Logger logger = getLogger();
|
||||
if (logger != null) {
|
||||
try {
|
||||
Field nameField = Logger.class.getDeclaredField("name");
|
||||
nameField.setAccessible(true);
|
||||
nameField.set(logger, "FastAsyncWorldEdit");
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
// {
|
||||
// java.util.logging.Logger logger = getLogger();
|
||||
// if (logger != null) {
|
||||
// try {
|
||||
// Field nameField = Logger.class.getDeclaredField("name");
|
||||
// nameField.setAccessible(true);
|
||||
// nameField.set(logger, "FastAsyncWorldEdit");
|
||||
// } catch (Throwable ignore) {
|
||||
// ignore.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
{
|
||||
File pluginsFolder = MainUtil.getJarFile().getParentFile();
|
||||
for (File file : pluginsFolder.listFiles()) {
|
||||
|
@ -19,6 +19,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
// TODO FIXME
|
||||
@ -95,7 +96,7 @@ public class FaweLocalBlockQueue extends LocalBlockQueue {
|
||||
if (reg == null) {
|
||||
reg = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.USER_COMMANDS).getRegistries().getBiomeRegistry();
|
||||
}
|
||||
List<BiomeType> biomes = BiomeTypes.values();
|
||||
Collection<BiomeType> biomes = BiomeTypes.values();
|
||||
lastBiome = biome;
|
||||
this.biome = Biomes.findBiomeByName(biomes, biome, reg);
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.biome.Biomes;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
@ -56,7 +58,7 @@ public class PlotSetBiome extends Command {
|
||||
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
|
||||
final HashSet<RegionWrapper> regions = plot.getRegions();
|
||||
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
|
||||
List<BiomeType> knownBiomes = BiomeTypes.values();
|
||||
Collection<BiomeType> knownBiomes = BiomeTypes.values();
|
||||
final BiomeType biome = Biomes.findBiomeByName(knownBiomes, args[0], biomeRegistry);
|
||||
if (biome == null) {
|
||||
String biomes = StringMan.join(WorldUtil.IMP.getBiomeList(), Captions.BLOCK_LIST_SEPARATER.s());
|
||||
|
@ -107,7 +107,7 @@ public class BiomeCommands extends MethodCommands {
|
||||
}
|
||||
|
||||
BiomeRegistry biomeRegistry = getBiomeRegistry();
|
||||
List<BiomeType> biomes = BiomeTypes.values();
|
||||
Collection<BiomeType> biomes = BiomeTypes.values();
|
||||
int totalPages = biomes.size() / 19 + 1;
|
||||
Message msg = BBC.BIOME_LIST_HEADER.m(page, totalPages);
|
||||
String setBiome = Commands.getAlias(BiomeCommands.class, "/setbiome");
|
||||
@ -144,7 +144,7 @@ public class BiomeCommands extends MethodCommands {
|
||||
@CommandPermissions("worldedit.biome.info")
|
||||
public void biomeInfo(Player player, LocalSession session, final EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
BiomeRegistry biomeRegistry = getBiomeRegistry();
|
||||
List<BiomeType> values = BiomeTypes.values();
|
||||
Collection<BiomeType> values = BiomeTypes.values();
|
||||
final int[] biomes = new int[values.size()];
|
||||
final String qualifier;
|
||||
|
||||
|
@ -74,6 +74,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -710,7 +711,7 @@ public class RegionCommands extends MethodCommands {
|
||||
BiomeType biome = null;
|
||||
if (context.argsLength() >= 1) {
|
||||
BiomeRegistry biomeRegistry = worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
|
||||
List<BiomeType> knownBiomes = BiomeTypes.values();
|
||||
Collection<BiomeType> knownBiomes = BiomeTypes.values();
|
||||
biome = Biomes.findBiomeByName(knownBiomes, context.getString(0), biomeRegistry);
|
||||
}
|
||||
Long seed = context.argsLength() != 2 || !MathMan.isInteger(context.getString(1)) ? null : Long.parseLong(context.getString(1));
|
||||
|
@ -22,7 +22,7 @@ package com.sk89q.worldedit.registry;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class Category<T> {
|
||||
public abstract class Category<T> implements RegistryItem {
|
||||
private final Set<T> set = new HashSet<>();
|
||||
protected final String id;
|
||||
private boolean empty = true;
|
||||
@ -43,6 +43,18 @@ public abstract class Category<T> {
|
||||
return this.set;
|
||||
}
|
||||
|
||||
private int internalId;
|
||||
|
||||
@Override
|
||||
public void setInternalId(int internalId) {
|
||||
this.internalId = internalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInternalId() {
|
||||
return internalId;
|
||||
}
|
||||
|
||||
protected abstract Set<T> load();
|
||||
|
||||
/**
|
||||
|
@ -22,11 +22,15 @@ package com.sk89q.worldedit.registry;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class NamespacedRegistry<V> extends Registry<V> {
|
||||
public final class NamespacedRegistry<V extends RegistryItem> extends Registry<V> {
|
||||
private static final String MINECRAFT_NAMESPACE = "minecraft";
|
||||
|
||||
private final String defaultNamespace;
|
||||
private final List<V> values = new ArrayList<>();
|
||||
private int lastInternalId = 0;
|
||||
|
||||
public NamespacedRegistry(final String name) {
|
||||
this(name, MINECRAFT_NAMESPACE);
|
||||
@ -37,14 +41,33 @@ public final class NamespacedRegistry<V> extends Registry<V> {
|
||||
this.defaultNamespace = defaultNamespace;
|
||||
}
|
||||
|
||||
public @Nullable V get(final String key) {
|
||||
return super.get(this.orDefaultNamespace(key));
|
||||
public synchronized V register(final String key, final V value) {
|
||||
requireNonNull(key, "key");
|
||||
int index = key.indexOf(':');
|
||||
checkState(index > -1, "key is not namespaced");
|
||||
V existing = super.get(key);
|
||||
if (existing != null) {
|
||||
throw new UnsupportedOperationException("Replacing existing registrations is not supported");
|
||||
}
|
||||
value.setInternalId(lastInternalId++);
|
||||
values.add(value);
|
||||
super.register(key, value);
|
||||
if (key.startsWith(defaultNamespace)) {
|
||||
super.register(key.substring(index), value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public V register(final String key, final V value) {
|
||||
requireNonNull(key, "key");
|
||||
checkState(key.indexOf(':') > -1, "key is not namespaced");
|
||||
return super.register(key, value);
|
||||
public V getByInternalId(int index) {
|
||||
return values.get(index);
|
||||
}
|
||||
|
||||
public int getInternalId(V value) {
|
||||
return value.getInternalId();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return values.size();
|
||||
}
|
||||
|
||||
private String orDefaultNamespace(final String key) {
|
||||
|
@ -33,17 +33,21 @@ import javax.annotation.Nullable;
|
||||
|
||||
public class Registry<V> implements Iterable<V> {
|
||||
private final Map<String, V> map = new HashMap<>();
|
||||
private Collection<V> values = Collections.unmodifiableCollection(map.values());
|
||||
private final String name;
|
||||
|
||||
public Registry(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public @Nullable V get(final String key) {
|
||||
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
|
||||
public @Nullable V get(final CharSequence key) {
|
||||
return this.map.get(key);
|
||||
}
|
||||
|
||||
public @Nullable V get(final String key) {
|
||||
return get((CharSequence) key);
|
||||
}
|
||||
|
||||
public V register(final String key, final V value) {
|
||||
requireNonNull(key, "key");
|
||||
requireNonNull(value, "value");
|
||||
@ -58,12 +62,11 @@ public class Registry<V> implements Iterable<V> {
|
||||
}
|
||||
|
||||
public Collection<V> values() {
|
||||
return Collections.unmodifiableCollection(this.map.values());
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<V> iterator() {
|
||||
return this.map.values().iterator();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.sk89q.worldedit.registry;
|
||||
|
||||
public interface RegistryItem {
|
||||
void setInternalId(int internalId);
|
||||
|
||||
int getInternalId();
|
||||
}
|
@ -19,22 +19,29 @@
|
||||
|
||||
package com.sk89q.worldedit.world.biome;
|
||||
|
||||
import com.sk89q.worldedit.registry.RegistryItem;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
|
||||
/**
|
||||
* All the types of biomes in the game.
|
||||
*/
|
||||
public class BiomeType {
|
||||
public class BiomeType implements RegistryItem {
|
||||
|
||||
public static final NamespacedRegistry<BiomeType> REGISTRY = new NamespacedRegistry<>("biome type");
|
||||
private final int internalId;
|
||||
private final String id;
|
||||
|
||||
protected BiomeType(String id, int internalId) {
|
||||
public BiomeType(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private int internalId;
|
||||
|
||||
@Override
|
||||
public void setInternalId(int internalId) {
|
||||
this.internalId = internalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInternalId() {
|
||||
return internalId;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.biome;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -107,28 +108,15 @@ public class BiomeTypes {
|
||||
private BiomeTypes() {
|
||||
}
|
||||
|
||||
private static List<BiomeType> biomes = new ArrayList<>();
|
||||
private static List<BiomeType> biomesLocked = Collections.unmodifiableList(biomes);
|
||||
|
||||
private static BiomeType register(final String id) {
|
||||
BiomeType biome = new BiomeType(id, biomes.size());
|
||||
biomes.add(biome);
|
||||
return register(biome);
|
||||
}
|
||||
|
||||
public static BiomeType register(final BiomeType biome) {
|
||||
return BiomeType.REGISTRY.register(biome.getId(), biome);
|
||||
}
|
||||
|
||||
public static @Nullable BiomeType get(final String id) {
|
||||
return BiomeType.REGISTRY.get(id);
|
||||
}
|
||||
|
||||
public static BiomeType get(int internalId) {
|
||||
return biomes.get(internalId);
|
||||
return BiomeType.REGISTRY.getByInternalId(internalId);
|
||||
}
|
||||
|
||||
public static List<BiomeType> values() {
|
||||
return biomesLocked;
|
||||
public static Collection<BiomeType> values() {
|
||||
return BiomeType.REGISTRY.values();
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
|
||||
// Suggest property
|
||||
String input = charSequence.toString();
|
||||
BlockType finalType = type;
|
||||
throw new SuggestInputParseException("Invalid property " + type + " | " + input, input, () ->
|
||||
throw new SuggestInputParseException("Invalid property " + charSequence + ":" + input + " for type " + type, input, () ->
|
||||
finalType.getProperties().stream()
|
||||
.map(p -> p.getName())
|
||||
.filter(p -> p.startsWith(input))
|
||||
|
@ -29,6 +29,7 @@ import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
|
||||
import com.sk89q.worldedit.function.pattern.FawePattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
@ -48,10 +49,13 @@ public class BlockType implements FawePattern {
|
||||
private final String id;
|
||||
private final BlockTypes.Settings settings;
|
||||
|
||||
private boolean initItemType;
|
||||
private ItemType itemType;
|
||||
|
||||
protected BlockType(String id, int internalId, List<BlockState> states) {
|
||||
this.settings = new BlockTypes.Settings(this, id, internalId, states);
|
||||
int i = id.indexOf("[");
|
||||
this.id = i == -1 ? id : id.substring(0, i);
|
||||
this.settings = new BlockTypes.Settings(this, id, internalId, states);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ -94,9 +98,9 @@ public class BlockType implements FawePattern {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BlockState withPropertyId(int internalPropertiesId) {
|
||||
if (internalPropertiesId == 0) return getDefaultState();
|
||||
return BlockState.getFromInternalId(getInternalId() + (internalPropertiesId << BlockTypes.BIT_OFFSET));
|
||||
public BlockState withPropertyId(int propertyId) {
|
||||
if (settings.stateOrdinals == null) return settings.defaultState;
|
||||
return BlockTypes.states[settings.stateOrdinals[propertyId]];
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ -237,7 +241,11 @@ public class BlockType implements FawePattern {
|
||||
*/
|
||||
@Nullable
|
||||
public ItemType getItemType() {
|
||||
return settings.itemType;
|
||||
if(!initItemType) {
|
||||
initItemType = true;
|
||||
itemType = ItemTypes.get(getId());
|
||||
}
|
||||
return itemType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
@ -19,9 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.world.entity;
|
||||
|
||||
import com.sk89q.worldedit.registry.RegistryItem;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
|
||||
public class EntityType {
|
||||
public class EntityType implements RegistryItem {
|
||||
|
||||
public static final NamespacedRegistry<EntityType> REGISTRY = new NamespacedRegistry<>("entity type");
|
||||
|
||||
@ -39,6 +40,18 @@ public class EntityType {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
private int internalId;
|
||||
|
||||
@Override
|
||||
public void setInternalId(int internalId) {
|
||||
this.internalId = internalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInternalId() {
|
||||
return internalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this item, or the ID if the name cannot be found.
|
||||
*
|
||||
|
@ -19,13 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.world.fluid;
|
||||
|
||||
import com.sk89q.worldedit.registry.RegistryItem;
|
||||
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 class FluidType implements RegistryItem {
|
||||
|
||||
public static final NamespacedRegistry<FluidType> REGISTRY = new NamespacedRegistry<>("fluid type");
|
||||
|
||||
@ -44,6 +45,18 @@ public class FluidType {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
private int internalId;
|
||||
|
||||
@Override
|
||||
public void setInternalId(int internalId) {
|
||||
this.internalId = internalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInternalId() {
|
||||
return internalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getId();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
public void setInternalId(int 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();
|
||||
}
|
||||
}
|
||||
|
@ -343,14 +343,14 @@
|
||||
"51:14": "minecraft:fire[east=false,south=false,north=false,west=false,up=false,age=14]",
|
||||
"51:15": "minecraft:fire[east=false,south=false,north=false,west=false,up=false,age=15]",
|
||||
"52:0": "minecraft:spawner",
|
||||
"53:0": "minecraft:oak_stairs[half=bottom,shape=straight,facing=east]",
|
||||
"53:1": "minecraft:oak_stairs[half=bottom,shape=straight,facing=west]",
|
||||
"53:2": "minecraft:oak_stairs[half=bottom,shape=straight,facing=south]",
|
||||
"53:3": "minecraft:oak_stairs[half=bottom,shape=straight,facing=north]",
|
||||
"53:4": "minecraft:oak_stairs[half=top,shape=straight,facing=east]",
|
||||
"53:5": "minecraft:oak_stairs[half=top,shape=straight,facing=west]",
|
||||
"53:6": "minecraft:oak_stairs[half=top,shape=straight,facing=south]",
|
||||
"53:7": "minecraft:oak_stairs[half=top,shape=straight,facing=north]",
|
||||
"53:0": "minecraft:oak_stairs[half=bottom,shape=outer_right,facing=east]",
|
||||
"53:1": "minecraft:oak_stairs[half=bottom,shape=outer_right,facing=west]",
|
||||
"53:2": "minecraft:oak_stairs[half=bottom,shape=outer_right,facing=south]",
|
||||
"53:3": "minecraft:oak_stairs[half=bottom,shape=outer_right,facing=north]",
|
||||
"53:4": "minecraft:oak_stairs[half=top,shape=outer_right,facing=east]",
|
||||
"53:5": "minecraft:oak_stairs[half=top,shape=outer_right,facing=west]",
|
||||
"53:6": "minecraft:oak_stairs[half=top,shape=outer_right,facing=south]",
|
||||
"53:7": "minecraft:oak_stairs[half=top,shape=outer_right,facing=north]",
|
||||
"54:0": "minecraft:chest",
|
||||
"54:2": "minecraft:chest[facing=north,type=single]",
|
||||
"54:3": "minecraft:chest[facing=south,type=single]",
|
||||
@ -404,7 +404,7 @@
|
||||
"61:11": "minecraft:furnace[facing=south,lit=false]",
|
||||
"61:12": "minecraft:furnace[facing=west,lit=false]",
|
||||
"61:13": "minecraft:furnace[facing=east,lit=false]",
|
||||
"62:0": "minecraft:lit_furnace",
|
||||
"62:0": "minecraft:furnace[lit=true]",
|
||||
"62:2": "minecraft:furnace[facing=north,lit=true]",
|
||||
"62:3": "minecraft:furnace[facing=south,lit=true]",
|
||||
"62:4": "minecraft:furnace[facing=west,lit=true]",
|
||||
@ -521,7 +521,7 @@
|
||||
"75:10": "minecraft:redstone_wall_torch[facing=west,lit=false]",
|
||||
"75:11": "minecraft:redstone_wall_torch[facing=south,lit=false]",
|
||||
"75:12": "minecraft:redstone_wall_torch[facing=north,lit=false]",
|
||||
"75:13": "minecraft:redstone_wall_torch[facing=up,lit=false]",
|
||||
"75:13": "minecraft:redstone_wall_torch[lit=false]",
|
||||
"76:0": "minecraft:redstone_torch[lit=true]",
|
||||
"76:1": "minecraft:redstone_wall_torch[facing=east,lit=true]",
|
||||
"76:2": "minecraft:redstone_wall_torch[facing=west,lit=true]",
|
||||
@ -532,7 +532,7 @@
|
||||
"76:10": "minecraft:redstone_wall_torch[facing=west,lit=true]",
|
||||
"76:11": "minecraft:redstone_wall_torch[facing=south,lit=true]",
|
||||
"76:12": "minecraft:redstone_wall_torch[facing=north,lit=true]",
|
||||
"76:13": "minecraft:redstone_wall_torch[facing=up,lit=true]",
|
||||
"76:13": "minecraft:redstone_wall_torch[lit=true]",
|
||||
"77:0": "minecraft:stone_button[powered=false,facing=east,face=ceiling]",
|
||||
"77:1": "minecraft:stone_button[powered=false,facing=east,face=wall]",
|
||||
"77:2": "minecraft:stone_button[powered=false,facing=west,face=wall]",
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren