Clarify state when asking for caps with no platforms (+ fuzzy system changes)

This commit is contained in:
Kenzie Togami 2018-12-28 22:20:12 -08:00 committed by IronApollo
parent 7d7da78dbc
commit 8f11d0469b
3 changed files with 40 additions and 18 deletions

View File

@ -170,8 +170,13 @@ public class PlatformManager {
if (platform != null) { if (platform != null) {
return platform; return platform;
} else { } else {
if (preferences.isEmpty() && !platforms.isEmpty()) { if (preferences.isEmpty()) {
return platforms.get(0); // Use the first available if preferences have not been decided yet. // Use the first available if preferences have not been decided yet.
if (platforms.isEmpty()) {
// No platforms registered, this is being called too early!
throw new NoCapablePlatformException("No platforms have been registered yet! Please wait until WorldEdit is initialized.");
}
return platforms.get(0);
} }
throw new NoCapablePlatformException("No platform was found supporting " + capability.name()); throw new NoCapablePlatformException("No platform was found supporting " + capability.name());
} }

View File

@ -216,6 +216,10 @@ public class BlockType implements FawePattern {
} }
return defaultState; return defaultState;
} }
public FuzzyBlockState getFuzzyMatcher() {
return new FuzzyBlockState(this);
}
/** /**
* Slow * Slow

View File

@ -37,12 +37,26 @@ public class FuzzyBlockState extends BlockState {
super(blockType); super(blockType);
} }
@SuppressWarnings("unchecked") private FuzzyBlockState(BlockType blockType, Map<Property<?>, Object> values) {
@Override this(blockType);
public BlockState toImmutableState() { for (Map.Entry<Property<?>, Object> entry : values.entrySet()) {
// setState(entry.getKey(), entry.getValue());
with((Property<Object>)entry.getKey(), entry.getValue());
}
}
/**
* Gets a full BlockState from this fuzzy one, filling in
* properties with default values where necessary.
*
* @return The full BlockState
*/
public BlockState getFullState() {
BlockState state = getBlockType().getDefaultState(); BlockState state = getBlockType().getDefaultState();
for (Map.Entry<Property<?>, Object> entry : getStates().entrySet()) { for (Map.Entry<Property<?>, Object> entry : getStates().entrySet()) {
state = state.with((Property<Object>) entry.getKey(), entry.getValue()); @SuppressWarnings("unchecked")
Property<Object> objKey = (Property<Object>) entry.getKey();
state = state.with(objKey, entry.getValue());
} }
return getBlockType().getDefaultState(); return getBlockType().getDefaultState();
} }
@ -60,7 +74,7 @@ public class FuzzyBlockState extends BlockState {
* Builder for FuzzyBlockState * Builder for FuzzyBlockState
*/ */
public static class Builder { public static class Builder {
private BlockState internalState; private BlockType type;
private Map<Property<?>, Object> values = new HashMap<>(); private Map<Property<?>, Object> values = new HashMap<>();
/** /**
@ -71,7 +85,7 @@ public class FuzzyBlockState extends BlockState {
*/ */
public Builder type(BlockType type) { public Builder type(BlockType type) {
checkNotNull(type); checkNotNull(type);
internalState = type.getDefaultState(); this.type = type;
return this; return this;
} }
@ -83,7 +97,7 @@ public class FuzzyBlockState extends BlockState {
*/ */
public Builder type(BlockState state) { public Builder type(BlockState state) {
checkNotNull(state); checkNotNull(state);
internalState = state; this.type = state.getBlockType();
return this; return this;
} }
@ -98,7 +112,8 @@ public class FuzzyBlockState extends BlockState {
public <V> Builder withProperty(Property<V> property, V value) { public <V> Builder withProperty(Property<V> property, V value) {
checkNotNull(property); checkNotNull(property);
checkNotNull(value); checkNotNull(value);
checkNotNull(internalState, "The type must be set before the properties!"); checkNotNull(type, "The type must be set before the properties!");
type.getProperty(property.getName()); // Verify the property is valid for this type
values.put(property, value); values.put(property, value);
return this; return this;
} }
@ -109,13 +124,11 @@ public class FuzzyBlockState extends BlockState {
* @return The fuzzy BlockState * @return The fuzzy BlockState
*/ */
public FuzzyBlockState build() { public FuzzyBlockState build() {
checkNotNull(internalState); checkNotNull(type);
FuzzyBlockState blockState = new FuzzyBlockState(internalState.getBlockType()); if (values.isEmpty()) {
for (Map.Entry<Property<?>, Object> entry : values.entrySet()) { return type.getFuzzyMatcher();
// blockState.setState(entry.getKey(), entry.getValue());
blockState = (FuzzyBlockState) blockState.with((Property<Object>) entry.getKey(), entry.getValue());
} }
return blockState; return new FuzzyBlockState(type, values);
} }
/** /**
@ -124,9 +137,9 @@ public class FuzzyBlockState extends BlockState {
* @return The builder, for chaining * @return The builder, for chaining
*/ */
public Builder reset() { public Builder reset() {
this.internalState = null; this.type = null;
this.values.clear(); this.values.clear();
return this; return this;
} }
} }
} }