com.sk89q.worldedit.util.collection.LocatedBlockList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of FastAsyncWorldEdit-Core Show documentation
Show all versions of FastAsyncWorldEdit-Core Show documentation
Blazingly fast Minecraft world manipulation for artists, builders and everyone else.
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.sk89q.worldedit.util.collection;
import com.google.common.collect.Iterators;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.LocatedBlock;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Iterator;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Wrapper around a list of blocks located in the world.
*/
public class LocatedBlockList implements Iterable {
private final BlockMap blocks = BlockMap.createForBaseBlock();
private final PositionList order = PositionList.create(
WorldEdit.getInstance().getConfiguration().extendedYLimit
);
public LocatedBlockList() {
}
public LocatedBlockList(Collection collection) {
for (LocatedBlock locatedBlock : collection) {
add(locatedBlock.getLocation(), locatedBlock.getBlock());
}
}
public void add(LocatedBlock setBlockCall) {
checkNotNull(setBlockCall);
add(setBlockCall.getLocation(), setBlockCall.getBlock());
}
public > void add(BlockVector3 location, B block) {
blocks.put(location, block.toBaseBlock());
order.add(location);
}
public boolean containsLocation(BlockVector3 location) {
return blocks.containsKey(location);
}
@Nullable
public BaseBlock get(BlockVector3 location) {
return blocks.get(location);
}
public int size() {
return order.size();
}
public void clear() {
blocks.clear();
order.clear();
}
@Override
public Iterator iterator() {
return Iterators.transform(order.iterator(), position ->
new LocatedBlock(position, blocks.get(position)));
}
public Iterator reverseIterator() {
return Iterators.transform(order.reverseIterator(), position ->
new LocatedBlock(position, blocks.get(position)));
}
}