Java Code Examples for org.bukkit.block.BlockFace#DOWN

The following examples show how to use org.bukkit.block.BlockFace#DOWN . 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: BlockListener.java    From Carbon with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void slabInteract(PlayerInteractEvent event) {
	if (event.getItem() == null || event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getItem().getType() != Carbon.injector().redSandstoneSlabMat)
		return;
	Block clickedBlock = event.getClickedBlock();
	if (clickedBlock.getType() == Carbon.injector().redSandstoneSlabMat)
		if ((clickedBlock.getData() == 0 && event.getBlockFace() == BlockFace.UP) || (clickedBlock.getData() == 8 && event.getBlockFace() == BlockFace.DOWN)) {
			setDoubleSlab(event.getPlayer(), clickedBlock);
			event.setCancelled(true);
			return;
		}
	Block adjacent = clickedBlock.getRelative(event.getBlockFace());
	if (adjacent.getType() == Carbon.injector().redSandstoneSlabMat) {
		setDoubleSlab(event.getPlayer(), adjacent);
		event.setCancelled(true);
	}
}
 
Example 2
Source File: WorldProblemListener.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void repairChunk(ChunkLoadEvent event) {
  if (this.repairedChunks.put(event.getWorld(), event.getChunk())) {
    // Replace formerly invisible half-iron-door blocks with barriers
    for (Block ironDoor : event.getChunk().getBlocks(Material.IRON_DOOR_BLOCK)) {
      BlockFace half = (ironDoor.getData() & 8) == 0 ? BlockFace.DOWN : BlockFace.UP;
      if (ironDoor.getRelative(half.getOppositeFace()).getType() != Material.IRON_DOOR_BLOCK) {
        ironDoor.setType(Material.BARRIER, false);
      }
    }

    // Remove all block 36 and remember the ones at y=0 so VoidFilter can check them
    for (Block block36 : event.getChunk().getBlocks(Material.PISTON_MOVING_PIECE)) {
      if (block36.getY() == 0) {
        block36Locations
            .get(event.getWorld())
            .add(block36.getX(), block36.getY(), block36.getZ());
      }
      block36.setType(Material.AIR, false);
    }
  }
}
 
Example 3
Source File: LWC.java    From Modern-LWC with MIT License 6 votes vote down vote up
/**
 * Find a protection that is adjacent to another block on any of the block's 6
 * sides
 *
 * @param block
 * @param ignore
 * @return
 */
public List<Protection> findAdjacentProtectionsOnAllSides(Block block, Block... ignore) {
    BlockFace[] faces = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST,
            BlockFace.UP, BlockFace.DOWN};
    List<Block> ignoreList = Arrays.asList(ignore);
    List<Protection> found = new ArrayList<Protection>();

    for (BlockFace face : faces) {
        Protection protection;
        Block adjacentBlock = block.getRelative(face);

        if (!ignoreList.contains(adjacentBlock.getLocation())
                && (protection = findProtection(adjacentBlock.getLocation())) != null) {
            found.add(protection);
        }
    }

    return found;
}
 
Example 4
Source File: LWC.java    From Modern-LWC with MIT License 6 votes vote down vote up
/**
 * Find a block that is adjacent to another block on any of the block's 6 sides
 * given a Material
 *
 * @param block
 * @param material
 * @param ignore
 * @return
 */
public Block findAdjacentBlockOnAllSides(Block block, Material material, Block... ignore) {
    BlockFace[] faces = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST,
            BlockFace.UP, BlockFace.DOWN};
    List<Block> ignoreList = Arrays.asList(ignore);

    for (BlockFace face : faces) {
        Block adjacentBlock = block.getRelative(face);

        if (adjacentBlock.getType() == material && !ignoreList.contains(adjacentBlock)) {
            return adjacentBlock;
        }
    }

    return null;
}
 
Example 5
Source File: Banner.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public BlockFace getAttachedFace() {
    if (isWallBanner()) {
        byte data = getData();

        switch (data) {
            case 0x2:
                return BlockFace.SOUTH;

            case 0x3:
                return BlockFace.NORTH;

            case 0x4:
                return BlockFace.EAST;

            case 0x5:
                return BlockFace.WEST;
        }

        return null;
    } else {
        return BlockFace.DOWN;
    }
}
 
Example 6
Source File: Observer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public BlockFace getFacing() {
    int data = getData() & 0x7;

    switch (data) {
        case 0x0:
            return BlockFace.DOWN;
        case 0x1:
            return BlockFace.UP;
        case 0x2:
            return BlockFace.SOUTH;
        case 0x3:
            return BlockFace.NORTH;
        case 0x4:
            return BlockFace.EAST;
        case 0x5:
            return BlockFace.WEST;
        default:
            throw new IllegalArgumentException("Illegal facing direction " + data);
    }
}
 
Example 7
Source File: Dispenser.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public BlockFace getFacing() {
    int data = getData() & 0x7;

    switch (data) {
        case 0x0:
            return BlockFace.DOWN;

        case 0x1:
            return BlockFace.UP;

        case 0x2:
            return BlockFace.NORTH;

        case 0x3:
            return BlockFace.SOUTH;

        case 0x4:
            return BlockFace.WEST;

        case 0x5:
        default:
            return BlockFace.EAST;
    }
}
 
Example 8
Source File: PistonExtensionMaterial.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public BlockFace getFacing() {
    byte dir = (byte) (getData() & 7);

    switch (dir) {
        case 0:
            return BlockFace.DOWN;
        case 1:
            return BlockFace.UP;
        case 2:
            return BlockFace.NORTH;
        case 3:
            return BlockFace.SOUTH;
        case 4:
            return BlockFace.WEST;
        case 5:
            return BlockFace.EAST;
        default:
            return BlockFace.SELF;
    }
}
 
Example 9
Source File: Sign.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the face that this block is attached on
 *
 * @return BlockFace attached to
 */
public BlockFace getAttachedFace() {
    if (isWallSign()) {
        byte data = getData();

        switch (data) {
            case 0x2:
                return BlockFace.SOUTH;

            case 0x3:
                return BlockFace.NORTH;

            case 0x4:
                return BlockFace.EAST;

            case 0x5:
                return BlockFace.WEST;
        }

        return null;
    } else {
        return BlockFace.DOWN;
    }
}
 
Example 10
Source File: Lever.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the face that this block is attached on
 *
 * @return BlockFace attached to
 */
public BlockFace getAttachedFace() {
    byte data = (byte) (getData() & 0x7);

    switch (data) {
        case 0x1:
            return BlockFace.WEST;

        case 0x2:
            return BlockFace.EAST;

        case 0x3:
            return BlockFace.NORTH;

        case 0x4:
            return BlockFace.SOUTH;

        case 0x5:
        case 0x6:
            return BlockFace.DOWN;

        case 0x0:
        case 0x7:
            return BlockFace.UP;

    }

    return null;
}
 
Example 11
Source File: CraftBlock.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public int getBlockPower(BlockFace face) {
    int power = 0;
    BlockRedstoneWire wire = Blocks.redstone_wire;
    net.minecraft.world.World world = chunk.getHandle().worldObj;
    if ((face == BlockFace.DOWN || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y - 1, z, 0)) power = wire.func_150178_a(world, x, y - 1, z, power);
    if ((face == BlockFace.UP || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y + 1, z, 1)) power = wire.func_150178_a(world, x, y + 1, z, power);
    if ((face == BlockFace.EAST || face == BlockFace.SELF) && world.getIndirectPowerOutput(x + 1, y, z, 2)) power = wire.func_150178_a(world, x + 1, y, z, power);
    if ((face == BlockFace.WEST || face == BlockFace.SELF) && world.getIndirectPowerOutput(x - 1, y, z, 3)) power = wire.func_150178_a(world, x - 1, y, z, power);
    if ((face == BlockFace.NORTH || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y, z - 1, 4)) power = wire.func_150178_a(world, x, y, z - 1, power);
    if ((face == BlockFace.SOUTH || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y, z + 1, 5)) power = wire.func_150178_a(world, x, y, z - 1, power);
    return power > 0 ? power : (face == BlockFace.SELF ? isBlockIndirectlyPowered() : isBlockFaceIndirectlyPowered(face)) ? 15 : 0;
}
 
Example 12
Source File: TestMultiBlocks.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testValidConstructor() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test"));
    MultiBlock multiblock = new MultiBlock(item, new Material[9], BlockFace.DOWN);

    Assertions.assertEquals(item, multiblock.getSlimefunItem());
    Assertions.assertArrayEquals(new Material[9], multiblock.getStructure());
    Assertions.assertEquals(BlockFace.DOWN, multiblock.getTriggerBlock());
}
 
Example 13
Source File: TestMultiBlocks.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEqual() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test"));

    MultiBlock multiblock = new MultiBlock(item, new Material[] { Material.BIRCH_WOOD, Material.BIRCH_WOOD, Material.BIRCH_WOOD, null, Material.CRAFTING_TABLE, null, Material.BIRCH_WOOD, Material.DISPENSER, Material.BIRCH_WOOD }, BlockFace.DOWN);
    MultiBlock multiblock2 = new MultiBlock(item, new Material[] { Material.BIRCH_WOOD, Material.BIRCH_WOOD, Material.BIRCH_WOOD, null, Material.CRAFTING_TABLE, null, Material.BIRCH_WOOD, Material.DISPENSER, Material.BIRCH_WOOD }, BlockFace.DOWN);

    Assertions.assertTrue(multiblock.equals(multiblock2));
}
 
Example 14
Source File: TestMultiBlocks.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testNotEqual() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test"));

    MultiBlock multiblock = new MultiBlock(item, new Material[] { Material.BIRCH_WOOD, Material.BIRCH_WOOD, Material.BIRCH_WOOD, null, Material.CRAFTING_TABLE, null, Material.BIRCH_WOOD, Material.DISPENSER, Material.BIRCH_WOOD }, BlockFace.DOWN);
    MultiBlock multiblock2 = new MultiBlock(item, new Material[] { Material.BIRCH_WOOD, Material.BIRCH_WOOD, Material.BIRCH_WOOD, null, Material.EMERALD_BLOCK, null, Material.BIRCH_WOOD, Material.DISPENSER, Material.BIRCH_WOOD }, BlockFace.DOWN);
    MultiBlock multiblock3 = new MultiBlock(item, new Material[] { Material.DROPPER, Material.BIRCH_WOOD, Material.BIRCH_WOOD, null, Material.DIAMOND_BLOCK, null, Material.BIRCH_WOOD, Material.DISPENSER, Material.TNT }, BlockFace.DOWN);
    MultiBlock multiblock4 = new MultiBlock(item, new Material[] { Material.BIRCH_WOOD, Material.BIRCH_WOOD, Material.BIRCH_WOOD, null, Material.CRAFTING_TABLE, null, Material.BIRCH_WOOD, Material.DISPENSER, Material.BIRCH_WOOD }, BlockFace.SELF);

    Assertions.assertFalse(multiblock.equals(null));
    Assertions.assertFalse(multiblock.equals(multiblock2));
    Assertions.assertFalse(multiblock.equals(multiblock3));
    Assertions.assertFalse(multiblock.equals(multiblock4));
}
 
Example 15
Source File: FallingBlocksRule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Test if the given block is supportive from the given direction,
 * either because this rule makes the block sticky, or because it's
 * a solid block supporting from below.
 */
public boolean canSupport(@Nullable Block supporter, BlockFace from) {
    if(supporter == null || supporter.getType() == Material.AIR) return false;
    if(from == BlockFace.DOWN && Materials.canSupportBlocks(supporter.getType())) return true;
    return canSupport(supporter);
}
 
Example 16
Source File: BlockFromToListener.java    From IridiumSkyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
    try {
        final Block block = event.getBlock();
        final Location location = block.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(location);
        if (island == null) return;

        final Material material = block.getType();
        final Block toBlock = event.getToBlock();
        final Location toLocation = toBlock.getLocation();

        if (material.equals(Material.WATER) || material.equals(Material.LAVA)) {
            final Island toIsland = islandManager.getIslandViaLocation(toLocation);
            if (island != toIsland)
                event.setCancelled(true);
        }

        if (!IridiumSkyblock.getUpgrades().oresUpgrade.enabled) return;

        if (event.getFace() == BlockFace.DOWN) return;

        if (!isSurroundedByWater(toLocation))
            return;

        final int oreLevel = island.getOreLevel();
        final World world = location.getWorld();
        if (world == null) return;

        final String worldName = world.getName();
        final Config config = IridiumSkyblock.getConfiguration();
        List<String> islandOreUpgrades;
        if (worldName.equals(config.worldName)) islandOreUpgrades = IridiumSkyblock.oreUpgradeCache.get(oreLevel);
        else if (worldName.equals(config.netherWorldName)) islandOreUpgrades = IridiumSkyblock.netherOreUpgradeCache.get(oreLevel);
        else return;

        Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> {
            final Material toMaterial = toBlock.getType();
            if (!(toMaterial.equals(Material.COBBLESTONE) || toMaterial.equals(Material.STONE)))
                return;

            final Random random = new Random();
            final String oreUpgrade = islandOreUpgrades.get(random.nextInt(islandOreUpgrades.size()));

            final XMaterial oreUpgradeXmaterial = XMaterial.valueOf(oreUpgrade);
            final Material oreUpgradeMaterial = oreUpgradeXmaterial.parseMaterial(true);
            if (oreUpgradeMaterial == null) return;

            toBlock.setType(oreUpgradeMaterial);

            final BlockState blockState = toBlock.getState();
            blockState.update(true);

            if (Utils.isBlockValuable(toBlock)) {
                final XMaterial xmaterial = XMaterial.matchXMaterial(material);
                island.valuableBlocks.compute(xmaterial.name(), (name, original) -> {
                    if (original == null) return 1;
                    return original + 1;
                });
                if (island.updating)
                    island.tempValues.add(location);
                island.calculateIslandValue();
            }
        });
    } catch (Exception ex) {
        IridiumSkyblock.getInstance().sendErrorMessage(ex);
    }
}
 
Example 17
Source File: MakeshiftSmeltery.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
public MakeshiftSmeltery(Category category, SlimefunItemStack item) {
    super(category, item, new ItemStack[] { null, new ItemStack(Material.OAK_FENCE), null, new ItemStack(Material.BRICKS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.BRICKS), null, new ItemStack(Material.FLINT_AND_STEEL), null }, new ItemStack[0], BlockFace.DOWN);
}
 
Example 18
Source File: Utils.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Determines the axis-aligned {@link BlockFace} for the given direction.
 * If modY is zero only {@link BlockFace}s facing horizontal will be returned.
 * This method takes into account that the values for EAST/WEST and NORTH/SOUTH
 * were switched in some past version of bukkit. So it should also properly work
 * with older bukkit versions.
 * 
 * @param modX
 * @param modY
 * @param modZ
 * @return
 */
public static BlockFace getAxisBlockFace(double modX, double modY, double modZ) {
	double xAbs = Math.abs(modX);
	double yAbs = Math.abs(modY);
	double zAbs = Math.abs(modZ);

	if (xAbs >= zAbs) {
		if (xAbs >= yAbs) {
			if (modX >= 0.0D) {
				// EAST/WEST and NORTH/SOUTH values were switched in some past bukkit version:
				// with this additional checks it should work across different versions
				if (BlockFace.EAST.getModX() == 1) {
					return BlockFace.EAST;
				} else {
					return BlockFace.WEST;
				}
			} else {
				if (BlockFace.EAST.getModX() == 1) {
					return BlockFace.WEST;
				} else {
					return BlockFace.EAST;
				}
			}
		} else {
			if (modY >= 0.0D) {
				return BlockFace.UP;
			} else {
				return BlockFace.DOWN;
			}
		}
	} else {
		if (zAbs >= yAbs) {
			if (modZ >= 0.0D) {
				if (BlockFace.SOUTH.getModZ() == 1) {
					return BlockFace.SOUTH;
				} else {
					return BlockFace.NORTH;
				}
			} else {
				if (BlockFace.SOUTH.getModZ() == 1) {
					return BlockFace.NORTH;
				} else {
					return BlockFace.SOUTH;
				}
			}
		} else {
			if (modY >= 0.0D) {
				return BlockFace.UP;
			} else {
				return BlockFace.DOWN;
			}
		}
	}
}
 
Example 19
Source File: BlockListener.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlace(BlockPlaceEvent e) {

    final Material type = e.getBlock().getType();
    final Block placingBlock = e.getBlock();
    final Player player = e.getPlayer();

    if (type != Material.CHEST) {
        return;
    }
    Block chest = null;
    //Chest combine mechanic based checking
    if (player.isSneaking()) {
        Block blockAgainst = e.getBlockAgainst();
        if (blockAgainst.getType() == Material.CHEST && placingBlock.getFace(blockAgainst) != BlockFace.UP && placingBlock.getFace(blockAgainst) != BlockFace.DOWN && !(((Chest) blockAgainst.getState()).getInventory() instanceof DoubleChestInventory)) {
            chest = e.getBlockAgainst();
        } else {
            return;
        }
    } else {
        //Get all chest in vertical Location
        BlockFace placingChestFacing = ((Directional) (placingBlock.getState().getBlockData())).getFacing();
        for (BlockFace face : Util.getVerticalFacing()) {
            //just check the right side and left side
            if (face != placingChestFacing && face != placingChestFacing.getOppositeFace()) {
                Block nearByBlock = placingBlock.getRelative(face);
                if (nearByBlock.getType() == Material.CHEST
                        //non double chest
                        && !(((Chest) nearByBlock.getState()).getInventory() instanceof DoubleChestInventory)
                        //same facing
                        && placingChestFacing == ((Directional) nearByBlock.getState().getBlockData()).getFacing()) {
                    if (chest == null) {
                        chest = nearByBlock;
                    } else {
                        //when multiply chests competed, minecraft will always combine with right side
                        if (placingBlock.getFace(nearByBlock) == Util.getRightSide(placingChestFacing)) {
                            chest = nearByBlock;
                        }
                    }
                }
            }
        }
    }
    if (chest == null) {
        return;
    }

    Shop shop = getShopPlayer(chest.getLocation(), false);
    if (shop != null) {
        if (!QuickShop.getPermissionManager().hasPermission(player, "quickshop.create.double")) {
            e.setCancelled(true);
            MsgUtil.sendMessage(player, MsgUtil.getMessage("no-double-chests", player));

        } else if (!shop.getModerator().isModerator(player.getUniqueId())) {
            e.setCancelled(true);
            MsgUtil.sendMessage(player, MsgUtil.getMessage("not-managed-shop", player));
        }
    }
}
 
Example 20
Source File: FallingBlocksRule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Test if the given block is supportive from the given direction, either because this rule makes
 * the block sticky, or because it's a solid block supporting from below.
 */
public boolean canSupport(@Nullable Block supporter, BlockFace from) {
  return supporter != null
      && (from == BlockFace.DOWN && Materials.isSolid(supporter.getType())
          || this.canSupport(supporter));
}