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

The following examples show how to use org.bukkit.block.BlockFace#UP . 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: 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 2
Source File: CraftBlock.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Notch uses a 0-5 to mean DOWN, UP, NORTH, SOUTH, WEST, EAST
 * in that order all over. This method is convenience to convert for us.
 *
 * @return BlockFace the BlockFace represented by this number
 */
public static BlockFace notchToBlockFace(int notch) {
    switch (notch) {
    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 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: PistonBaseMaterial.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
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 5
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
private void handleDoor(BlockTransformEvent event, Door door) {
  BlockFace relative = door.isTopHalf() ? BlockFace.DOWN : BlockFace.UP;
  BlockState oldState = event.getOldState().getBlock().getRelative(relative).getState();
  BlockState newState = event.getBlock().getRelative(relative).getState();
  BlockTransformEvent toCall;
  if (event instanceof ParticipantBlockTransformEvent) {
    toCall =
        new ParticipantBlockTransformEvent(
            event, oldState, newState, ((ParticipantBlockTransformEvent) event).getPlayerState());
  } else if (event instanceof PlayerBlockTransformEvent) {
    toCall =
        new PlayerBlockTransformEvent(
            event, oldState, newState, ((PlayerBlockTransformEvent) event).getPlayerState());
  } else {
    toCall = new BlockTransformEvent(event, oldState, newState);
  }
  callEvent(toCall, true);
}
 
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: Button.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() {
    byte data = (byte) (getData() & 0x7);

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

        case 0x1:
            return BlockFace.WEST;

        case 0x2:
            return BlockFace.EAST;

        case 0x3:
            return BlockFace.NORTH;

        case 0x4:
            return BlockFace.SOUTH;

        case 0x5:
            return BlockFace.DOWN;
    }

    return null;
}
 
Example 8
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 9
Source File: Power.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
private void powerCreateFarmland(Player player, ItemStack tool, Block block) {
	if (block.getType().equals(Material.GRASS_BLOCK) || block.getType().equals(Material.DIRT)) {
		if (block.getWorld().getBlockAt(block.getLocation().add(0, 1, 0)).getType().equals(Material.AIR)) {
			if (tool.getItemMeta() instanceof Damageable) {
				Damageable damageable = (Damageable) tool.getItemMeta();
				damageable.setDamage(damageable.getDamage() + 1);
				tool.setItemMeta((ItemMeta) damageable);
			}

			PlayerInteractEvent event = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, tool, block, BlockFace.UP);
			Bukkit.getPluginManager().callEvent(event);

			block.setType(Material.FARMLAND); // Event only does Plugin event (no vanilla conversion to Farmland and
			// Tool-Damage)
		}
	}
}
 
Example 10
Source File: Tree.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get direction of the log
 *
 * @return one of:
 * <ul>
 * <li>BlockFace.TOP for upright (default)
 * <li>BlockFace.NORTH (east-west)
 * <li>BlockFace.WEST (north-south)
 * <li>BlockFace.SELF (directionless)
 * </ul>
 */
@SuppressWarnings("deprecation")
public BlockFace getDirection() {
    switch ((getData() >> 2) & 0x3) {
        case 0: // Up-down
        default:
            return BlockFace.UP;
        case 1: // North-south
            return BlockFace.WEST;
        case 2: // East-west
            return BlockFace.NORTH;
        case 3: // Directionless (bark on all sides)
            return BlockFace.SELF;
    }
}
 
Example 11
Source File: IndustrialMiner.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
public IndustrialMiner(Category category, SlimefunItemStack item, Material baseMaterial, boolean silkTouch, int range) {
    super(category, item, new ItemStack[] { null, null, null, new CustomItem(Material.PISTON, "Piston (facing up)"), new ItemStack(Material.CHEST), new CustomItem(Material.PISTON, "Piston (facing up)"), new ItemStack(baseMaterial), new ItemStack(SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14) ? Material.BLAST_FURNACE : Material.FURNACE), new ItemStack(baseMaterial) }, new ItemStack[0], BlockFace.UP);

    this.range = range;
    this.silkTouch = silkTouch;

    registerDefaultFuelTypes();
}
 
Example 12
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 13
Source File: RandomUtils.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public static BlockFace randomAdjacentFace(){
	BlockFace[] faces = new BlockFace[]{
		BlockFace.DOWN,
		BlockFace.UP,
		BlockFace.EAST,
		BlockFace.WEST,
		BlockFace.NORTH,
		BlockFace.SOUTH
	};
	return faces[randomInteger(0,faces.length-1)];
}
 
Example 14
Source File: PlayerInteract.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
	Player player = event.getPlayer();
	PlayerInventory inv = player.getInventory();
	ItemStack item = inv.getItemInMainHand();
	if (event.getHand() != null)
		switch (event.getHand()) {
		case OFF_HAND:
			item = inv.getItemInOffHand();
			break;
		default:
			break;
		}

	if (AdditionsAPI.isCustomItem(item)) {
		CustomItemPlayerInteractEvent customEvent = new CustomItemPlayerInteractEvent(event,
				new CustomItemStack(item));
		Bukkit.getServer().getPluginManager().callEvent(customEvent);
	}
	if (event.getAction() != null && event.getAction() == Action.RIGHT_CLICK_BLOCK
			&& ToolType.getToolType(item.getType()) != null
			&& ToolType.getToolType(item.getType()).equals(ToolType.HOE)) {
		Block block = event.getClickedBlock();
		Material material = block.getType();
		Location blockLoc = block.getLocation();
		blockLoc.setY(blockLoc.getBlockY() + 1);
		Material materialUp = blockLoc.getBlock().getType();
		@SuppressWarnings("deprecation")
		byte data = block.getData();

		BlockFace face = event.getBlockFace();
		if (materialUp == Material.AIR && (face == BlockFace.UP || face == BlockFace.EAST || face == BlockFace.NORTH
				|| face == BlockFace.SOUTH || face == BlockFace.WEST))
			if (shouldPlaySound(material, item, data, player))
				player.playSound(block.getLocation(), "additionsapi.hoe.till", 1.0F, 1.0F);
	}
}
 
Example 15
Source File: PaperPatch.java    From ViaVersion with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlace(BlockPlaceEvent e) {
    if (isOnPipe(e.getPlayer())) {
        Location location = e.getPlayer().getLocation();
        Location diff = location.clone().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D));
        Material block = e.getBlockPlaced().getType();
        if (isPlacable(block)) {
            return;
        }
        if (location.getBlock().equals(e.getBlock())) {
            e.setCancelled(true);
        } else {
            if (location.getBlock().getRelative(BlockFace.UP).equals(e.getBlock())) {
                e.setCancelled(true);
            } else {
                // Within radius of block
                if (Math.abs(diff.getX()) <= 0.8 && Math.abs(diff.getZ()) <= 0.8D) {
                    // Are they on the edge / shifting ish
                    if (diff.getY() <= 0.1D && diff.getY() >= -0.1D) {
                        e.setCancelled(true);
                        return;
                    }
                    BlockFace relative = e.getBlockAgainst().getFace(e.getBlock());
                    // Are they towering up, (handles some latency)
                    if (relative == BlockFace.UP) {
                        if (diff.getY() < 1D && diff.getY() >= 0D) {
                            e.setCancelled(true);
                        }
                    }
                }
            }
        }
    }
}
 
Example 16
Source File: Lever.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Sets the direction this lever is pointing in
 */
public void setFacingDirection(BlockFace face) {
    byte data = (byte) (getData() & 0x8);
    BlockFace attach = getAttachedFace();

    if (attach == BlockFace.DOWN) {
        switch (face) {
            case SOUTH:
            case NORTH:
                data |= 0x5;
                break;

            case EAST:
            case WEST:
                data |= 0x6;
                break;
        }
    } else if (attach == BlockFace.UP) {
        switch (face) {
            case SOUTH:
            case NORTH:
                data |= 0x7;
                break;

            case EAST:
            case WEST:
                data |= 0x0;
                break;
        }
    } else {
        switch (face) {
            case EAST:
                data |= 0x1;
                break;

            case WEST:
                data |= 0x2;
                break;

            case SOUTH:
                data |= 0x3;
                break;

            case NORTH:
                data |= 0x4;
                break;
        }
    }
    setData(data);
}
 
Example 17
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 18
Source File: ActiveMiner.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
private void setPistonState(Block block, boolean extended) {
    if (!running) {
        return;
    }

    try {
        // Smoke Particles around the Chest for dramatic effect
        Location particleLoc = chest.getLocation().clone().add(0, -1, 0);
        block.getWorld().spawnParticle(Particle.SMOKE_NORMAL, particleLoc, 20, 0.7, 0.7, 0.7, 0);

        if (block.getType() == Material.MOVING_PISTON) {
            // Yeah it isn't really cool when this happens
            block.getRelative(BlockFace.UP).setType(Material.AIR);
        }
        else if (block.getType() == Material.PISTON) {
            Block above = block.getRelative(BlockFace.UP);

            // Check if the above block is valid
            if (above.isEmpty() || above.getType() == Material.PISTON_HEAD) {
                Piston piston = (Piston) block.getBlockData();

                // Check if the piston is actually facing upwards
                if (piston.getFacing() == BlockFace.UP) {
                    setExtended(block, piston, extended);
                }
                else {
                    // The pistons must be facing upwards
                    stop("machines.INDUSTRIAL_MINER.piston-facing");
                }
            }
            else {
                // The pistons must be facing upwards
                stop("machines.INDUSTRIAL_MINER.piston-space");
            }
        }
        else {
            // The piston has been destroyed
            stop("machines.INDUSTRIAL_MINER.destroyed");
        }
    }
    catch (Exception e) {
        Slimefun.getLogger().log(Level.SEVERE, e, () -> "An Error occurred while moving a Piston for an Industrial Miner at " + new BlockPosition(block));
        stop();
    }
}
 
Example 19
Source File: MagicWorkbench.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
public MagicWorkbench(Category category, SlimefunItemStack item) {
    super(category, item, new ItemStack[] { null, null, null, null, null, null, new ItemStack(Material.BOOKSHELF), new ItemStack(Material.CRAFTING_TABLE), new ItemStack(Material.DISPENSER) }, new ItemStack[0], BlockFace.UP);
}
 
Example 20
Source File: ItemListener.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
   public void onCauldronClick(PlayerInteractEvent evt) {
       if (evt.getAction() == Action.RIGHT_CLICK_BLOCK) {
           if (evt.getBlockFace() == BlockFace.UP && evt.getClickedBlock().getType() == Material.CAULDRON && evt.getItem() != null && evt.getItem().getType() == Carbon.injector().bannerItemMat) {
           	evt.setCancelled(true);
           	ItemStack originalBanner = evt.getItem();
           	//create new banner with latest pattern removed
               net.minecraft.server.v1_7_R4.ItemStack nmsNewBanner = CraftItemStack.asNMSCopy(originalBanner);
               NBTTagCompound tag = nmsNewBanner.getTag();
               byte waterLevel = evt.getClickedBlock().getData();
               if (waterLevel > 0 && tag != null && tag.hasKey("BlockEntityTag") && tag.getCompound("BlockEntityTag").hasKey("Patterns")) {
                NBTTagCompound compound = tag.getCompound("BlockEntityTag");
                NBTTagList list = compound.getList("Patterns", 10);
                NBTTagList newList = new NBTTagList();
                for (int n = 0; n < list.size() - 1; n++) {
                    newList.add(list.get(n));
                }
                if (newList.size() > 0) {
                	compound.set("Patterns", newList);
                } else {
                	compound.remove("Patterns");
                }
                ItemStack newBannerItem = CraftItemStack.asCraftMirror(nmsNewBanner);
                newBannerItem.setAmount(1);
                //update cauldron
                evt.getClickedBlock().setData(--waterLevel);
                //update used itemstack
                if (originalBanner.getAmount() > 1) {
                	evt.getItem().setAmount(originalBanner.getAmount() - 1);
                } else {
                	evt.getItem().setAmount(0);
                	evt.getPlayer().setItemInHand(null);
                }
                //add new banner
                evt.getPlayer().getInventory().addItem(newBannerItem);
                evt.getPlayer().updateInventory();
               }
           }
       }
   }