Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-07 12:00:07 +01:00
State system is done. It works. Finally. Still a few rough edges that need fixing however.
Dieser Commit ist enthalten in:
Ursprung
6b5f218809
Commit
c3d832c3fd
@ -82,6 +82,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
||||
|
||||
WorldEdit worldEdit = WorldEdit.getInstance();
|
||||
|
||||
loadAdapter(); // Need an adapter to work with special blocks with NBT data
|
||||
|
||||
// Setup platform
|
||||
server = new BukkitServerInterface(this, getServer());
|
||||
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
|
||||
// platforms to be worried about... at the current time of writing
|
||||
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
|
||||
|
||||
loadAdapter(); // Need an adapter to work with special blocks with NBT data
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
|
Binäre Datei nicht angezeigt.
@ -164,8 +164,10 @@ class DefaultBlockParser extends InputParser<BlockStateHolder> {
|
||||
if (propertyKey == null) {
|
||||
throw new NoMatchException("Unknown state " + parts[0] + " for block " + state.getBlockType().getName());
|
||||
}
|
||||
Object value = propertyKey.getValueFor(parts[1]);
|
||||
if (value == null) {
|
||||
Object value;
|
||||
try {
|
||||
value = propertyKey.getValueFor(parts[1]);
|
||||
} catch (IllegalArgumentException e) {
|
||||
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 com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractProperty<T> implements Property<T> {
|
||||
|
@ -34,7 +34,7 @@ public class DirectionalProperty extends AbstractProperty<Direction> {
|
||||
@Nullable
|
||||
@Override
|
||||
public Direction getValueFor(final String string) {
|
||||
Direction direction = Direction.valueOf(string);
|
||||
Direction direction = Direction.valueOf(string.toUpperCase());
|
||||
if (!getValues().contains(direction)) {
|
||||
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.Maps;
|
||||
import com.google.common.collect.Table;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -66,19 +68,28 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
}
|
||||
|
||||
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<>();
|
||||
for (int i = 0; i < valueLists.size(); i++) {
|
||||
List<Object> valueList = valueLists.get(i);
|
||||
Property<?> property = properties.get(i);
|
||||
LinkedHashMap<Property<?>, Object> valueMap = new LinkedHashMap<>();
|
||||
BlockState stateMaker = new BlockState(blockType);
|
||||
for (Object value : valueList) {
|
||||
valueMap.put(property, value);
|
||||
stateMaker.setState(property, value);
|
||||
List<? extends Property> properties = blockType.getProperties();
|
||||
|
||||
if (!properties.isEmpty()) {
|
||||
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);
|
||||
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()) {
|
||||
@ -101,7 +112,13 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
|
||||
property.getValues().forEach(value -> {
|
||||
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()) {
|
||||
return this.getBlockType().getId();
|
||||
} 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 + "]";
|
||||
}
|
||||
}
|
||||
|
@ -133,9 +133,7 @@ public class BundledBlockData {
|
||||
|
||||
public static class BlockEntry {
|
||||
private String id;
|
||||
private String unlocalizedName;
|
||||
public String localizedName;
|
||||
private List<String> aliases;
|
||||
private SimpleBlockMaterial material = new SimpleBlockMaterial();
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren