Java Code Examples for org.bukkit.block.data.Rotatable#setRotation()

The following examples show how to use org.bukkit.block.data.Rotatable#setRotation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProgrammableAndroid.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
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());
}
 
Example 2
Source File: ProgrammableAndroid.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
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());
    }
}
 
Example 3
Source File: Schematic.java    From ExoticGarden with GNU General Public License v3.0 4 votes vote down vote up
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());
                        }
                    }
                }
            }
        }
    }
}
 
Example 4
Source File: PlantsListener.java    From ExoticGarden with GNU General Public License v3.0 4 votes vote down vote up
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;
            }
        }
    }
}