下面列出了怎么用org.bukkit.material.Attachable的API类实例代码及写法,或者点击链接到github查看源代码。
public boolean update(boolean force, boolean applyPhysics) {
if (!isPlaced()) {
return true;
}
Block block = getBlock();
if (block.getType() != getType()) {
if (!force) {
return false;
}
}
BlockPos pos = new BlockPos(x, y, z);
IBlockState newBlock = CraftMagicNumbers.getBlock(getType()).getStateFromMeta(this.getRawData());
block.setTypeIdAndData(getTypeId(), getRawData(), applyPhysics);
world.getHandle().notifyBlockUpdate(
pos,
CraftMagicNumbers.getBlock(block).getStateFromMeta(block.getData()),
newBlock,
3
);
// Update levers etc
if (applyPhysics && getData() instanceof Attachable) {
world.getHandle().notifyNeighborsOfStateChange(pos.offset(CraftBlock.blockFaceToNotch(((Attachable) getData()).getAttachedFace())), newBlock.getBlock(), false);
}
if (nbt != null) {
TileEntity te = world.getHandle().getTileEntity(new BlockPos(this.x, this.y, this.z));
if (te != null) {
te.readFromNBT(nbt);
}
}
return true;
}
private BlockFace getSignFacingFromWorld() {
// try getting the current sign facing from the sign in the world:
Sign sign = this.getSign();
if (sign != null) {
return ((Attachable) sign.getData()).getFacing();
}
return null;
}
@Override
public boolean spawn() {
Location signLocation = this.getActualLocation();
if (signLocation == null) return false;
Block signBlock = signLocation.getBlock();
if (signBlock.getType() != Material.AIR) {
return false;
}
// place sign: // TODO maybe also allow non-wall signs?
// cancel block physics for this placed sign if needed:
ShopkeepersPlugin.getInstance().cancelNextBlockPhysics(signLocation);
signBlock.setType(Material.WALL_SIGN);
// cleanup state if no block physics were triggered:
ShopkeepersPlugin.getInstance().cancelNextBlockPhysics(null);
// in case sign placement has failed for some reason:
if (!Utils.isSign(signBlock.getType())) {
return false;
}
// set sign facing:
if (signFacing != null) {
Sign signState = (Sign) signBlock.getState();
((Attachable) signState.getData()).setFacingDirection(signFacing);
// apply facing:
signState.update();
}
// init sign content:
updateSign = false;
this.updateSign();
return true;
}
private static Block getAttached(Sign sign) {
Attachable data = (Attachable) sign.getData();
BlockFace attachingBlockFace = data.getFacing().getOppositeFace();
return sign.getBlock().getRelative(attachingBlockFace);
}