下面列出了怎么用org.bukkit.block.data.Rotatable的API类实例代码及写法,或者点击链接到github查看源代码。
protected void rotate(Block b, int mod) {
BlockFace current = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
int index = POSSIBLE_ROTATIONS.indexOf(current) + mod;
if (index == POSSIBLE_ROTATIONS.size()) {
index = 0;
}
else if (index < 0) {
index = POSSIBLE_ROTATIONS.size() - 1;
}
BlockFace rotation = POSSIBLE_ROTATIONS.get(index);
Rotatable rotatatable = (Rotatable) b.getBlockData();
rotatatable.setRotation(rotation);
b.setBlockData(rotatatable);
BlockStorage.addBlockInfo(b, "rotation", rotation.name());
}
@Override
public BlockFace getFacing(Block block) {
if (block.getBlockData() instanceof Directional) {
return ((Directional) block.getBlockData()).getFacing();
} else if (block.getBlockData() instanceof Rotatable) {
return ((Rotatable) block.getBlockData()).getRotation();
} else {
throw new IllegalArgumentException("Block is not Directional or Rotatable");
}
}
@Override
public void setFacing(Block block, BlockFace facing) {
BlockData data = block.getBlockData();
if (data instanceof Directional) {
((Directional) data).setFacing(facing);
} else if (data instanceof Rotatable) {
((Rotatable) data).setRotation(facing);
} else {
throw new IllegalArgumentException("Block is not Directional or Rotatable");
}
block.setBlockData(data, false);
}
protected void move(Block b, BlockFace face, Block block) {
if (block.getY() > 0 && block.getY() < block.getWorld().getMaxHeight() && (block.getType() == Material.AIR || block.getType() == Material.CAVE_AIR)) {
block.setType(Material.PLAYER_HEAD);
Rotatable blockData = (Rotatable) block.getBlockData();
blockData.setRotation(face.getOppositeFace());
block.setBlockData(blockData);
SkullBlock.setFromBase64(block, texture);
b.setType(Material.AIR);
BlockStorage.moveBlockInfo(b.getLocation(), block.getLocation());
}
}
public static void pasteSchematic(Location loc, Tree tree) {
Schematic schematic;
try {
schematic = tree.getSchematic();
}
catch (IOException e) {
ExoticGarden.instance.getLogger().log(Level.WARNING, "Could not paste Schematic for Tree: " + tree.getFruitID() + "_TREE (" + e.getClass().getSimpleName() + ')', e);
return;
}
BlockFace[] faces = { BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST };
short[] blocks = schematic.getBlocks();
byte[] blockData = schematic.getData();
short length = schematic.getLength();
short width = schematic.getWidth();
short height = schematic.getHeight();
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
for (int z = 0; z < length; ++z) {
int index = y * width * length + z * width + x;
int blockX = x + loc.getBlockX() - length / 2;
int blockY = y + loc.getBlockY();
int blockZ = z + loc.getBlockZ() - width / 2;
Block block = new Location(loc.getWorld(), blockX, blockY, blockZ).getBlock();
if ((!block.getType().isSolid() && !block.getType().isInteractable() && !MaterialCollections.getAllUnbreakableBlocks().contains(block.getType())) || block.getType() == Material.AIR || block.getType() == Material.CAVE_AIR || org.bukkit.Tag.SAPLINGS.isTagged(block.getType())) {
Material material = parseId(blocks[index], blockData[index]);
if (material != null) {
if (blocks[index] != 0) {
block.setType(material);
}
if (org.bukkit.Tag.LEAVES.isTagged(material)) {
if (ThreadLocalRandom.current().nextInt(100) < 25) {
BlockStorage.store(block, tree.getItem());
}
}
else if (material == Material.PLAYER_HEAD) {
Rotatable s = (Rotatable) block.getBlockData();
s.setRotation(faces[ThreadLocalRandom.current().nextInt(faces.length)]);
block.setBlockData(s);
SkullBlock.setFromHash(block, tree.getTexture());
BlockStorage.store(block, tree.getFruit());
}
}
}
}
}
}
}
private void growStructure(StructureGrowEvent e) {
SlimefunItem item = BlockStorage.check(e.getLocation().getBlock());
if (item != null) {
e.setCancelled(true);
for (Tree tree : ExoticGarden.getTrees()) {
if (item.getID().equalsIgnoreCase(tree.getSapling())) {
BlockStorage.clearBlockInfo(e.getLocation());
Schematic.pasteSchematic(e.getLocation(), tree);
return;
}
}
for (Berry berry : ExoticGarden.getBerries()) {
if (item.getID().equalsIgnoreCase(berry.toBush())) {
switch (berry.getType()) {
case BUSH:
e.getLocation().getBlock().setType(Material.OAK_LEAVES);
break;
case ORE_PLANT:
case DOUBLE_PLANT:
Block blockAbove = e.getLocation().getBlock().getRelative(BlockFace.UP);
item = BlockStorage.check(blockAbove);
if (item != null) return;
if (!Tag.SAPLINGS.isTagged(blockAbove.getType()) && !Tag.LEAVES.isTagged(blockAbove.getType())) {
switch (blockAbove.getType()) {
case AIR:
case CAVE_AIR:
case SNOW:
break;
default:
return;
}
}
BlockStorage.store(blockAbove, berry.getItem());
e.getLocation().getBlock().setType(Material.OAK_LEAVES);
blockAbove.setType(Material.PLAYER_HEAD);
Rotatable rotatable = (Rotatable) blockAbove.getBlockData();
rotatable.setRotation(faces[ThreadLocalRandom.current().nextInt(faces.length)]);
blockAbove.setBlockData(rotatable);
SkullBlock.setFromHash(blockAbove, berry.getTexture());
break;
default:
e.getLocation().getBlock().setType(Material.PLAYER_HEAD);
Rotatable s = (Rotatable) e.getLocation().getBlock().getBlockData();
s.setRotation(faces[ThreadLocalRandom.current().nextInt(faces.length)]);
e.getLocation().getBlock().setBlockData(s);
SkullBlock.setFromHash(e.getLocation().getBlock(), berry.getTexture());
break;
}
BlockStorage._integrated_removeBlockInfo(e.getLocation(), false);
BlockStorage.store(e.getLocation().getBlock(), berry.getItem());
e.getWorld().playEffect(e.getLocation(), Effect.STEP_SOUND, Material.OAK_LEAVES);
break;
}
}
}
}
private void sendInfo(Player p, Block b) {
SlimefunItem item = BlockStorage.check(b);
p.sendMessage(" ");
p.sendMessage(ChatColors.color("&d" + b.getType() + " &[email protected] X: " + b.getX() + " Y: " + b.getY() + " Z: " + b.getZ()));
p.sendMessage(ChatColors.color("&dId: " + "&e" + item.getID()));
p.sendMessage(ChatColors.color("&dPlugin: " + "&e" + item.getAddon().getName()));
if (b.getState() instanceof Skull) {
p.sendMessage(ChatColors.color("&dSkull: " + enabledTooltip));
// Check if the skull is a wall skull, and if so use Directional instead of Rotatable.
if (b.getType() == Material.PLAYER_WALL_HEAD) {
p.sendMessage(ChatColors.color(" &dFacing: &e" + ((Directional) b.getBlockData()).getFacing().toString()));
}
else {
p.sendMessage(ChatColors.color(" &dRotation: &e" + ((Rotatable) b.getBlockData()).getRotation().toString()));
}
}
if (BlockStorage.getStorage(b.getWorld()).hasInventory(b.getLocation())) {
p.sendMessage(ChatColors.color("&dInventory: " + enabledTooltip));
}
else {
p.sendMessage(ChatColors.color("&dInventory: " + disabledTooltip));
}
TickerTask ticker = SlimefunPlugin.getTickerTask();
if (item.isTicking()) {
p.sendMessage(ChatColors.color("&dTicker: " + enabledTooltip));
p.sendMessage(ChatColors.color(" &dAsync: &e" + (BlockStorage.check(b).getBlockTicker().isSynchronized() ? disabledTooltip : enabledTooltip)));
p.sendMessage(ChatColors.color(" &dTimings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b))));
p.sendMessage(ChatColors.color(" &dTotal Timings: &e" + NumberUtils.getAsMillis(ticker.getTimings(BlockStorage.checkID(b)))));
p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b.getChunk()))));
}
else if (item.getEnergyTicker() != null) {
p.sendMessage(ChatColors.color("&dTicking: " + "&3Indirect"));
p.sendMessage(ChatColors.color(" &dTimings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b))));
p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b.getChunk()))));
}
else {
p.sendMessage(ChatColors.color("&dTicker: " + disabledTooltip));
p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&dTicking: " + disabledTooltip));
}
if (ChargableBlock.isChargable(b)) {
p.sendMessage(ChatColors.color("&dChargeable: " + enabledTooltip));
p.sendMessage(ChatColors.color(" &dEnergy: &e" + ChargableBlock.getCharge(b) + " / " + ChargableBlock.getMaxCharge(b)));
}
else {
p.sendMessage(ChatColors.color("&dChargeable: " + disabledTooltip));
}
p.sendMessage(ChatColors.color(" &dEnergyNet Type: &e" + EnergyNet.getComponent(b.getLocation())));
p.sendMessage(ChatColors.color("&6" + BlockStorage.getBlockInfoAsJson(b)));
p.sendMessage(" ");
}
protected static byte getLegacyData(BlockData skull) {
if (skull instanceof Rotatable) {
return LegacyBlockFace.getLegacyRotatableId(((Rotatable) skull).getRotation());
}
return 0;
}