3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 10:30:04 +01:00

Few minor improvements to the fuzzy system.

Dieser Commit ist enthalten in:
Matthew Miller 2018-12-28 15:05:05 +10:00
Ursprung b544782f3b
Commit 54b6e57186
2 geänderte Dateien mit 20 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -129,8 +129,7 @@ public class BlockState implements BlockStateHolder<BlockState> {
@Override
public <V> BlockState with(final Property<V> property, final V value) {
BlockState result = states.get(property, value);
return result == null ? this : result;
return states.row(property).getOrDefault(value, this);
}
@Override

Datei anzeigen

@ -37,6 +37,13 @@ public class FuzzyBlockState extends BlockState {
super(blockType);
}
private FuzzyBlockState(BlockType blockType, Map<Property<?>, Object> values) {
this(blockType);
for (Map.Entry<Property<?>, Object> entry : values.entrySet()) {
setState(entry.getKey(), entry.getValue());
}
}
/**
* Gets a full BlockState from this fuzzy one, filling in
* properties with default values where necessary.
@ -46,8 +53,9 @@ public class FuzzyBlockState extends BlockState {
public BlockState getFullState() {
BlockState state = getBlockType().getDefaultState();
for (Map.Entry<Property<?>, Object> entry : getStates().entrySet()) {
//noinspection unchecked
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();
}
@ -65,7 +73,7 @@ public class FuzzyBlockState extends BlockState {
* Builder for FuzzyBlockState
*/
public static class Builder {
private BlockState internalState;
private BlockType type;
private Map<Property<?>, Object> values = new HashMap<>();
/**
@ -76,7 +84,7 @@ public class FuzzyBlockState extends BlockState {
*/
public Builder type(BlockType type) {
checkNotNull(type);
internalState = type.getDefaultState();
this.type = type;
return this;
}
@ -88,7 +96,7 @@ public class FuzzyBlockState extends BlockState {
*/
public Builder type(BlockState state) {
checkNotNull(state);
internalState = state;
this.type = state.getBlockType();
return this;
}
@ -103,7 +111,8 @@ public class FuzzyBlockState extends BlockState {
public <V> Builder withProperty(Property<V> property, V value) {
checkNotNull(property);
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);
return this;
}
@ -114,15 +123,11 @@ public class FuzzyBlockState extends BlockState {
* @return The fuzzy BlockState
*/
public FuzzyBlockState build() {
checkNotNull(internalState);
checkNotNull(type);
if (values.isEmpty()) {
return internalState.getBlockType().getFuzzyMatcher();
return type.getFuzzyMatcher();
}
FuzzyBlockState blockState = new FuzzyBlockState(internalState.getBlockType());
for (Map.Entry<Property<?>, Object> entry : values.entrySet()) {
blockState.setState(entry.getKey(), entry.getValue());
}
return blockState;
return new FuzzyBlockState(type, values);
}
/**
@ -131,7 +136,7 @@ public class FuzzyBlockState extends BlockState {
* @return The builder, for chaining
*/
public Builder reset() {
this.internalState = null;
this.type = null;
this.values.clear();
return this;
}