3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-09-16 13:01:24 +02:00

State system is done. It works. Finally. Still a few rough edges that need fixing however.

Dieser Commit ist enthalten in:
Matthew Miller 2018-07-18 17:39:25 +10:00
Ursprung 6b5f218809
Commit c3d832c3fd
8 geänderte Dateien mit 42 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -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() {

Datei anzeigen

@ -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]);
} }

Datei anzeigen

@ -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> {

Datei anzeigen

@ -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());
} }

Datei anzeigen

@ -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,19 +68,28 @@ 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();
BlockState stateMaker = new BlockState(blockType); for (Property prop : properties) {
for (Object value : valueList) { List<Object> vals = Lists.newArrayList();
valueMap.put(property, value); vals.addAll(prop.getValues());
stateMaker.setState(property, value); 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);
for (int i = 0; i < valueList.size(); i++) {
Property<?> property = properties.get(i);
Object value = valueList.get(i);
valueMap.put(property, value);
stateMaker.setState(property, value);
}
stateMap.put(valueMap, stateMaker);
} }
stateMap.put(valueMap, stateMaker);
} }
if (stateMap.isEmpty()) { if (stateMap.isEmpty()) {
@ -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));
}
} }
}); });
} }

Datei anzeigen

@ -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 + "]";
} }
} }

Datei anzeigen

@ -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();
} }