use of com.sk89q.worldedit.registry.state.DirectionalProperty in project FastAsyncWorldEdit by IntellectualSites.
the class BlockTransformExtent method getDirections.
private static long[] getDirections(AbstractProperty property) {
if (property instanceof DirectionalProperty) {
DirectionalProperty directional = (DirectionalProperty) property;
return adapt(directional.getValues().toArray(new Direction[0]));
} else {
List values = property.getValues();
PropertyKey key = property.getKey();
switch(key.getName().toLowerCase()) {
case "half":
{
return adapt(UP, DOWN);
}
case "type":
{
return adapt(combine(UP), combine(DOWN), 0L);
}
case "rotation":
{
List<Direction> directions = new ArrayList<>();
for (Object value : values) {
directions.add(Direction.fromRotationIndex((Integer) value).get());
}
return adapt(directions.toArray(new Direction[0]));
}
case "axis":
{
switch(property.getValues().size()) {
case 3:
return adapt(combine(EAST, WEST), combine(UP, DOWN), combine(SOUTH, NORTH));
case 2:
return adapt(combine(EAST, WEST), combine(SOUTH, NORTH));
default:
LOGGER.error("Invalid {} {}", property.getName(), property.getValues());
return null;
}
}
case "facing":
{
List<Direction> directions = new ArrayList<>();
for (Object value : values) {
directions.add(Direction.valueOf(value.toString().toUpperCase(Locale.ROOT)));
}
return adapt(directions.toArray(new Direction[0]));
}
case "face":
{
if (values.size() == 3) {
return adapt(combine(UP), combine(NORTH, EAST, SOUTH, WEST), combine(DOWN));
}
return null;
}
case "hinge":
{
return adapt(combine(NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST), combine(NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST));
}
case "shape":
{
if (values.contains("left")) {
return adapt(combine(EAST, WEST), combine(NORTH, SOUTH));
}
if (values.contains("straight")) {
ArrayList<Long> result = new ArrayList<>();
for (Object value : values) {
// [straight, inner_left, inner_right, outer_left, outer_right]
switch(value.toString()) {
case "straight":
result.add(combine(NORTH, EAST, SOUTH, WEST));
continue;
case "inner_left":
result.add(orIndex(combine(NORTHEAST, NORTHWEST, SOUTHWEST, SOUTHEAST), property.getIndexFor("outer_right"), property.getIndexFor("outer_left")));
continue;
case "inner_right":
result.add(orIndex(combine(NORTHEAST, NORTHWEST, SOUTHWEST, SOUTHEAST), property.getIndexFor("outer_right"), property.getIndexFor("outer_left")));
continue;
case "outer_left":
result.add(orIndex(combine(NORTHEAST, NORTHWEST, SOUTHWEST, SOUTHEAST), property.getIndexFor("inner_left"), property.getIndexFor("inner_right")));
continue;
case "outer_right":
result.add(orIndex(combine(NORTHEAST, NORTHWEST, SOUTHWEST, SOUTHEAST), property.getIndexFor("inner_left"), property.getIndexFor("inner_right")));
continue;
default:
LOGGER.warn("Unknown direction {}", value);
result.add(0L);
}
}
return adapt(result.toArray(new Long[0]));
} else {
List<Long> directions = new ArrayList<>();
for (Object value : values) {
switch(value.toString()) {
case "north_south":
directions.add(combine(NORTH, SOUTH));
break;
case "east_west":
directions.add(combine(EAST, WEST));
break;
case "ascending_east":
directions.add(combine(ASCENDING_EAST));
break;
case "ascending_west":
directions.add(combine(ASCENDING_WEST));
break;
case "ascending_north":
directions.add(combine(ASCENDING_NORTH));
break;
case "ascending_south":
directions.add(combine(ASCENDING_SOUTH));
break;
case "south_east":
directions.add(combine(SOUTHEAST));
break;
case "south_west":
directions.add(combine(SOUTHWEST));
break;
case "north_west":
directions.add(combine(NORTHWEST));
break;
case "north_east":
directions.add(combine(NORTHEAST));
break;
default:
LOGGER.warn("Unknown direction {}", value);
directions.add(0L);
}
}
return adapt(directions.toArray(new Long[0]));
}
}
}
}
return null;
}
use of com.sk89q.worldedit.registry.state.DirectionalProperty in project FastAsyncWorldEdit by IntellectualSites.
the class PaperweightAdapter method getProperties.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
Map<String, Property<?>> properties = Maps.newTreeMap(String::compareTo);
Block block = getBlockFromType(blockType);
StateDefinition<Block, net.minecraft.world.level.block.state.BlockState> blockStateList = block.getStateDefinition();
for (net.minecraft.world.level.block.state.properties.Property state : blockStateList.getProperties()) {
Property property;
if (state instanceof net.minecraft.world.level.block.state.properties.BooleanProperty) {
property = new BooleanProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
} else if (state instanceof DirectionProperty) {
property = new DirectionalProperty(state.getName(), (List<Direction>) state.getPossibleValues().stream().map(e -> Direction.valueOf(((StringRepresentable) e).getSerializedName().toUpperCase(Locale.ROOT))).collect(Collectors.toList()));
} else if (state instanceof net.minecraft.world.level.block.state.properties.EnumProperty) {
property = new EnumProperty(state.getName(), (List<String>) state.getPossibleValues().stream().map(e -> ((StringRepresentable) e).getSerializedName()).collect(Collectors.toList()));
} else if (state instanceof net.minecraft.world.level.block.state.properties.IntegerProperty) {
property = new IntegerProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
} else {
throw new IllegalArgumentException("FastAsyncWorldEdit needs an update to support " + state.getClass().getSimpleName());
}
properties.put(property.getName(), property);
}
return properties;
}
Aggregations