Rewrote block parsing, and further switch to BlockState

This commit is contained in:
Matthew Miller
2018-06-17 23:13:22 +10:00
parent 5f5a1797ad
commit 811f1d4433
13 changed files with 198 additions and 404 deletions

View File

@ -62,6 +62,7 @@ public interface World extends Extent {
* @param id the block ID
* @return true if the block ID is a valid one
*/
@Deprecated
boolean isValidBlockType(int id);
/**

View File

@ -196,7 +196,7 @@ public class BundledBlockData {
private String unlocalizedName;
public String localizedName;
private List<String> aliases;
private Map<String, SimpleState> states = new HashMap<>();
public Map<String, SimpleState> states = new HashMap<>();
private SimpleBlockMaterial material = new SimpleBlockMaterial();
}

View File

@ -23,6 +23,9 @@ import com.sk89q.worldedit.world.registry.state.value.SimpleStateValue;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
public class SimpleState<T extends SimpleStateValue> implements State<T> {
@ -41,4 +44,10 @@ public class SimpleState<T extends SimpleStateValue> implements State<T> {
public List<T> getValues() {
return Collections.unmodifiableList(values);
}
@Nullable
@Override
public T getValueFor(String string) {
return values.stream().filter(value -> Objects.equals(value.getData(), string)).findFirst().orElse(null);
}
}

View File

@ -23,6 +23,8 @@ import com.sk89q.worldedit.world.registry.state.value.SimpleStateValue;
import java.util.List;
import javax.annotation.Nullable;
/**
* Describes a state property of a block.
*
@ -38,4 +40,12 @@ public interface State<T extends SimpleStateValue> {
*/
List<T> getValues();
/**
* Gets the value for the given string, or null.
*
* @param string The string
* @return The value, or null
*/
@Nullable
T getValueFor(String string);
}