Search in sources :

Example 1 with Countable

use of com.sk89q.worldedit.util.Countable in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method distr.

@Command(name = "/distr", desc = "Get the distribution of blocks in the selection")
@CommandPermissions("worldedit.analysis.distr")
public void distr(Actor actor, World world, LocalSession session, // FAWE start > add extent to RegionVisitor to allow chunk preloading
EditSession editSession, // FAWE end
@Switch(name = 'c', desc = "Get the distribution of the clipboard instead") boolean clipboardDistr, @Switch(name = 'd', desc = "Separate blocks by state") boolean separateStates, @ArgFlag(name = 'p', desc = "Gets page from a previous distribution.") Integer page) throws WorldEditException {
    List<Countable<BlockState>> distribution;
    if (page == null) {
        if (clipboardDistr) {
            // throws if missing
            Clipboard clipboard = session.getClipboard().getClipboard();
            BlockDistributionCounter count = new BlockDistributionCounter(clipboard, separateStates);
            // FAWE start > add extent to RegionVisitor to allow chunk preloading
            RegionVisitor visitor = new RegionVisitor(clipboard.getRegion(), count, editSession);
            // FAWE end
            Operations.completeBlindly(visitor);
            distribution = count.getDistribution();
        } else {
            distribution = editSession.getBlockDistribution(session.getSelection(world), separateStates);
        }
        session.setLastDistribution(distribution);
        page = 1;
    } else {
        distribution = session.getLastDistribution();
        if (distribution == null) {
            actor.print(Caption.of("worldedit.distr.no-previous"));
            return;
        }
    }
    if (distribution.isEmpty()) {
        // *Should* always be false
        actor.print(Caption.of("worldedit.distr.no-blocks"));
        return;
    }
    BlockDistributionResult res = new BlockDistributionResult(distribution, separateStates);
    if (!actor.isPlayer()) {
        res.formatForConsole();
    }
    actor.print(res.create(page));
}
Also used : Countable(com.sk89q.worldedit.util.Countable) RegionVisitor(com.sk89q.worldedit.function.visitor.RegionVisitor) BlockDistributionCounter(com.sk89q.worldedit.function.block.BlockDistributionCounter) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 2 with Countable

use of com.sk89q.worldedit.util.Countable in project FastAsyncWorldEdit by IntellectualSites.

the class Extent method getBlockDistributionWithData.

/**
 * Get the block distribution (with data values) inside a region.
 *
 * @param region a region
 * @return the results
 */
default List<Countable<BlockState>> getBlockDistributionWithData(final Region region) {
    int[][] counter = new int[BlockTypes.size()][];
    for (final BlockVector3 pt : region) {
        BlockState blk = this.getBlock(pt);
        BlockType type = blk.getBlockType();
        if (type == BlockTypes.__RESERVED__) {
            int[] stateCounter = counter[1];
            if (stateCounter == null) {
                counter[1] = stateCounter = new int[BlockTypes.AIR.getMaxStateId() + 1];
            }
            stateCounter[BlockTypes.AIR.getDefaultState().getInternalPropertiesId()]++;
        }
        int[] stateCounter = counter[type.getInternalId()];
        if (stateCounter == null) {
            counter[type.getInternalId()] = stateCounter = new int[type.getMaxStateId() + 1];
        }
        stateCounter[blk.getInternalPropertiesId()]++;
    }
    List<Countable<BlockState>> distribution = new ArrayList<>();
    for (int typeId = 0; typeId < counter.length; typeId++) {
        BlockType type = BlockTypes.get(typeId);
        int[] stateCount = counter[typeId];
        if (stateCount != null) {
            for (int propId = 0; propId < stateCount.length; propId++) {
                int count = stateCount[propId];
                if (count != 0) {
                    BlockState state = type.withPropertyId(propId);
                    distribution.add(new Countable<>(state, count));
                }
            }
        }
    }
    // Collections.reverse(distribution);
    return distribution;
}
Also used : Countable(com.sk89q.worldedit.util.Countable) BlockState(com.sk89q.worldedit.world.block.BlockState) BlockType(com.sk89q.worldedit.world.block.BlockType) ArrayList(java.util.ArrayList) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3)

Example 3 with Countable

use of com.sk89q.worldedit.util.Countable in project FastAsyncWorldEdit by IntellectualSites.

the class DistrFilter method getTypeDistribution.

public List<Countable<BlockType>> getTypeDistribution() {
    final List<Countable<BlockType>> distribution = new ArrayList<>();
    int[] typeCounter = new int[BlockTypesCache.values.length];
    for (int i = 0; i < counter.length; i++) {
        final int count = counter[i];
        if (count != 0) {
            BlockState state = BlockTypesCache.states[i];
            typeCounter[state.getBlockType().getInternalId()] += count;
        }
    }
    for (int i = 0; i < typeCounter.length; i++) {
        final int count = typeCounter[i];
        if (count != 0) {
            distribution.add(new Countable<>(BlockTypesCache.values[i], count));
        }
    }
    Collections.sort(distribution);
    return distribution;
}
Also used : Countable(com.sk89q.worldedit.util.Countable) BlockState(com.sk89q.worldedit.world.block.BlockState) ArrayList(java.util.ArrayList)

Example 4 with Countable

use of com.sk89q.worldedit.util.Countable in project PixelsSkyblock by dudullle.

the class OnislandObjective method check.

@Override
public boolean check(Player p, Island i) {
    if (!type) {
        List<Countable<Integer>> blocks = WEManager.count(Bukkit.getWorld("world"), i.getEdges().get(0), i.getEdges().get(1));
        for (Countable<Integer> b : blocks) {
            if (b.getID() == mat_ID && b.getAmount() >= quantity) {
                return true;
            } else if (b.getID() == mat_ID) {
                calculated_nb = b.getAmount();
            }
        }
        return false;
    } else {
        try {
            List<Entity> es = (List<Entity>) WEManager.count_entities(Bukkit.getWorld("world"), i.getEdges().get(0), i.getEdges().get(1));
            int qte = 0;
            for (Entity e : es) {
                try {
                    if (e.getState().getTypeId().toString().equalsIgnoreCase(it_name)) {
                        qte += 1;
                    }
                } catch (Exception ex) {
                }
            }
            calculated_nb = qte;
            if (qte >= quantity) {
                return true;
            }
        } catch (Exception ex) {
        }
    }
    return false;
}
Also used : Countable(com.sk89q.worldedit.util.Countable) Entity(com.sk89q.worldedit.entity.Entity) List(java.util.List)

Example 5 with Countable

use of com.sk89q.worldedit.util.Countable in project FastAsyncWorldEdit by IntellectualSites.

the class HistorySubCommands method distr.

@Command(name = "distr", aliases = { "distribution" }, desc = "View block distribution for an edit")
@CommandPermissions("worldedit.history.distr")
public void distr(Player player, LocalSession session, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @Arg(desc = "edit index") Integer index, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) throws ExecutionException, InterruptedException {
    String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
    Reference<PaginationBox> cached = player.getMeta(pageCommand);
    PaginationBox pages = cached == null ? null : cached.get();
    if (page == null || pages == null) {
        RollbackOptimizedHistory edit = database.getEdit(other, index).get();
        SimpleChangeSetSummary summary = edit.summarize(RegionWrapper.GLOBAL(), false);
        if (summary != null) {
            List<Countable<BlockState>> distr = summary.getBlockDistributionWithData();
            SelectionCommands.BlockDistributionResult distrPages = new SelectionCommands.BlockDistributionResult(distr, true, pageCommand);
            pages = new PaginationBox.MergedPaginationBox("Block Distribution", pageCommand, pages, distrPages);
            player.setMeta(pageCommand, new SoftReference<>(pages));
        }
        page = 1;
    }
    if (pages == null) {
        player.print(Caption.of("fawe.worldedit.history.distr.summary_null"));
    } else {
        player.print(pages.create(page));
    }
}
Also used : Countable(com.sk89q.worldedit.util.Countable) SimpleChangeSetSummary(com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary) PaginationBox(com.sk89q.worldedit.util.formatting.component.PaginationBox) RollbackOptimizedHistory(com.fastasyncworldedit.core.history.RollbackOptimizedHistory) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Aggregations

Countable (com.sk89q.worldedit.util.Countable)7 BlockState (com.sk89q.worldedit.world.block.BlockState)3 ArrayList (java.util.ArrayList)3 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)2 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 BlockType (com.sk89q.worldedit.world.block.BlockType)2 Command (org.enginehub.piston.annotation.Command)2 RollbackOptimizedHistory (com.fastasyncworldedit.core.history.RollbackOptimizedHistory)1 SimpleChangeSetSummary (com.fastasyncworldedit.core.history.changeset.SimpleChangeSetSummary)1 Entity (com.sk89q.worldedit.entity.Entity)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 BlockDistributionCounter (com.sk89q.worldedit.function.block.BlockDistributionCounter)1 RegionVisitor (com.sk89q.worldedit.function.visitor.RegionVisitor)1 PaginationBox (com.sk89q.worldedit.util.formatting.component.PaginationBox)1 List (java.util.List)1