mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
State system is done. It works. Finally. Still a few rough edges that need fixing however.
This commit is contained in:
parent
6b5f218809
commit
c3d832c3fd
@ -82,6 +82,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
|
|
||||||
WorldEdit worldEdit = WorldEdit.getInstance();
|
WorldEdit worldEdit = WorldEdit.getInstance();
|
||||||
|
|
||||||
|
loadAdapter(); // Need an adapter to work with special blocks with NBT data
|
||||||
|
|
||||||
// Setup platform
|
// Setup platform
|
||||||
server = new BukkitServerInterface(this, getServer());
|
server = new BukkitServerInterface(this, getServer());
|
||||||
worldEdit.getPlatformManager().register(server);
|
worldEdit.getPlatformManager().register(server);
|
||||||
@ -101,8 +103,6 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
// Forge WorldEdit and there's (probably) not going to be any other
|
// Forge WorldEdit and there's (probably) not going to be any other
|
||||||
// platforms to be worried about... at the current time of writing
|
// platforms to be worried about... at the current time of writing
|
||||||
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
|
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
|
||||||
|
|
||||||
loadAdapter(); // Need an adapter to work with special blocks with NBT data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfig() {
|
private void loadConfig() {
|
||||||
|
Binary file not shown.
@ -164,8 +164,10 @@ class DefaultBlockParser extends InputParser<BlockStateHolder> {
|
|||||||
if (propertyKey == null) {
|
if (propertyKey == null) {
|
||||||
throw new NoMatchException("Unknown state " + parts[0] + " for block " + state.getBlockType().getName());
|
throw new NoMatchException("Unknown state " + parts[0] + " for block " + state.getBlockType().getName());
|
||||||
}
|
}
|
||||||
Object value = propertyKey.getValueFor(parts[1]);
|
Object value;
|
||||||
if (value == null) {
|
try {
|
||||||
|
value = propertyKey.getValueFor(parts[1]);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
throw new NoMatchException("Unknown value " + parts[1] + " for state " + parts[0]);
|
throw new NoMatchException("Unknown value " + parts[1] + " for state " + parts[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,9 @@ package com.sk89q.worldedit.registry.state;
|
|||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class AbstractProperty<T> implements Property<T> {
|
public abstract class AbstractProperty<T> implements Property<T> {
|
||||||
|
@ -34,7 +34,7 @@ public class DirectionalProperty extends AbstractProperty<Direction> {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Direction getValueFor(final String string) {
|
public Direction getValueFor(final String string) {
|
||||||
Direction direction = Direction.valueOf(string);
|
Direction direction = Direction.valueOf(string.toUpperCase());
|
||||||
if (!getValues().contains(direction)) {
|
if (!getValues().contains(direction)) {
|
||||||
throw new IllegalArgumentException("Invalid direction value: " + string + ". Must be in " + getValues().toString());
|
throw new IllegalArgumentException("Invalid direction value: " + string + ". Must be in " + getValues().toString());
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,12 @@ import com.google.common.collect.HashBasedTable;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Table;
|
import com.google.common.collect.Table;
|
||||||
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.registry.state.Property;
|
import com.sk89q.worldedit.registry.state.Property;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -66,20 +68,29 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Map<Map<Property<?>, Object>, BlockState> generateStateMap(BlockType blockType) {
|
public static Map<Map<Property<?>, Object>, BlockState> generateStateMap(BlockType blockType) {
|
||||||
List<? extends Property> properties = blockType.getProperties();
|
|
||||||
List<List<Object>> valueLists = Lists.cartesianProduct(properties.stream().map(Property::getValues).collect(Collectors.toList()));
|
|
||||||
Map<Map<Property<?>, Object>, BlockState> stateMap = new LinkedHashMap<>();
|
Map<Map<Property<?>, Object>, BlockState> stateMap = new LinkedHashMap<>();
|
||||||
for (int i = 0; i < valueLists.size(); i++) {
|
List<? extends Property> properties = blockType.getProperties();
|
||||||
List<Object> valueList = valueLists.get(i);
|
|
||||||
Property<?> property = properties.get(i);
|
if (!properties.isEmpty()) {
|
||||||
LinkedHashMap<Property<?>, Object> valueMap = new LinkedHashMap<>();
|
List<List<Object>> separatedValues = Lists.newArrayList();
|
||||||
|
for (Property prop : properties) {
|
||||||
|
List<Object> vals = Lists.newArrayList();
|
||||||
|
vals.addAll(prop.getValues());
|
||||||
|
separatedValues.add(vals);
|
||||||
|
}
|
||||||
|
List<List<Object>> valueLists = Lists.cartesianProduct(separatedValues);
|
||||||
|
for (List<Object> valueList : valueLists) {
|
||||||
|
Map<Property<?>, Object> valueMap = Maps.newTreeMap(Comparator.comparing(Property::getName));
|
||||||
BlockState stateMaker = new BlockState(blockType);
|
BlockState stateMaker = new BlockState(blockType);
|
||||||
for (Object value : valueList) {
|
for (int i = 0; i < valueList.size(); i++) {
|
||||||
|
Property<?> property = properties.get(i);
|
||||||
|
Object value = valueList.get(i);
|
||||||
valueMap.put(property, value);
|
valueMap.put(property, value);
|
||||||
stateMaker.setState(property, value);
|
stateMaker.setState(property, value);
|
||||||
}
|
}
|
||||||
stateMap.put(valueMap, stateMaker);
|
stateMap.put(valueMap, stateMaker);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (stateMap.isEmpty()) {
|
if (stateMap.isEmpty()) {
|
||||||
// No properties.
|
// No properties.
|
||||||
@ -101,7 +112,13 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
|||||||
|
|
||||||
property.getValues().forEach(value -> {
|
property.getValues().forEach(value -> {
|
||||||
if(value != entry.getValue()) {
|
if(value != entry.getValue()) {
|
||||||
states.put(property, value, stateMap.get(this.withValue(property, value)));
|
BlockState modifiedState = stateMap.get(this.withValue(property, value));
|
||||||
|
if (modifiedState != null) {
|
||||||
|
states.put(property, value, modifiedState);
|
||||||
|
} else {
|
||||||
|
System.out.println(stateMap);
|
||||||
|
WorldEdit.logger.warning("Found a null state at " + this.withValue(property, value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,9 @@ public interface BlockStateHolder<T extends BlockStateHolder> {
|
|||||||
if (getStates().isEmpty()) {
|
if (getStates().isEmpty()) {
|
||||||
return this.getBlockType().getId();
|
return this.getBlockType().getId();
|
||||||
} else {
|
} else {
|
||||||
String properties = getStates().entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.joining(","));
|
String properties =
|
||||||
|
getStates().entrySet().stream().map(entry -> entry.getKey().getName() + "=" + entry.getValue().toString().toLowerCase()).collect(Collectors.joining(
|
||||||
|
","));
|
||||||
return this.getBlockType().getId() + "[" + properties + "]";
|
return this.getBlockType().getId() + "[" + properties + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,9 +133,7 @@ public class BundledBlockData {
|
|||||||
|
|
||||||
public static class BlockEntry {
|
public static class BlockEntry {
|
||||||
private String id;
|
private String id;
|
||||||
private String unlocalizedName;
|
|
||||||
public String localizedName;
|
public String localizedName;
|
||||||
private List<String> aliases;
|
|
||||||
private SimpleBlockMaterial material = new SimpleBlockMaterial();
|
private SimpleBlockMaterial material = new SimpleBlockMaterial();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user