org.bukkit.block.BlockFace#UP源码实例Demo

下面列出了org.bukkit.block.BlockFace#UP 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: PGM   文件: BlockTransformListener.java
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);
}
 
源代码2 项目: MineTinker   文件: Power.java
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)
		}
	}
}
 
源代码3 项目: Carbon   文件: BlockListener.java
@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);
	}
}
 
源代码4 项目: Kettle   文件: Button.java
/**
 * 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;
}
 
源代码5 项目: Kettle   文件: Observer.java
@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);
    }
}
 
源代码6 项目: Kettle   文件: PistonExtensionMaterial.java
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;
    }
}
 
源代码7 项目: Kettle   文件: PistonBaseMaterial.java
@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;
    }
}
 
源代码8 项目: Modern-LWC   文件: LWC.java
/**
 * 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;
}
 
源代码9 项目: Thermos   文件: CraftBlock.java
/**
 * 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;
    }
}
 
源代码10 项目: Thermos   文件: CraftBlock.java
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;
}
 
源代码11 项目: Kettle   文件: Tree.java
/**
 * 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;
    }
}
 
源代码12 项目: Slimefun4   文件: IndustrialMiner.java
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();
}
 
源代码13 项目: UhcCore   文件: RandomUtils.java
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)];
}
 
源代码14 项目: AdditionsAPI   文件: PlayerInteract.java
@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);
	}
}
 
源代码15 项目: ViaVersion   文件: PaperPatch.java
@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);
                        }
                    }
                }
            }
        }
    }
}
 
源代码16 项目: Carbon   文件: ItemListener.java
@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();
               }
           }
       }
   }
 
源代码17 项目: Kettle   文件: Lever.java
/**
 * 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);
}
 
源代码18 项目: Shopkeepers   文件: Utils.java
/**
 * 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;
			}
		}
	}
}
 
源代码19 项目: Slimefun4   文件: ActiveMiner.java
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();
    }
}
 
源代码20 项目: Slimefun4   文件: MagicWorkbench.java
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);
}