Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-26 02:50:06 +01:00
Few minor improvements to the fuzzy system.
Dieser Commit ist enthalten in:
Ursprung
b544782f3b
Commit
54b6e57186
@ -129,8 +129,7 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <V> BlockState with(final Property<V> property, final V value) {
|
public <V> BlockState with(final Property<V> property, final V value) {
|
||||||
BlockState result = states.get(property, value);
|
return states.row(property).getOrDefault(value, this);
|
||||||
return result == null ? this : result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,6 +37,13 @@ public class FuzzyBlockState extends BlockState {
|
|||||||
super(blockType);
|
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
|
* Gets a full BlockState from this fuzzy one, filling in
|
||||||
* properties with default values where necessary.
|
* properties with default values where necessary.
|
||||||
@ -46,8 +53,9 @@ public class FuzzyBlockState extends BlockState {
|
|||||||
public BlockState getFullState() {
|
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()) {
|
||||||
//noinspection unchecked
|
@SuppressWarnings("unchecked")
|
||||||
state = state.with((Property<Object>) entry.getKey(), entry.getValue());
|
Property<Object> objKey = (Property<Object>) entry.getKey();
|
||||||
|
state = state.with(objKey, entry.getValue());
|
||||||
}
|
}
|
||||||
return getBlockType().getDefaultState();
|
return getBlockType().getDefaultState();
|
||||||
}
|
}
|
||||||
@ -65,7 +73,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<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,7 +84,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +96,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +111,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;
|
||||||
}
|
}
|
||||||
@ -114,15 +123,11 @@ public class FuzzyBlockState extends BlockState {
|
|||||||
* @return The fuzzy BlockState
|
* @return The fuzzy BlockState
|
||||||
*/
|
*/
|
||||||
public FuzzyBlockState build() {
|
public FuzzyBlockState build() {
|
||||||
checkNotNull(internalState);
|
checkNotNull(type);
|
||||||
if (values.isEmpty()) {
|
if (values.isEmpty()) {
|
||||||
return internalState.getBlockType().getFuzzyMatcher();
|
return type.getFuzzyMatcher();
|
||||||
}
|
}
|
||||||
FuzzyBlockState blockState = new FuzzyBlockState(internalState.getBlockType());
|
return new FuzzyBlockState(type, values);
|
||||||
for (Map.Entry<Property<?>, Object> entry : values.entrySet()) {
|
|
||||||
blockState.setState(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
return blockState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,7 +136,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren