cn.nukkit.block.BlockConnectable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
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));
}
}