当前位置: 首页>>代码示例>>Java>>正文


Java Location.getBlock方法代码示例

本文整理汇总了Java中org.bukkit.Location.getBlock方法的典型用法代码示例。如果您正苦于以下问题:Java Location.getBlock方法的具体用法?Java Location.getBlock怎么用?Java Location.getBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.Location的用法示例。


在下文中一共展示了Location.getBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStandingOn

import org.bukkit.Location; //导入方法依赖的package包/类
public static List<Block> getStandingOn(Location playerLoc, double entityWidth) {
    double halfWidth = entityWidth / 2;

    List<Block> blocksUnderPlayer = new ArrayList<>(2);
    for (int firstSign = -1; firstSign <= 1; firstSign += 2) {
        for (int secondSign = -1; secondSign <= 1; secondSign += 2) {
            Location blockLoc = playerLoc.clone().add(firstSign * halfWidth, 0, secondSign * halfWidth);
            Block block = blockLoc.getBlock();
            if (!blocksUnderPlayer.contains(block)) {
                blocksUnderPlayer.add(block);
            }
        }
    }

    return blocksUnderPlayer;
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:17,代码来源:LocationUtils.java

示例2: hasBlock

import org.bukkit.Location; //导入方法依赖的package包/类
/**
 * Check if a block is under the player.
 *
 * @param location   the location
 * @param comparable the class to check against.
 * @return true if the block is under the player.
 */
public static boolean hasBlock(Location location, Class comparable) {
    LocationBit bit = new LocationBit(0.3);

    // check if were already under that block.
    Location subtracted = location.clone().subtract(0, 0.3, 0);
    Block subtractedBlock = subtracted.getBlock();

    if (subtractedBlock.getType().getData().equals(comparable)) {
        return true;
    }

    for (int i = 1; i <= 4; i++) {
        Location newLocation = location.clone().add(bit.getX(), -0.3, bit.getZ());
        Block block = newLocation.getBlock();
        if (block.getType().getData().equals(comparable)) {
            return true;
        }
        bit.shift(i);
    }
    return false;
}
 
开发者ID:Vrekt,项目名称:Arc-v2,代码行数:29,代码来源:LocationHelper.java

示例3: getNearbyEntities

import org.bukkit.Location; //导入方法依赖的package包/类
public static List<Entity> getNearbyEntities(Location center, double radius, EntityType filter)
{
    double chunkRadius = radius < 16 ? 1 : (radius - (radius % 16)) / 16;
    List<Entity> entities = new ArrayList<>();

    for (double chX = 0 - chunkRadius; chX <= chunkRadius; chX++)
    {
        for (double chZ = 0 - chunkRadius; chZ <= chunkRadius; chZ++)
        {
            double x = center.getX();
            double y = center.getY();
            double z = center.getZ();

            for (Entity entity : new Location(center.getWorld(), x + (chX * 16), y, z + (chZ * 16)).getChunk().getEntities())
            {
                if (filter != null && entity.getType() != filter)
                    continue;

                if (entity.getLocation().distance(center) <= radius && entity.getLocation().getBlock() != center.getBlock())
                    entities.add(entity);
            }
        }
    }

    return entities;
}
 
开发者ID:SamaGames,项目名称:SamaGamesAPI,代码行数:27,代码来源:ProximityUtils.java

示例4: isOnSlab

import org.bukkit.Location; //导入方法依赖的package包/类
/**
 * @return if we are on a slab.
 */
public static boolean isOnSlab(Location location) {
    LocationBit bit = new LocationBit(0.5);

    // check if were already under that block.
    Location subtracted = location.clone().subtract(0, 0.1, 0);
    Block subtractedBlock = subtracted.getBlock();

    if (subtractedBlock.getType().getData().equals(Step.class)) {
        return true;
    }

    for (int i = 1; i <= 4; i++) {
        Location newLocation = location.clone().add(bit.getX(), -0.1, bit.getZ());
        Block block = newLocation.getBlock();
        if (block.getType().getData().equals(Step.class)) {
            return true;
        }
        bit.shift(i);
    }
    return false;
}
 
开发者ID:Vrekt,项目名称:Arc-v2,代码行数:25,代码来源:LocationHelper.java

示例5: onInteract

import org.bukkit.Location; //导入方法依赖的package包/类
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
	Player p = e.getPlayer();
	if(hasPermission(enchant_open, p))
	{	
	
	Location loc = new Location(p.getWorld(), 10000.0D, 255.0D, 10000.0D);
	//Can't be handled differently :(
	Block im5 = loc.getBlock();
       if(im5.getType() != Material.ENCHANTMENT_TABLE)
       {
          im5.setType(Material.ENCHANTMENT_TABLE);
       }
	
       p.openEnchanting(loc, true);
	}
	super.onInteract(e, es);
}
 
开发者ID:benfah,项目名称:Bags2,代码行数:20,代码来源:BagEnchant.java

示例6: isIllegallyOutsideLane

import org.bukkit.Location; //导入方法依赖的package包/类
private static boolean isIllegallyOutsideLane(Region lane, Location loc) {
    Block feet = loc.getBlock();
    if(feet == null) return false;

    if(isIllegalBlock(lane, feet)) {
        return true;
    }

    Block head = feet.getRelative(BlockFace.UP);
    if(head == null) return false;

    if(isIllegalBlock(lane, head)) {
        return true;
    }

    return false;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:18,代码来源:LaneMatchModule.java

示例7: onPlace

import org.bukkit.Location; //导入方法依赖的package包/类
@EventHandler
public void onPlace(BlockPlaceEvent e) {
	if (e.isCancelled()) {
		return;
	}
	if (!e.getBlock().getType().equals(Material.CAULDRON)) {
		return;
	}
	Block b = e.getBlock();
	Location loc = b.getLocation();
	loc.setY(loc.getY() + 1);
	Block upon = loc.getBlock();
	if (upon.getType().equals(Material.AIR)) {
		return;
	}
	e.setCancelled(true);
	e.getPlayer().sendMessage(Messages.getMessages().getNoPlace().replace("&", "§"));
}
 
开发者ID:Soldier233,项目名称:SlimefunBugFixer,代码行数:19,代码来源:Listeners.java

示例8: clearVisualBlock

import org.bukkit.Location; //导入方法依赖的package包/类
/**
 * Clears a visual block at a given location for a player.
 *
 * @param player
 *            the player to clear for
 * @param location
 *            the location to clear at
 * @param sendRemovalPacket
 *            if a packet to send a block change should be sent (this is used to prevent unnecessary packets sent when disconnecting or changing worlds, for example)
 * @return if the visual block was shown in the first place
 */
public boolean clearVisualBlock(Player player, Location location, boolean sendRemovalPacket) {
    synchronized (storedVisualises) {
        VisualBlock visualBlock = this.storedVisualises.remove(player.getUniqueId(), location);
        if (sendRemovalPacket && visualBlock != null) {
            // Have to send a packet to the original block type, don't send if the fake block has the same data properties though.
            Block block = location.getBlock();
            VisualBlockData visualBlockData = visualBlock.getBlockData();
            if (visualBlockData.getBlockType() != block.getType() || visualBlockData.getData() != block.getData()) {
                player.sendBlockChange(location, block.getType(), block.getData());
            }

            return true;
        }
    }

    return false;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:29,代码来源:VisualiseHandler.java

示例9: onSupplyDropInventoryClose

import org.bukkit.Location; //导入方法依赖的package包/类
@EventHandler
public void onSupplyDropInventoryClose(InventoryCloseEvent e) {
	Location loc = e.getInventory().getLocation();
	Block b = loc.getBlock();

	if (b.getType() == Material.CHEST) {

		if (core.getSupplyDropManager().isSupplyDrop(b.getLocation())) {
			if (core.getSupplyDropManager().isEmpty(loc)) {
				core.getSupplyDropManager().removeSupplyDrop(loc);
				
				b.setType(Material.AIR);
				loc.getWorld().playSound(loc, Sound.BLOCK_WOOD_BREAK, 1, 1);
			}

		}
	}
}
 
开发者ID:kadeska,项目名称:MT_Core,代码行数:19,代码来源:SupplyDropListener.java

示例10: renew

import org.bukkit.Location; //导入方法依赖的package包/类
boolean renew(BlockVector pos, MaterialData material) {
    // We need to do the entity check here rather than canRenew, because we are not
    // notified when entities move in our out of the way.
    if(!isClearOfEntities(pos)) return false;

    Location location = pos.toLocation(match.getWorld());
    Block block = location.getBlock();
    BlockState newState = location.getBlock().getState();
    newState.setMaterialData(material);

    BlockRenewEvent event = new BlockRenewEvent(block, newState, this);
    match.callEvent(event); // Our own handler will get this and remove the block from the pool
    if(event.isCancelled()) return false;

    newState.update(true, true);

    if(definition.particles) {
        NMSHacks.playBlockBreakEffect(match.getWorld(), pos, material.getItemType());
    }

    if(definition.sound) {
        NMSHacks.playBlockPlaceSound(match.getWorld(), pos, material.getItemType(), 1f);
    }

    return true;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:27,代码来源:Renewable.java

示例11: move

import org.bukkit.Location; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR)
public void move(final PlayerMoveEvent event) {
    Player player = event.getPlayer();
    Location to = event.getTo();
    Location from = event.getFrom();
    Block toBlock = to.getBlock();
    Block fromBlock = from.getBlock();

    handleLook(player, to);

    if(PORTAL_MATERIALS.contains(toBlock.getType()) && !PORTAL_MATERIALS.contains(fromBlock.getType())) {
        nearestSign(event.getTo()).ifPresent(
            sign -> sign.connector().teleport(player)
        );
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:17,代码来源:SignUpdater.java

示例12: isUnderBlock

import org.bukkit.Location; //导入方法依赖的package包/类
/**
 * @param location the location
 * @return if we are under a block.
 */
public static boolean isUnderBlock(Location location) {
    LocationBit bit = new LocationBit(0.5);

    // check if were already under that block.
    Location added = location.clone().add(0, 2, 0);
    Block addedBlock = added.getBlock();
    if (addedBlock.getType().isSolid()) {
        return true;
    }

    for (int i = 1; i <= 4; i++) {
        Location newLocation = location.clone().add(bit.getX(), 2, bit.getZ());
        Block block = newLocation.getBlock();
        if (block.getType().isSolid()) {
            return true;
        }
        bit.shift(i);
    }
    return false;
}
 
开发者ID:Vrekt,项目名称:Arc-v2,代码行数:25,代码来源:LocationHelper.java

示例13: getNearbyEntities

import org.bukkit.Location; //导入方法依赖的package包/类
Entity[] getNearbyEntities(Location l, int radius){
	int chunkRadius = radius < 16 ? 1 : (radius - (radius % 16))/16;
	HashSet<Entity> radiusEntities = new HashSet<Entity>();
     	for (int chX = 0 -chunkRadius; chX <= chunkRadius; chX ++){
     		for (int chZ = 0 -chunkRadius; chZ <= chunkRadius; chZ++){
     			int x=(int) l.getX(),y=(int) l.getY(),z=(int) l.getZ();
     			for (Entity e : new Location(l.getWorld(),x+(chX*16),y,z+(chZ*16)).getChunk().getEntities()){
     				if (e.getLocation().distance(l) <= radius && e.getLocation().getBlock() != l.getBlock()) radiusEntities.add(e);
     			}
     		}
     	}
     return radiusEntities.toArray(new Entity[radiusEntities.size()]);
}
 
开发者ID:Slaymd,项目名称:CaulCrafting,代码行数:14,代码来源:ItemDropListener.java

示例14: getBlockInfront

import org.bukkit.Location; //导入方法依赖的package包/类
private Block getBlockInfront(Location eyeloc, String cardinal) {
    double changex = 0;
    double changez = 0;
    switch(cardinal) {
        case "N":
            changez = -1;
            break;
        case "NW":
            changez = -1;
            changex = -1;
            break;
        case "NE":
            changex = 1;
            changez = -1;
            break;
        case "W":
            changex = -1;
            break;
        case "S":
            changez = 1;
            break;
        case "SW":
            changez = 1;
            changex = -1;
            break;
        case "SE":
            changex = 1;
            changez = 1;
            break;
        case "E":
            changex = 1;
            break;
    }
    eyeloc.add(changex,0,changez);
    return eyeloc.getBlock();
}
 
开发者ID:Notoh,项目名称:DynamicAC,代码行数:37,代码来源:DamageListener.java

示例15: isOnGround

import org.bukkit.Location; //导入方法依赖的package包/类
/**
 * Check if we are on ground by expanding the location and checking blocks
 * around us.
 *
 * @param location the location we traveled to.
 * @param vertical the players vertical speed.
 * @return whether or not were on the ground. true if we are.
 */
public static boolean isOnGround(Location location, double vertical) {
    LocationBit bit = new LocationBit(0.3);

    // get two different block locations.
    Location subtractedGround = location.clone().subtract(0, 0.5, 0);
    Block oddBlock = location.getBlock().getRelative(BlockFace.DOWN);
    Block groundBlock = subtractedGround.getBlock();

    boolean hasClimbable = groundBlock.getType().equals(Material.LADDER);
    boolean isOnOddBlock = isOnStair(oddBlock.getLocation()) || isOnSlab(oddBlock.getLocation()) || (MaterialHelper.isFence(oddBlock.getType())
            || MaterialHelper.isFenceGate(oddBlock.getType()));

    if (groundBlock.getType().isSolid() || hasClimbable && vertical == 0.0 || isOnOddBlock) {
        // solid block found, return.
        return true;
    }
    // expand the location and determine if we are being supported by a block.

    for (int i = 1; i <= 4; i++) {
        Location newGround = location.clone().add(bit.getX(), -0.5, bit.getZ());
        Block block = newGround.getBlock();
        if (block.getType().isSolid() && !hasClimbable) {
            return true;
        }

        bit.shift(i);
    }
    return false;
}
 
开发者ID:Vrekt,项目名称:Arc-v2,代码行数:38,代码来源:LocationHelper.java


注:本文中的org.bukkit.Location.getBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。