cn.nukkit.block.BlockConnectable Maven / Gradle / Ivy
package cn.nukkit.block;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;
import cn.nukkit.math.BlockFace;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Set;
@PowerNukkitOnly
@Since("1.3.0.0-PN")
public interface BlockConnectable {
@PowerNukkitOnly
@Since("1.3.0.0-PN")
Block getSideAtLayer(int layer, BlockFace face);
@PowerNukkitOnly
@Since("1.3.0.0-PN")
boolean canConnect(Block block);
@PowerNukkitOnly
@Since("1.3.0.0-PN")
default boolean isStraight() {
Set connections = getConnections();
if (connections.size() != 2) {
return false;
}
Iterator iterator = connections.iterator();
BlockFace a = iterator.next();
BlockFace b = iterator.next();
return a.getOpposite() == b;
}
@PowerNukkitOnly
@Since("1.3.0.0-PN")
default Set getConnections() {
EnumSet connections = EnumSet.noneOf(BlockFace.class);
for (BlockFace blockFace : BlockFace.Plane.HORIZONTAL) {
if (isConnected(blockFace)) {
connections.add(blockFace);
}
}
return connections;
}
@PowerNukkitOnly
@Since("1.3.0.0-PN")
default boolean isConnected(BlockFace face) {
return canConnect(getSideAtLayer(0, face));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy