Package org.bukkit.block

Examples of org.bukkit.block.BlockState


     * @param blocks The blocks of the grown vanilla tree to search.
     * @return The lowest x/z location.
     */
    private Location searchLowestXZLocation(int y, List<BlockState> blocks)
    {
        BlockState lowestXZ = null;
        for (BlockState blockState : blocks)
        {
            // Check if block has correct y
            if (blockState.getY() != y)
            {
                continue;
            }

            // Check if block is a log
            if (blockState.getType() != Material.LOG && blockState.getType() != Material.LOG_2)
            {
                continue;
            }

            if (lowestXZ == null)
            {
                // Found a candidate
                lowestXZ = blockState;
                continue;
            }

            if (blockState.getX() <= lowestXZ.getX() && blockState.getZ() <= lowestXZ.getZ())
            {
                // Found a better candidate
                lowestXZ = blockState;
                continue;
            }
        }

        if (lowestXZ == null)
        {
            return null;
        } else
        {
            return lowestXZ.getLocation();
        }
    }
View Full Code Here


            CreatureType.SKELETON, CreatureType.ZOMBIE,
            CreatureType.CREEPER, CreatureType.SPIDER
        };

        block.setType(Material.MOB_SPAWNER);
        BlockState state = block.getState();
        if (state instanceof CreatureSpawner) {
            ((CreatureSpawner) state).setCreatureType(types[random.nextInt(types.length)]);
        }
    }
View Full Code Here

        }
    }

    private static void placeChest(Random random, Block block) {
        block.setType(Material.CHEST);
        BlockState state = block.getState();
        if (state instanceof Chest) {
            Inventory chest = ((Chest) state).getInventory();

            for (int i = 0; i < 5; i++) {
                chest.setItem(random.nextInt(chest.getSize()), getRandomTool(random, i));
View Full Code Here

            int y = sourceY + random.nextInt(4) - random.nextInt(4);

            if (y < 255 && world.getBlockAt(x, y, z).getType() == Material.AIR &&
                    (world.getBlockAt(x, y - 1, z).getType() == Material.GRASS ||
                    world.getBlockAt(x, y - 1, z).getType() == Material.DIRT)) {
                final BlockState state = world.getBlockAt(x, y, z).getState();
                state.setType(Material.LONG_GRASS);
                state.setData(grass);
                state.update(true);
            }
        }
    }
View Full Code Here

        setTypes(3, 3);
    }

    @Override
    public boolean canPlaceOn() {
        final BlockState state = delegate.getBlockState(loc.getBlock().getRelative(BlockFace.DOWN).getLocation());
        return state.getType() == Material.GRASS || state.getType() == Material.DIRT;
    }
View Full Code Here

        setTypes(3, 0);
    }

    @Override
    public boolean canPlaceOn() {
        final BlockState state = delegate.getBlockState(loc.getBlock().getRelative(BlockFace.DOWN).getLocation());
        return state.getType() == Material.GRASS || state.getType() == Material.DIRT;
    }
View Full Code Here

        setHeight(random.nextInt(3) + random.nextInt(3) + 5);
    }

    @Override
    public boolean canPlaceOn() {
        final BlockState state = delegate.getBlockState(loc.getBlock().getRelative(BlockFace.DOWN).getLocation());
        return state.getType() == Material.GRASS || state.getType() == Material.DIRT;
    }
View Full Code Here

    public boolean canHeightFit() {
        return loc.getBlockY() >= 1 && loc.getBlockY() + height + 1 <= 255;
    }

    public boolean canPlaceOn() {
        final BlockState state = delegate.getBlockState(loc.getBlock().getRelative(BlockFace.DOWN).getLocation());
        return state.getType() == Material.GRASS || state.getType() == Material.DIRT || state.getType() == Material.SOIL;
    }
View Full Code Here

          if (!player.getEyeLocation().getBlock().equals(block) && !player.getLocation().getBlock().equals(block)) {
            CustomBlock cb = MaterialData.getCustomBlock(damage);

            if (cb != null && isReplaceable(block.getType())) {
              BlockState oldState = block.getState();
              block.setTypeIdAndData(cb.getBlockId(), (byte)(cb.getBlockData()), true);
              cb.onBlockPlace(block.getWorld(), block.getX(), block.getY(), block.getZ(), player);

              int rot = Math.round(player.getLocation().getYaw() + 45 % 360);
              boolean mirrored = player.getLocation().getPitch() < -45;
              if (rot < 0 ) {
                rot += 360;
              }
              rot = (2 - (rot/90)) % 4;
              if (rot < 0) {
                rot += 4;
              }
              byte rotation;
              if (cb.canMirroredRotate() && mirrored) {
                rotation = cb.canRotate() ? (byte) (rot + 4) : 4;
              } else {
                rotation = cb.canRotate() ? (byte) rot : 0;
              }
              mm.overrideBlock(block, cb, rotation);

              if (canPlaceAt(block, oldState, (SpoutBlock)event.getClickedBlock(), item, player)) {
                // Yay, take the item from inventory
                if (player.getGameMode() == GameMode.SURVIVAL) {
                  if (item.getAmount() == 1) {
                  // Remove this for Stuff 
                  event.getPlayer().setItemInHand(null);
                  } else {
                    item.setAmount(item.getAmount() - 1);
                  }
                }
                player.playSound(player.getLocation(), Sound.DIG_STONE, 1.0F, 0.7936508F);
                player.updateInventory();
                // Now we have placed a nice custom block! We should check its rotation and rotate the base block!
                if (cb.canRotate()) {
                  if (cb.canMirroredRotate() && mirrored) {
                    if (block.getType() == Material.LEVER || block.getType() == Material.TORCH || block.getType() == Material.STONE_BUTTON || block.getType() == Material.WOOD_BUTTON) {
                      // The below Types need a slightly different data value to assign correct positioning.
                      if (event.getBlockFace() == BlockFace.UP) {
                        block.setData((byte) 5);
                      } else if (event.getBlockFace() == BlockFace.DOWN) {
                        block.setData((byte) 7);
                      } else if (rot == 1) {
                        block.setData((byte) 1);
                      } else if (rot == 2) {
                        block.setData((byte) 4);
                      } else if (rot == 3) {
                        block.setData((byte) 2);
                      } else if (rot == 0) {
                        block.setData((byte) 3);
                      }
                    } else {
                      if (rot == 1) {
                        block.setData((byte) 5);
                      } else if (rot == 2) {
                        block.setData((byte) 6);
                      } else if (rot == 3) {
                        block.setData((byte) 4);
                      } else {
                        block.setData((byte) 7);
                      }
                    }
                  } else {
                    if (block.getType() == Material.LEVER || block.getType() == Material.TORCH || block.getType() == Material.STONE_BUTTON || block.getType() == Material.WOOD_BUTTON) {
                      // The below Types need a slightly different data value to assign correct positioning.
                      if (event.getBlockFace() == BlockFace.UP) {
                        block.setData((byte) 5);
                      } else if (event.getBlockFace() == BlockFace.DOWN) {
                        block.setData((byte) 7);
                      } else if (rot == 1) {
                        block.setData((byte) 1);
                      } else if (rot == 2) {
                        block.setData((byte) 4);
                      } else if (rot == 3) {
                        block.setData((byte) 2);
                      } else if (rot == 0) {
                        block.setData((byte) 3);
                      }
                    } else {
                      if (rot == 1) {
                        block.setData((byte) 1);
                      } else if (rot == 2) {
                        block.setData((byte) 2);
                      } else if (rot == 3) {
                        block.setData((byte) 0);
                      } else if (rot == 0 ){
                        block.setData((byte) 3);
                      }
                    }
                  }
                }
              } else {
                // Event cancelled or can't build
                mm.removeBlockOverride(block);
                block.setTypeIdAndData(oldState.getTypeId(), oldState.getRawData(), true);
              }
            }
          }
        }
      }
View Full Code Here

    if (block.isEmpty() && !getActualBlock(x, y - 1, z).isEmpty())
      setBlock(block, material, data);
  }
 
  public final void setBlock(Block block, Material material, MaterialData data) {
    BlockState state = block.getState();
    state.setType(material);
    state.setData(data);
    state.update(true, doPhysics);
  }
View Full Code Here

TOP

Related Classes of org.bukkit.block.BlockState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.