Switch from PropertyKey enum to class (#971)

* Switch from PropertyKey enum to class

* Fix generic toArray
This commit is contained in:
Hannes Greule
2021-03-14 20:38:11 +01:00
committed by GitHub
parent 786baf09f4
commit d974164204
8 changed files with 409 additions and 209 deletions

View File

@ -185,7 +185,7 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
stateId = property.modifyIndex(stateId, index);
} else {
// suggest
PropertyKey key = PropertyKey.get(charSequence);
PropertyKey key = PropertyKey.getByName(charSequence);
if (key == null || !type.hasProperty(key)) {
// Suggest property
String input = charSequence.toString();

View File

@ -181,13 +181,13 @@ public class BlockType implements Keyed, Pattern {
}
public boolean hasProperty(PropertyKey key) {
int ordinal = key.ordinal();
return this.settings.propertiesMapArr.length > ordinal ? this.settings.propertiesMapArr[ordinal] != null : false;
int ordinal = key.getId();
return this.settings.propertiesMapArr.length > ordinal && this.settings.propertiesMapArr[ordinal] != null;
}
public <V> Property<V> getProperty(PropertyKey key) {
try {
return (Property<V>) this.settings.propertiesMapArr[key.ordinal()];
return (Property<V>) this.settings.propertiesMapArr[key.getId()];
} catch (IndexOutOfBoundsException ignored) {
return null;
}

View File

@ -59,7 +59,7 @@ public class BlockTypesCache {
// Ensure the properties are registered
int maxOrdinal = 0;
for (String key : properties.keySet()) {
maxOrdinal = Math.max(PropertyKey.getOrCreate(key).ordinal(), maxOrdinal);
maxOrdinal = Math.max(PropertyKey.getOrCreate(key).getId(), maxOrdinal);
}
this.propertiesMapArr = new AbstractProperty[maxOrdinal + 1];
int prop_arr_i = 0;
@ -70,7 +70,7 @@ public class BlockTypesCache {
for (Map.Entry<String, ? extends Property<?>> entry : properties.entrySet()) {
PropertyKey key = PropertyKey.getOrCreate(entry.getKey());
AbstractProperty<?> property = ((AbstractProperty) entry.getValue()).withOffset(bitOffset);
this.propertiesMapArr[key.ordinal()] = property;
this.propertiesMapArr[key.getId()] = property;
this.propertiesArr[prop_arr_i++] = property;
propMap.put(entry.getKey(), property);