Search in sources :

Example 1 with DirectionalProperty

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;
}
Also used : ArrayList(java.util.ArrayList) DirectionalProperty(com.sk89q.worldedit.registry.state.DirectionalProperty) List(java.util.List) ArrayList(java.util.ArrayList) Direction(com.sk89q.worldedit.util.Direction) PropertyKey(com.fastasyncworldedit.core.registry.state.PropertyKey)

Example 2 with DirectionalProperty

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;
}
Also used : Property(com.sk89q.worldedit.registry.state.Property) LoadingCache(com.google.common.cache.LoadingCache) DirectionalProperty(com.sk89q.worldedit.registry.state.DirectionalProperty) StringRepresentable(net.minecraft.util.StringRepresentable) Item(net.minecraft.world.item.Item) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) BiomeTypes(com.sk89q.worldedit.world.biome.BiomeTypes) Constants(com.sk89q.worldedit.internal.Constants) Component(com.sk89q.worldedit.util.formatting.text.Component) MinecraftServer(net.minecraft.server.MinecraftServer) Location(org.bukkit.Location) SideEffect(com.sk89q.worldedit.util.SideEffect) LongArrayBinaryTag(com.sk89q.worldedit.util.nbt.LongArrayBinaryTag) Map(java.util.Map) Path(java.nio.file.Path) BlockStateHolder(com.sk89q.worldedit.world.block.BlockStateHolder) BlockStateIdAccess(com.sk89q.worldedit.internal.block.BlockStateIdAccess) BlockData(org.bukkit.block.data.BlockData) LongBinaryTag(com.sk89q.worldedit.util.nbt.LongBinaryTag) Set(java.util.Set) InteractionResult(net.minecraft.world.InteractionResult) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) InvocationTargetException(java.lang.reflect.InvocationTargetException) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) WorldEditPlugin(com.sk89q.worldedit.bukkit.WorldEditPlugin) CraftBlockData(org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData) StringBinaryTag(com.sk89q.worldedit.util.nbt.StringBinaryTag) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) ItemStack(net.minecraft.world.item.ItemStack) Extent(com.sk89q.worldedit.extent.Extent) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) ChunkHolder(net.minecraft.server.level.ChunkHolder) EntityType(net.minecraft.world.entity.EntityType) WorldGenSettings(net.minecraft.world.level.levelgen.WorldGenSettings) CraftServer(org.bukkit.craftbukkit.v1_18_R1.CraftServer) IntArrayBinaryTag(com.sk89q.worldedit.util.nbt.IntArrayBinaryTag) LazyReference(com.sk89q.worldedit.util.concurrency.LazyReference) SpigotConfig(org.spigotmc.SpigotConfig) Biome(net.minecraft.world.level.biome.Biome) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) WorldEditException(com.sk89q.worldedit.WorldEditException) CraftMagicNumbers(org.bukkit.craftbukkit.v1_18_R1.util.CraftMagicNumbers) RegenOptions(com.sk89q.worldedit.world.RegenOptions) ShortBinaryTag(com.sk89q.worldedit.util.nbt.ShortBinaryTag) UseOnContext(net.minecraft.world.item.context.UseOnContext) Nullable(javax.annotation.Nullable) WorldNativeAccess(com.sk89q.worldedit.internal.wna.WorldNativeAccess) DataFixer(com.sk89q.worldedit.world.DataFixer) Files(java.nio.file.Files) Lifecycle(com.mojang.serialization.Lifecycle) Field(java.lang.reflect.Field) ChunkPos(net.minecraft.world.level.ChunkPos) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) ForkJoinPool(java.util.concurrent.ForkJoinPool) ByteArrayBinaryTag(com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag) LevelStem(net.minecraft.world.level.dimension.LevelStem) BlockState(com.sk89q.worldedit.world.block.BlockState) InteractionHand(net.minecraft.world.InteractionHand) ChunkStatus(net.minecraft.world.level.chunk.ChunkStatus) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) Watchdog(com.sk89q.worldedit.extension.platform.Watchdog) ResourceLocation(net.minecraft.resources.ResourceLocation) Either(com.mojang.datafixers.util.Either) BlockVector2(com.sk89q.worldedit.math.BlockVector2) BlockTypes(com.sk89q.worldedit.world.block.BlockTypes) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ClientboundEntityEventPacket(net.minecraft.network.protocol.game.ClientboundEntityEventPacket) Player(org.bukkit.entity.Player) ChunkGenerator(org.bukkit.generator.ChunkGenerator) Registry(net.minecraft.core.Registry) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) BooleanProperty(com.sk89q.worldedit.registry.state.BooleanProperty) Locale(java.util.Locale) Refraction(com.sk89q.worldedit.bukkit.adapter.Refraction) DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) Method(java.lang.reflect.Method) Bukkit(org.bukkit.Bukkit) StateDefinition(net.minecraft.world.level.block.state.StateDefinition) SafeFiles(com.sk89q.worldedit.util.io.file.SafeFiles) BlockType(com.sk89q.worldedit.world.block.BlockType) ChunkProgressListener(net.minecraft.server.level.progress.ChunkProgressListener) PrimaryLevelData(net.minecraft.world.level.storage.PrimaryLevelData) BaseItem(com.sk89q.worldedit.blocks.BaseItem) BlockHitResult(net.minecraft.world.phys.BlockHitResult) ClientboundBlockEntityDataPacket(net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket) BlockableEventLoop(net.minecraft.util.thread.BlockableEventLoop) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) BukkitImplAdapter(com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter) Blocks(net.minecraft.world.level.block.Blocks) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) Preconditions.checkState(com.google.common.base.Preconditions.checkState) CacheLoader(com.google.common.cache.CacheLoader) Objects(java.util.Objects) Util(net.minecraft.Util) List(java.util.List) EnumProperty(com.sk89q.worldedit.registry.state.EnumProperty) BlockPos(net.minecraft.core.BlockPos) BukkitAdapter(com.sk89q.worldedit.bukkit.BukkitAdapter) CacheBuilder(com.google.common.cache.CacheBuilder) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ServerLevel(net.minecraft.server.level.ServerLevel) OptionalInt(java.util.OptionalInt) Level(java.util.logging.Level) EndBinaryTag(com.sk89q.worldedit.util.nbt.EndBinaryTag) Environment(org.bukkit.World.Environment) ImmutableList(com.google.common.collect.ImmutableList) DoubleBinaryTag(com.sk89q.worldedit.util.nbt.DoubleBinaryTag) FloatBinaryTag(com.sk89q.worldedit.util.nbt.FloatBinaryTag) ByteBinaryTag(com.sk89q.worldedit.util.nbt.ByteBinaryTag) Direction(com.sk89q.worldedit.util.Direction) SpawnReason(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason) WeakReference(java.lang.ref.WeakReference) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) LevelStorageSource(net.minecraft.world.level.storage.LevelStorageSource) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) Region(com.sk89q.worldedit.regions.Region) PaperweightFaweAdapter(com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R1.PaperweightFaweAdapter) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Maps(com.google.common.collect.Maps) ResourceKey(net.minecraft.resources.ResourceKey) StructureBlockEntity(net.minecraft.world.level.block.entity.StructureBlockEntity) LevelSettings(net.minecraft.world.level.LevelSettings) Entity(net.minecraft.world.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity) Vec3(net.minecraft.world.phys.Vec3) IntegerProperty(com.sk89q.worldedit.registry.state.IntegerProperty) DirectionProperty(net.minecraft.world.level.block.state.properties.DirectionProperty) WatchdogThread(org.spigotmc.WatchdogThread) Block(net.minecraft.world.level.block.Block) ItemType(com.sk89q.worldedit.world.item.ItemType) Clearable(net.minecraft.world.Clearable) Direction(com.sk89q.worldedit.util.Direction) EnumProperty(com.sk89q.worldedit.registry.state.EnumProperty) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DirectionProperty(net.minecraft.world.level.block.state.properties.DirectionProperty) Property(com.sk89q.worldedit.registry.state.Property) DirectionalProperty(com.sk89q.worldedit.registry.state.DirectionalProperty) BooleanProperty(com.sk89q.worldedit.registry.state.BooleanProperty) EnumProperty(com.sk89q.worldedit.registry.state.EnumProperty) IntegerProperty(com.sk89q.worldedit.registry.state.IntegerProperty) DirectionProperty(net.minecraft.world.level.block.state.properties.DirectionProperty) IntegerProperty(com.sk89q.worldedit.registry.state.IntegerProperty) BooleanProperty(com.sk89q.worldedit.registry.state.BooleanProperty) BlockState(com.sk89q.worldedit.world.block.BlockState) StringRepresentable(net.minecraft.util.StringRepresentable) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) Block(net.minecraft.world.level.block.Block) DirectionalProperty(com.sk89q.worldedit.registry.state.DirectionalProperty)

Aggregations

DirectionalProperty (com.sk89q.worldedit.registry.state.DirectionalProperty)2 Direction (com.sk89q.worldedit.util.Direction)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PropertyKey (com.fastasyncworldedit.core.registry.state.PropertyKey)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 ImmutableList (com.google.common.collect.ImmutableList)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Futures (com.google.common.util.concurrent.Futures)1 Either (com.mojang.datafixers.util.Either)1 Lifecycle (com.mojang.serialization.Lifecycle)1 WorldEditException (com.sk89q.worldedit.WorldEditException)1 BaseItem (com.sk89q.worldedit.blocks.BaseItem)1 BaseItemStack (com.sk89q.worldedit.blocks.BaseItemStack)1 BukkitAdapter (com.sk89q.worldedit.bukkit.BukkitAdapter)1