some adapter refactoring

This commit is contained in:
Jesse Boyd
2019-11-19 04:40:40 +00:00
parent 751765cc01
commit 1b07846746
30 changed files with 1855 additions and 4779 deletions

View File

@ -144,6 +144,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
BlockState state = null;
try {
String palettePart = fix(entry.getKey());
System.out.println("Read " + palettePart);
state = BlockState.get(palettePart);
} catch (InputParseException e) {
e.printStackTrace();

View File

@ -179,7 +179,7 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
// Suggest property
String input = charSequence.toString();
BlockType finalType = type;
throw new SuggestInputParseException("Invalid property " + charSequence + ":" + input + " for type " + type, input, () ->
throw new SuggestInputParseException("Invalid property " + key + ":" + input + " for type " + type, input, () ->
finalType.getProperties().stream()
.map(Property::getName)
.filter(p -> StringMan.blockStateMatches(input, p))
@ -196,6 +196,7 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
case '=': {
charSequence.setSubstring(last, i);
property = (AbstractProperty) type.getPropertyMap().get(charSequence);
if (property == null) System.out.println("No prop " + charSequence + " | " + type.getPropertyMap());
last = i + 1;
break;
}

View File

@ -741,6 +741,7 @@ public final class BlockTypes {
private static Field[] fieldsTmp;
private static JoinedCharSequence joined;
private static int initIndex = 0;
public static BlockType init() {
if (fieldsTmp == null) {
fieldsTmp = BlockTypes.class.getDeclaredFields();

View File

@ -176,7 +176,7 @@ public class BlockTypesCache {
Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS);
Registries registries = platform.getRegistries();
BlockRegistry blockReg = registries.getBlockRegistry();
Collection<String> blocks = blockReg.registerBlocks();
Collection<String> blocks = blockReg.values();
Map<String, String> blockMap = blocks.stream().collect(Collectors.toMap(item -> item.charAt(item.length() - 1) == ']' ? item.substring(0, item.indexOf('[')) : item, item -> item));
int size = blockMap.size();

View File

@ -0,0 +1,22 @@
package com.sk89q.worldedit.world.block;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.ItemRegistry;
import com.sk89q.worldedit.world.registry.Registries;
public final class ItemTypesCache {
public static void init() {}
static {
Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS);
Registries registries = platform.getRegistries();
ItemRegistry itemReg = registries.getItemRegistry();
for (String key : itemReg.values()) {
ItemType item = new ItemType(key);
ItemType.REGISTRY.register(key, item);
}
}
}

View File

@ -77,7 +77,7 @@ public interface BlockRegistry {
/**
* Register all blocks
*/
default Collection<String> registerBlocks() {
default Collection<String> values() {
return Collections.emptyList();
}
}

View File

@ -22,6 +22,8 @@ package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.world.item.ItemType;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
public interface ItemRegistry {
@ -34,4 +36,10 @@ public interface ItemRegistry {
@Nullable
String getName(ItemType itemType);
/**
* Register all items
*/
default Collection<String> values() {
return Collections.emptyList();
}
}