Dieser Commit ist enthalten in:
Jesse Boyd 2019-04-05 15:15:10 +11:00
Ursprung 95c819684c
Commit 140809c903
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
20 geänderte Dateien mit 851 neuen und 734 gelöschten Zeilen

Datei anzeigen

@ -34,17 +34,26 @@ import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader; import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.PlatformReadyEvent; 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.Actor;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.NoCapablePlatformException; import com.sk89q.worldedit.extension.platform.NoCapablePlatformException;
import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.inventory.BlockBag; 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.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.ItemCategory;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Tag; import org.bukkit.Tag;
import org.bukkit.block.Biome;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -149,6 +158,7 @@ public class WorldEditPlugin extends JavaPlugin //implements TabCompleter
@Override @Override
public void onLoad() { public void onLoad() {
if (INSTANCE != null) return;
rename(); rename();
this.INSTANCE = this; this.INSTANCE = this;
FaweBukkit imp = new FaweBukkit(this); FaweBukkit imp = new FaweBukkit(this);
@ -162,11 +172,9 @@ public class WorldEditPlugin extends JavaPlugin //implements TabCompleter
server = new BukkitServerInterface(this, getServer()); server = new BukkitServerInterface(this, getServer());
worldEdit.getPlatformManager().register(server); worldEdit.getPlatformManager().register(server);
loadAdapter(); // Need an adapter to work with special blocks with NBT data loadAdapter(); // Need an adapter to work with special blocks with NBT data
worldEdit.loadMappings();
loadConfig(); // Load configuration loadConfig(); // Load configuration
fail(() -> PermissionsResolverManager.initialize(INSTANCE), "Failed to initialize permissions resolver"); fail(() -> PermissionsResolverManager.initialize(INSTANCE), "Failed to initialize permissions resolver");
} }
/** /**
@ -174,7 +182,11 @@ public class WorldEditPlugin extends JavaPlugin //implements TabCompleter
*/ */
@Override @Override
public void onEnable() { 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 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 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() { private void setupTags() {
// Tags // Tags
try { try {
@ -245,18 +299,18 @@ public class WorldEditPlugin extends JavaPlugin //implements TabCompleter
} }
} }
} }
{ // {
java.util.logging.Logger logger = getLogger(); // java.util.logging.Logger logger = getLogger();
if (logger != null) { // if (logger != null) {
try { // try {
Field nameField = Logger.class.getDeclaredField("name"); // Field nameField = Logger.class.getDeclaredField("name");
nameField.setAccessible(true); // nameField.setAccessible(true);
nameField.set(logger, "FastAsyncWorldEdit"); // nameField.set(logger, "FastAsyncWorldEdit");
} catch (Throwable ignore) { // } catch (Throwable ignore) {
ignore.printStackTrace(); // ignore.printStackTrace();
} // }
} // }
} // }
{ {
File pluginsFolder = MainUtil.getJarFile().getParentFile(); File pluginsFolder = MainUtil.getJarFile().getParentFile();
for (File file : pluginsFolder.listFiles()) { for (File file : pluginsFolder.listFiles()) {

Datei anzeigen

@ -19,6 +19,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
import java.util.Collection;
import java.util.List; import java.util.List;
// TODO FIXME // TODO FIXME
@ -95,7 +96,7 @@ public class FaweLocalBlockQueue extends LocalBlockQueue {
if (reg == null) { if (reg == null) {
reg = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.USER_COMMANDS).getRegistries().getBiomeRegistry(); reg = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.USER_COMMANDS).getRegistries().getBiomeRegistry();
} }
List<BiomeType> biomes = BiomeTypes.values(); Collection<BiomeType> biomes = BiomeTypes.values();
lastBiome = biome; lastBiome = biome;
this.biome = Biomes.findBiomeByName(biomes, biome, reg); this.biome = Biomes.findBiomeByName(biomes, biome, reg);
} }

Datei anzeigen

@ -27,6 +27,8 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.biome.Biomes; import com.sk89q.worldedit.world.biome.Biomes;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -56,7 +58,7 @@ public class PlotSetBiome extends Command {
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage()); checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
final HashSet<RegionWrapper> regions = plot.getRegions(); final HashSet<RegionWrapper> regions = plot.getRegions();
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); 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); final BiomeType biome = Biomes.findBiomeByName(knownBiomes, args[0], biomeRegistry);
if (biome == null) { if (biome == null) {
String biomes = StringMan.join(WorldUtil.IMP.getBiomeList(), Captions.BLOCK_LIST_SEPARATER.s()); String biomes = StringMan.join(WorldUtil.IMP.getBiomeList(), Captions.BLOCK_LIST_SEPARATER.s());

Datei anzeigen

@ -107,7 +107,7 @@ public class BiomeCommands extends MethodCommands {
} }
BiomeRegistry biomeRegistry = getBiomeRegistry(); BiomeRegistry biomeRegistry = getBiomeRegistry();
List<BiomeType> biomes = BiomeTypes.values(); Collection<BiomeType> biomes = BiomeTypes.values();
int totalPages = biomes.size() / 19 + 1; int totalPages = biomes.size() / 19 + 1;
Message msg = BBC.BIOME_LIST_HEADER.m(page, totalPages); Message msg = BBC.BIOME_LIST_HEADER.m(page, totalPages);
String setBiome = Commands.getAlias(BiomeCommands.class, "/setbiome"); String setBiome = Commands.getAlias(BiomeCommands.class, "/setbiome");
@ -144,7 +144,7 @@ public class BiomeCommands extends MethodCommands {
@CommandPermissions("worldedit.biome.info") @CommandPermissions("worldedit.biome.info")
public void biomeInfo(Player player, LocalSession session, final EditSession editSession, CommandContext args) throws WorldEditException { public void biomeInfo(Player player, LocalSession session, final EditSession editSession, CommandContext args) throws WorldEditException {
BiomeRegistry biomeRegistry = getBiomeRegistry(); BiomeRegistry biomeRegistry = getBiomeRegistry();
List<BiomeType> values = BiomeTypes.values(); Collection<BiomeType> values = BiomeTypes.values();
final int[] biomes = new int[values.size()]; final int[] biomes = new int[values.size()];
final String qualifier; final String qualifier;

Datei anzeigen

@ -74,6 +74,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -710,7 +711,7 @@ public class RegionCommands extends MethodCommands {
BiomeType biome = null; BiomeType biome = null;
if (context.argsLength() >= 1) { if (context.argsLength() >= 1) {
BiomeRegistry biomeRegistry = worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); 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); biome = Biomes.findBiomeByName(knownBiomes, context.getString(0), biomeRegistry);
} }
Long seed = context.argsLength() != 2 || !MathMan.isInteger(context.getString(1)) ? null : Long.parseLong(context.getString(1)); Long seed = context.argsLength() != 2 || !MathMan.isInteger(context.getString(1)) ? null : Long.parseLong(context.getString(1));

Datei anzeigen

@ -22,7 +22,7 @@ package com.sk89q.worldedit.registry;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
public abstract class Category<T> { public abstract class Category<T> implements RegistryItem {
private final Set<T> set = new HashSet<>(); private final Set<T> set = new HashSet<>();
protected final String id; protected final String id;
private boolean empty = true; private boolean empty = true;
@ -43,6 +43,18 @@ public abstract class Category<T> {
return this.set; 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(); protected abstract Set<T> load();
/** /**

Datei anzeigen

@ -22,11 +22,15 @@ package com.sk89q.worldedit.registry;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull; 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 static final String MINECRAFT_NAMESPACE = "minecraft";
private final String defaultNamespace; private final String defaultNamespace;
private final List<V> values = new ArrayList<>();
private int lastInternalId = 0;
public NamespacedRegistry(final String name) { public NamespacedRegistry(final String name) {
this(name, MINECRAFT_NAMESPACE); this(name, MINECRAFT_NAMESPACE);
@ -37,14 +41,33 @@ public final class NamespacedRegistry<V> extends Registry<V> {
this.defaultNamespace = defaultNamespace; this.defaultNamespace = defaultNamespace;
} }
public @Nullable V get(final String key) { public synchronized V register(final String key, final V value) {
return super.get(this.orDefaultNamespace(key)); 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) { public V getByInternalId(int index) {
requireNonNull(key, "key"); return values.get(index);
checkState(key.indexOf(':') > -1, "key is not namespaced"); }
return super.register(key, value);
public int getInternalId(V value) {
return value.getInternalId();
}
public int size() {
return values.size();
} }
private String orDefaultNamespace(final String key) { private String orDefaultNamespace(final String key) {

Datei anzeigen

@ -33,17 +33,21 @@ import javax.annotation.Nullable;
public class Registry<V> implements Iterable<V> { public class Registry<V> implements Iterable<V> {
private final Map<String, V> map = new HashMap<>(); private final Map<String, V> map = new HashMap<>();
private Collection<V> values = Collections.unmodifiableCollection(map.values());
private final String name; private final String name;
public Registry(final String name) { public Registry(final String name) {
this.name = name; this.name = name;
} }
public @Nullable V get(final String key) { public @Nullable V get(final CharSequence key) {
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
return this.map.get(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) { public V register(final String key, final V value) {
requireNonNull(key, "key"); requireNonNull(key, "key");
requireNonNull(value, "value"); requireNonNull(value, "value");
@ -58,12 +62,11 @@ public class Registry<V> implements Iterable<V> {
} }
public Collection<V> values() { public Collection<V> values() {
return Collections.unmodifiableCollection(this.map.values()); return values;
} }
@Override @Override
public Iterator<V> iterator() { public Iterator<V> iterator() {
return this.map.values().iterator(); return this.map.values().iterator();
} }
} }

Datei anzeigen

@ -0,0 +1,7 @@
package com.sk89q.worldedit.registry;
public interface RegistryItem {
void setInternalId(int internalId);
int getInternalId();
}

Datei anzeigen

@ -19,22 +19,29 @@
package com.sk89q.worldedit.world.biome; package com.sk89q.worldedit.world.biome;
import com.sk89q.worldedit.registry.RegistryItem;
import com.sk89q.worldedit.registry.NamespacedRegistry; import com.sk89q.worldedit.registry.NamespacedRegistry;
/** /**
* All the types of biomes in the game. * 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"); public static final NamespacedRegistry<BiomeType> REGISTRY = new NamespacedRegistry<>("biome type");
private final int internalId;
private final String id; private final String id;
protected BiomeType(String id, int internalId) { public BiomeType(String id) {
this.id = id; this.id = id;
}
private int internalId;
@Override
public void setInternalId(int internalId) {
this.internalId = internalId; this.internalId = internalId;
} }
@Override
public int getInternalId() { public int getInternalId() {
return internalId; return internalId;
} }

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.biome;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -107,28 +108,15 @@ public class BiomeTypes {
private 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) { public static @Nullable BiomeType get(final String id) {
return BiomeType.REGISTRY.get(id); return BiomeType.REGISTRY.get(id);
} }
public static BiomeType get(int internalId) { public static BiomeType get(int internalId) {
return biomes.get(internalId); return BiomeType.REGISTRY.getByInternalId(internalId);
} }
public static List<BiomeType> values() { public static Collection<BiomeType> values() {
return biomesLocked; return BiomeType.REGISTRY.values();
} }
} }

Datei anzeigen

@ -180,7 +180,7 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
// Suggest property // Suggest property
String input = charSequence.toString(); String input = charSequence.toString();
BlockType finalType = type; 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() finalType.getProperties().stream()
.map(p -> p.getName()) .map(p -> p.getName())
.filter(p -> p.startsWith(input)) .filter(p -> p.startsWith(input))

Datei anzeigen

@ -29,6 +29,7 @@ import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
import com.sk89q.worldedit.function.pattern.FawePattern; import com.sk89q.worldedit.function.pattern.FawePattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.registry.NamespacedRegistry; import com.sk89q.worldedit.registry.NamespacedRegistry;
@ -48,10 +49,13 @@ public class BlockType implements FawePattern {
private final String id; private final String id;
private final BlockTypes.Settings settings; private final BlockTypes.Settings settings;
private boolean initItemType;
private ItemType itemType;
protected BlockType(String id, int internalId, List<BlockState> states) { protected BlockType(String id, int internalId, List<BlockState> states) {
this.settings = new BlockTypes.Settings(this, id, internalId, states);
int i = id.indexOf("["); int i = id.indexOf("[");
this.id = i == -1 ? id : id.substring(0, i); this.id = i == -1 ? id : id.substring(0, i);
this.settings = new BlockTypes.Settings(this, id, internalId, states);
} }
@Deprecated @Deprecated
@ -94,9 +98,9 @@ public class BlockType implements FawePattern {
} }
@Deprecated @Deprecated
public BlockState withPropertyId(int internalPropertiesId) { public BlockState withPropertyId(int propertyId) {
if (internalPropertiesId == 0) return getDefaultState(); if (settings.stateOrdinals == null) return settings.defaultState;
return BlockState.getFromInternalId(getInternalId() + (internalPropertiesId << BlockTypes.BIT_OFFSET)); return BlockTypes.states[settings.stateOrdinals[propertyId]];
} }
@Deprecated @Deprecated
@ -237,7 +241,11 @@ public class BlockType implements FawePattern {
*/ */
@Nullable @Nullable
public ItemType getItemType() { public ItemType getItemType() {
return settings.itemType; if(!initItemType) {
initItemType = true;
itemType = ItemTypes.get(getId());
}
return itemType;
} }
/** /**

Datei anzeigen

@ -19,9 +19,10 @@
package com.sk89q.worldedit.world.entity; package com.sk89q.worldedit.world.entity;
import com.sk89q.worldedit.registry.RegistryItem;
import com.sk89q.worldedit.registry.NamespacedRegistry; import com.sk89q.worldedit.registry.NamespacedRegistry;
public class EntityType { public class EntityType implements RegistryItem {
public static final NamespacedRegistry<EntityType> REGISTRY = new NamespacedRegistry<>("entity type"); public static final NamespacedRegistry<EntityType> REGISTRY = new NamespacedRegistry<>("entity type");
@ -39,6 +40,18 @@ public class EntityType {
return this.id; 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. * Gets the name of this item, or the ID if the name cannot be found.
* *

Datei anzeigen

@ -19,13 +19,14 @@
package com.sk89q.worldedit.world.fluid; package com.sk89q.worldedit.world.fluid;
import com.sk89q.worldedit.registry.RegistryItem;
import com.sk89q.worldedit.registry.NamespacedRegistry; import com.sk89q.worldedit.registry.NamespacedRegistry;
/** /**
* Minecraft now has a 'fluid' system. This is a * Minecraft now has a 'fluid' system. This is a
* stub class to represent what it may be in the future. * 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"); public static final NamespacedRegistry<FluidType> REGISTRY = new NamespacedRegistry<>("fluid type");
@ -44,6 +45,18 @@ public class FluidType {
return this.id; return this.id;
} }
private int internalId;
@Override
public void setInternalId(int internalId) {
this.internalId = internalId;
}
@Override
public int getInternalId() {
return internalId;
}
@Override @Override
public String toString() { public String toString() {
return getId(); return getId();

Datei anzeigen

@ -34,6 +34,7 @@ import java.util.Set;
public class ItemCategory extends Category<ItemType> { public class ItemCategory extends Category<ItemType> {
public static final NamespacedRegistry<ItemCategory> REGISTRY = new NamespacedRegistry<>("item tag"); public static final NamespacedRegistry<ItemCategory> REGISTRY = new NamespacedRegistry<>("item tag");
private int internalId;
public ItemCategory(final String id) { public ItemCategory(final String id) {
super(id); super(id);
@ -56,4 +57,5 @@ public class ItemCategory extends Category<ItemType> {
public boolean contains(BaseItem baseItem) { public boolean contains(BaseItem baseItem) {
return this.getAll().contains(baseItem.getType()); return this.getAll().contains(baseItem.getType());
} }
} }

Datei anzeigen

@ -22,40 +22,44 @@ package com.sk89q.worldedit.world.item;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.registry.RegistryItem;
import com.sk89q.worldedit.registry.NamespacedRegistry; import com.sk89q.worldedit.registry.NamespacedRegistry;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class ItemType { public class ItemType implements RegistryItem {
public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>("item type"); public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>("item type");
private String id; private String id;
private BlockType blockType; private BlockType blockType;
private int internalId; private boolean initBlockType;
private BaseItem defaultState; private BaseItem defaultState;
protected ItemType(String id) { public ItemType(String id) {
// If it has no namespace, assume minecraft. // If it has no namespace, assume minecraft.
if (!id.contains(":")) { if (!id.contains(":")) {
id = "minecraft:" + id; id = "minecraft:" + id;
} }
this.id = id; this.id = id;
this.blockType = BlockTypes.get(this.id);
} }
public String getId() { public String getId() {
return this.id; return this.id;
} }
public int getInternalId() { private int internalId;
return this.internalId;
} @Override
public void setInternalId(int internalId) { 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) { public void setBlockType(BlockType blockType) {
if (!initBlockType) {
initBlockType = true;
this.blockType = BlockTypes.get(this.id);
}
this.blockType = blockType; this.blockType = blockType;
} }

Datei anzeigen

@ -19,22 +19,12 @@
package com.sk89q.worldedit.world.item; 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.block.BlockType;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
import javax.annotation.Nullable;
import java.util.Collection;
public final class ItemTypes { public final class ItemTypes {
@Nullable public static final ItemType ACACIA_BOAT = get("minecraft:acacia_boat"); @Nullable public static final ItemType ACACIA_BOAT = get("minecraft:acacia_boat");
@ -831,24 +821,6 @@ public final class ItemTypes {
private 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 @Nullable
public static ItemType parse(String input) { public static ItemType parse(String input) {
input = input.toLowerCase(); input = input.toLowerCase();
@ -866,30 +838,20 @@ public final class ItemTypes {
return result; 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) { public static final @Nullable ItemType get(String id) {
return ItemType.REGISTRY.get(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 @Deprecated
public static final ItemType get(final int ordinal) { public static final ItemType get(final int ordinal) {
return values()[ordinal]; return ItemType.REGISTRY.getByInternalId(ordinal);
} }
public static int size() { public static int size() {
return values().length; return ItemType.REGISTRY.size();
}
public static Collection<ItemType> values() {
return ItemType.REGISTRY.values();
} }
} }

Datei anzeigen

@ -343,14 +343,14 @@
"51:14": "minecraft:fire[east=false,south=false,north=false,west=false,up=false,age=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]", "51:15": "minecraft:fire[east=false,south=false,north=false,west=false,up=false,age=15]",
"52:0": "minecraft:spawner", "52:0": "minecraft:spawner",
"53:0": "minecraft:oak_stairs[half=bottom,shape=straight,facing=east]", "53:0": "minecraft:oak_stairs[half=bottom,shape=outer_right,facing=east]",
"53:1": "minecraft:oak_stairs[half=bottom,shape=straight,facing=west]", "53:1": "minecraft:oak_stairs[half=bottom,shape=outer_right,facing=west]",
"53:2": "minecraft:oak_stairs[half=bottom,shape=straight,facing=south]", "53:2": "minecraft:oak_stairs[half=bottom,shape=outer_right,facing=south]",
"53:3": "minecraft:oak_stairs[half=bottom,shape=straight,facing=north]", "53:3": "minecraft:oak_stairs[half=bottom,shape=outer_right,facing=north]",
"53:4": "minecraft:oak_stairs[half=top,shape=straight,facing=east]", "53:4": "minecraft:oak_stairs[half=top,shape=outer_right,facing=east]",
"53:5": "minecraft:oak_stairs[half=top,shape=straight,facing=west]", "53:5": "minecraft:oak_stairs[half=top,shape=outer_right,facing=west]",
"53:6": "minecraft:oak_stairs[half=top,shape=straight,facing=south]", "53:6": "minecraft:oak_stairs[half=top,shape=outer_right,facing=south]",
"53:7": "minecraft:oak_stairs[half=top,shape=straight,facing=north]", "53:7": "minecraft:oak_stairs[half=top,shape=outer_right,facing=north]",
"54:0": "minecraft:chest", "54:0": "minecraft:chest",
"54:2": "minecraft:chest[facing=north,type=single]", "54:2": "minecraft:chest[facing=north,type=single]",
"54:3": "minecraft:chest[facing=south,type=single]", "54:3": "minecraft:chest[facing=south,type=single]",
@ -404,7 +404,7 @@
"61:11": "minecraft:furnace[facing=south,lit=false]", "61:11": "minecraft:furnace[facing=south,lit=false]",
"61:12": "minecraft:furnace[facing=west,lit=false]", "61:12": "minecraft:furnace[facing=west,lit=false]",
"61:13": "minecraft:furnace[facing=east,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:2": "minecraft:furnace[facing=north,lit=true]",
"62:3": "minecraft:furnace[facing=south,lit=true]", "62:3": "minecraft:furnace[facing=south,lit=true]",
"62:4": "minecraft:furnace[facing=west,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:10": "minecraft:redstone_wall_torch[facing=west,lit=false]",
"75:11": "minecraft:redstone_wall_torch[facing=south,lit=false]", "75:11": "minecraft:redstone_wall_torch[facing=south,lit=false]",
"75:12": "minecraft:redstone_wall_torch[facing=north,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:0": "minecraft:redstone_torch[lit=true]",
"76:1": "minecraft:redstone_wall_torch[facing=east,lit=true]", "76:1": "minecraft:redstone_wall_torch[facing=east,lit=true]",
"76:2": "minecraft:redstone_wall_torch[facing=west,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:10": "minecraft:redstone_wall_torch[facing=west,lit=true]",
"76:11": "minecraft:redstone_wall_torch[facing=south,lit=true]", "76:11": "minecraft:redstone_wall_torch[facing=south,lit=true]",
"76:12": "minecraft:redstone_wall_torch[facing=north,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:0": "minecraft:stone_button[powered=false,facing=east,face=ceiling]",
"77:1": "minecraft:stone_button[powered=false,facing=east,face=wall]", "77:1": "minecraft:stone_button[powered=false,facing=east,face=wall]",
"77:2": "minecraft:stone_button[powered=false,facing=west,face=wall]", "77:2": "minecraft:stone_button[powered=false,facing=west,face=wall]",