本文整理了Java中org.bukkit.block.Block.getRelative()
方法的一些代码示例,展示了Block.getRelative()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.getRelative()
方法的具体详情如下:
包路径:org.bukkit.block.Block
类名称:Block
方法名:getRelative
[英]Gets the block at the given offsets
[中]获取给定偏移处的块
代码示例来源:origin: Bukkit/Bukkit
/**
* Convenience method for getting the faced Block.
*
* @return The faced Block
*/
public Block getToBlock() {
if (to == null) {
to = block.getRelative(face);
}
return to;
}
代码示例来源:origin: GlowstoneMC/Glowstone
private boolean isNearWater(Block block) {
for (BlockFace face : SIDES) {
switch (block.getRelative(face).getType()) {
case WATER:
case STATIONARY_WATER:
return true;
default:
break;
}
}
return false;
}
代码示例来源:origin: Bukkit/Bukkit
/**
* Get an immutable list of the blocks which will be moved by the
* extending.
*
* @return Immutable list of the moved blocks.
*/
public List<Block> getBlocks() {
if (blocks == null) {
ArrayList<Block> tmp = new ArrayList<Block>();
for (int i = 0; i < this.getLength(); i++) {
tmp.add(block.getRelative(getDirection(), i + 1));
}
blocks = Collections.unmodifiableList(tmp);
}
return blocks;
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public boolean canSpawn(World world, int x, int z) {
Block block = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN);
return block.getType() == Material.ENDER_STONE;
}
代码示例来源:origin: GlowstoneMC/Glowstone
private boolean hasDownSupport(Block block) {
Block down = block.getRelative(BlockFace.DOWN);
return down.getType() == Material.CHORUS_PLANT || down.getType() == Material.ENDER_STONE;
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public boolean canSpawn(World world, int x, int z) {
Block block = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN);
return block.getType() == Material.NETHERRACK;
}
代码示例来源:origin: Bukkit/Bukkit
/**
* Gets the location where the possible moving block might be if the
* retracting piston is sticky.
*
* @return The possible location of the possibly moving block.
*/
public Location getRetractLocation() {
return getBlock().getRelative(getDirection(), 2).getLocation();
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Generates up to 64 flowers around the given point.
*/
@Override
public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
boolean succeeded = false;
for (int i = 0; i < 64; i++) {
int x = sourceX + random.nextInt(8) - random.nextInt(8);
int z = sourceZ + random.nextInt(8) - random.nextInt(8);
int y = sourceY + random.nextInt(4) - random.nextInt(4);
Block block = world.getBlockAt(x, y, z);
if (y < 255 && block.getType() == Material.AIR
&& block.getRelative(BlockFace.DOWN).getType() == Material.GRASS) {
block.setType(type);
block.setData((byte) data);
succeeded = true;
}
}
return succeeded;
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public boolean canSpawn(World world, int x, int z) {
Block block = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN);
return !block.isLiquid() && !block.isEmpty() && !noSpawnFloors.contains(block.getType());
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Removes the grass, shrub, flower or mushroom directly above the given block, if present. Does
* not drop an item.
*
* @param block the block to update
* @return true if a plant was removed; false if none was present
*/
static boolean killPlantAbove(Block block) {
Block blockAbove = block.getRelative(BlockFace.UP);
Material mat = blockAbove.getType();
if (PLANT_TYPES.contains(mat)) {
if (mat == Material.DOUBLE_PLANT) {
MaterialData dataAbove = blockAbove.getState().getData();
if (dataAbove instanceof DoublePlant
&& ((DoublePlant) dataAbove).getSpecies()
== DoublePlantSpecies.PLANT_APEX) {
blockAbove.getRelative(BlockFace.UP)
.setType(Material.AIR);
}
}
blockAbove.setType(Material.AIR);
return true;
}
return false;
}
代码示例来源:origin: GlowstoneMC/Glowstone
private boolean isPistonExtended(Block block) {
// TODO: check direction of piston_extension to make sure that the extension is attached to
// piston
Block pistonHead = block
.getRelative(((PistonBaseMaterial) block.getState().getData()).getFacing());
return pistonHead.getType() == Material.PISTON_EXTENSION;
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Generates or extends a cactus, if there is space.
*/
@Override
public boolean generate(World world, Random random, int x, int y, int z) {
if (world.getBlockAt(x, y, z).isEmpty()) {
int height = random.nextInt(random.nextInt(3) + 1) + 1;
for (int n = y; n < y + height; n++) {
Block block = world.getBlockAt(x, n, z);
Material typeBelow = block.getRelative(BlockFace.DOWN).getType();
if ((typeBelow == Material.SAND || typeBelow == Material.CACTUS)
&& block.getRelative(BlockFace.UP).isEmpty()) {
for (BlockFace face : FACES) {
if (block.getRelative(face).getType().isSolid()) {
return n > y;
}
}
BlockState state = block.getState();
state.setType(Material.CACTUS);
state.setData(new MaterialData(Material.CACTUS));
state.update(true);
}
}
}
return true;
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
Block thisBlock;
do {
thisBlock = world.getBlockAt(sourceX, sourceY, sourceZ);
sourceY--;
} while ((thisBlock.isEmpty() || thisBlock.getType() == Material.LEAVES) && sourceY > 0);
sourceY++;
boolean succeeded = false;
for (int i = 0; i < 128; i++) {
int x = sourceX + random.nextInt(8) - random.nextInt(8);
int z = sourceZ + random.nextInt(8) - random.nextInt(8);
int y = sourceY + random.nextInt(4) - random.nextInt(4);
Block block = world.getBlockAt(x, y, z);
Material blockTypeBelow = block.getRelative(BlockFace.DOWN).getType();
if (y < 255 && block.getType() == Material.AIR && (
blockTypeBelow == Material.GRASS || blockTypeBelow == Material.DIRT)) {
BlockState state = block.getState();
state.setType(Material.LONG_GRASS);
state.setData(grassType);
state.update(true);
succeeded = true;
}
}
return succeeded;
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public void setOnGround(boolean onGround) {
float fallDistance = getFallDistance();
if (onGround && fallDistance > 3f) {
float damage = fallDistance - 3f;
damage = Math.round(damage);
if (damage > 0f) {
Material standingType = location.getBlock().getRelative(BlockFace.DOWN).getType();
// todo: only when bouncing
if (standingType == Material.SLIME_BLOCK) {
damage = 0f;
}
if (standingType == Material.HAY_BLOCK) {
damage *= 0.2f;
}
damage(damage, DamageCause.FALL);
}
}
super.setOnGround(onGround);
}
代码示例来源:origin: GlowstoneMC/Glowstone
private void addCocoa(int sourceX, int sourceY, int sourceZ, World world, Random random) {
if (height > 5 && random.nextInt(5) == 0) {
for (int y = 0; y < 2; y++) {
for (BlockFace cocoaFace : COCOA_FACES) { // rotate the 4 trunk faces
if (random.nextInt(COCOA_FACES.length - y)
== 0) { // higher it is, more chances there is
CocoaPlantSize size = COCOA_SIZE[random.nextInt(COCOA_SIZE.length)];
Block block = delegate
.getBlockState(world, sourceX, sourceY + height - 5 + y,
sourceZ)
.getBlock().getRelative(cocoaFace);
delegate.setTypeAndData(world, block.getX(), block.getY(),
block.getZ(),
Material.COCOA, new CocoaPlant(size, cocoaFace.getOppositeFace()));
}
}
}
}
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
|| block.getRelative(BlockFace.UP).getType() != Material.NETHERRACK) {
return;
int airBlockCount = 0;
for (BlockFace face : SIDES) {
Block neighbor = block.getRelative(face);
if (neighbor.getType() == Material.NETHERRACK) {
netherrackBlockCount++;
代码示例来源:origin: GlowstoneMC/Glowstone
private boolean canHoldPainting(Location where) {
Block block = where.getBlock();
if (block.getType().isSolid()) {
return false;
}
Block behind = block.getRelative(getAttachedFace());
return behind.getType().isSolid();
}
代码示例来源:origin: GlowstoneMC/Glowstone
private void placeBoat(GlowPlayer player, ItemStack holding) {
Block targetBlock = player.getTargetBlock((Set<Material>) null, 5);
if (targetBlock != null && !targetBlock.isEmpty()
&& targetBlock.getRelative(BlockFace.UP).isEmpty()) {
Location location = targetBlock.getRelative(BlockFace.UP).getLocation();
// center boat on cursor location
location.add(0.6875f, 0, 0.6875f);
location.setYaw(player.getLocation().getYaw());
Boat boat = targetBlock.getWorld().spawn(location, Boat.class);
boat.setWoodType(woodType);
if (player.getGameMode() != GameMode.CREATIVE) {
player.getInventory().removeItem(holding);
}
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
protected void jump() {
if (location.getBlock().isLiquid()) {
// jump out more when you breach the surface of the liquid
if (location.getBlock().getRelative(BlockFace.UP).isEmpty()) {
velocity.setY(velocity.getY() + 0.3);
}
// less jumping in liquid
velocity.setY(velocity.getY() + 0.04);
} else {
// jump normally
velocity.setY(velocity.getY() + 0.42);
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public void pulse() {
super.pulse();
if (ticksLived % (20 * 5) == 0) {
if (location.getBlock().getRelative(getAttachedFace()).getType() == Material.AIR) {
if (EventFactory.getInstance()
.callEvent(new HangingBreakEvent(this, RemoveCause.PHYSICS))
.isCancelled()) {
return;
}
world.dropItemNaturally(location, new ItemStack(Material.ITEM_FRAME));
if (!isEmpty()) {
world.dropItemNaturally(location, getItem().clone());
}
remove();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!