Search in sources :

Example 1 with IntTriple

use of com.fastasyncworldedit.core.math.IntTriple in project FastAsyncWorldEdit by IntellectualSites.

the class DiskOptimizedClipboard method toBaseBlock.

private BaseBlock toBaseBlock(BlockState state, int i) {
    if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
        CompoundTag nbt;
        if (nbtMap.size() < 4) {
            nbt = null;
            for (Map.Entry<IntTriple, CompoundTag> entry : nbtMap.entrySet()) {
                IntTriple key = entry.getKey();
                int index = getIndex(key.x(), key.y(), key.z());
                if (index == i) {
                    nbt = entry.getValue();
                    break;
                }
            }
        } else {
            int y = i / getArea();
            int newI = i - y * getArea();
            int z = newI / getWidth();
            int x = newI - z * getWidth();
            nbt = nbtMap.get(new IntTriple(x, y, z));
        }
        return state.toBaseBlock(nbt);
    }
    return state.toBaseBlock();
}
Also used : IntTriple(com.fastasyncworldedit.core.math.IntTriple) HashMap(java.util.HashMap) Map(java.util.Map) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 2 with IntTriple

use of com.fastasyncworldedit.core.math.IntTriple in project FastAsyncWorldEdit by IntellectualSites.

the class MemoryOptimizedClipboard method toBaseBlock.

private BaseBlock toBaseBlock(BlockState state, int i) {
    if (state.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
        CompoundTag nbt;
        if (nbtMap.size() < 4) {
            nbt = null;
            for (Map.Entry<IntTriple, CompoundTag> entry : nbtMap.entrySet()) {
                IntTriple trio = entry.getKey();
                int index = getIndex(trio.x(), trio.y(), trio.z());
                if (index == i) {
                    nbt = entry.getValue();
                    break;
                }
            }
        } else {
            int y = i / getArea();
            int newI = i - y * getArea();
            int z = newI / getWidth();
            int x = newI - z * getWidth();
            nbt = nbtMap.get(new IntTriple(x, y, z));
        }
        return state.toBaseBlock(nbt);
    }
    return state.toBaseBlock();
}
Also used : IntTriple(com.fastasyncworldedit.core.math.IntTriple) HashMap(java.util.HashMap) Map(java.util.Map) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 3 with IntTriple

use of com.fastasyncworldedit.core.math.IntTriple in project FastAsyncWorldEdit by IntellectualSites.

the class MemoryOptimizedClipboard method setTile.

@Override
public boolean setTile(int x, int y, int z, CompoundTag tag) {
    final Map<String, Tag> values = new HashMap<>(tag.getValue());
    values.put("x", new IntTag(x));
    values.put("y", new IntTag(y));
    values.put("z", new IntTag(z));
    nbtMap.put(new IntTriple(x, y, z), new CompoundTag(values));
    return true;
}
Also used : HashMap(java.util.HashMap) IntTag(com.sk89q.jnbt.IntTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) IntTriple(com.fastasyncworldedit.core.math.IntTriple) IntTag(com.sk89q.jnbt.IntTag) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 4 with IntTriple

use of com.fastasyncworldedit.core.math.IntTriple in project FastAsyncWorldEdit by IntellectualSites.

the class DFSVisitor method getIntDirections.

private IntTriple[] getIntDirections() {
    IntTriple[] array = new IntTriple[directions.size()];
    for (int i = 0; i < array.length; i++) {
        BlockVector3 dir = directions.get(i);
        array[i] = new IntTriple(dir.getBlockX(), dir.getBlockY(), dir.getBlockZ());
    }
    return array;
}
Also used : IntTriple(com.fastasyncworldedit.core.math.IntTriple) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3)

Example 5 with IntTriple

use of com.fastasyncworldedit.core.math.IntTriple in project FastAsyncWorldEdit by IntellectualSites.

the class DFSVisitor method resume.

@Override
public Operation resume(RunContext run) throws WorldEditException {
    MutableBlockVector3 mutable = new MutableBlockVector3();
    MutableBlockVector3 mutable2 = new MutableBlockVector3();
    IntTriple[] dirs = getIntDirections();
    while (!queue.isEmpty()) {
        NodePair current = queue.poll();
        Node from = current.to;
        hashQueue.remove(from);
        if (visited.containsKey(from)) {
            continue;
        }
        mutable.mutX(from.getX());
        mutable.mutY(from.getY());
        mutable.mutZ(from.getZ());
        function.apply(mutable);
        int countAdd = 0;
        int countAttempt = 0;
        for (IntTriple direction : dirs) {
            mutable2.mutX(from.getX() + direction.x());
            mutable2.mutY(from.getY() + direction.y());
            mutable2.mutZ(from.getZ() + direction.z());
            if (isVisitable(mutable, mutable2)) {
                Node adjacent = new Node(mutable2.getBlockX(), mutable2.getBlockY(), mutable2.getBlockZ());
                if (!adjacent.equals(current.from)) {
                    AtomicInteger adjacentCount = visited.get(adjacent);
                    if (adjacentCount == null) {
                        if (countAdd++ < maxBranch) {
                            if (!hashQueue.contains(adjacent)) {
                                if (current.depth == maxDepth) {
                                    countAttempt++;
                                } else {
                                    hashQueue.add(adjacent);
                                    queue.addFirst(new NodePair(from, adjacent, current.depth + 1));
                                }
                            } else {
                                countAttempt++;
                            }
                        } else {
                            countAttempt++;
                        }
                    } else if (adjacentCount.decrementAndGet() == 0) {
                        visited.remove(adjacent);
                    } else if (hashQueue.contains(adjacent)) {
                        countAttempt++;
                    }
                }
            }
        }
        if (countAttempt > 0) {
            visited.put(from, new AtomicInteger(countAttempt));
        }
        affected++;
    }
    return null;
}
Also used : MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntTriple(com.fastasyncworldedit.core.math.IntTriple)

Aggregations

IntTriple (com.fastasyncworldedit.core.math.IntTriple)7 CompoundTag (com.sk89q.jnbt.CompoundTag)5 HashMap (java.util.HashMap)5 Map (java.util.Map)3 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)2 IntTag (com.sk89q.jnbt.IntTag)2 Tag (com.sk89q.jnbt.Tag)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1