Java Code Examples for org.bukkit.block.Block#getY()
The following examples show how to use
org.bukkit.block.Block#getY() .
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: CraftBlockState.java From Thermos with GNU General Public License v3.0 | 6 votes |
public CraftBlockState(final Block block) { this.world = (CraftWorld) block.getWorld(); this.x = block.getX(); this.y = block.getY(); this.z = block.getZ(); this.type = block.getTypeId(); this.light = block.getLightLevel(); this.chunk = (CraftChunk) block.getChunk(); this.flag = 3; // Cauldron start - save TE data TileEntity te = world.getHandle().getTileEntity(x, y, z); if (te != null) { nbt = new NBTTagCompound(); te.writeToNBT(nbt); } else nbt = null; // Cauldron end createData(block.getData()); }
Example 2
Source File: HologramProjector.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private static ArmorStand getArmorStand(Block projector, boolean createIfNoneExists) { String nametag = BlockStorage.getLocationInfo(projector.getLocation(), "text"); double offset = Double.parseDouble(BlockStorage.getLocationInfo(projector.getLocation(), "offset")); Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5); for (Entity n : l.getChunk().getEntities()) { if (n instanceof ArmorStand && n.getCustomName() != null && n.getCustomName().equals(nametag) && l.distanceSquared(n.getLocation()) < 0.4D) { return (ArmorStand) n; } } if (!createIfNoneExists) { return null; } ArmorStand hologram = SimpleHologram.create(l); hologram.setCustomName(nametag); return hologram; }
Example 3
Source File: ElevatorPlate.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
public List<Block> getFloors(Block b) { List<Block> floors = new LinkedList<>(); for (int y = b.getWorld().getMaxHeight(); y > 0; y--) { if (y == b.getY()) { floors.add(b); continue; } Block block = b.getWorld().getBlockAt(b.getX(), y, b.getZ()); if (block.getType() == getItem().getType() && BlockStorage.check(block, getID())) { floors.add(block); } } return floors; }
Example 4
Source File: GameSign.java From DungeonsXL with GNU General Public License v3.0 | 6 votes |
/** * @param plugin the plugin instance * @param block a block which is protected by the returned GameSign * @return the game sign the block belongs to, null if it belongs to none */ public static GameSign getByBlock(DungeonsXL plugin, Block block) { if (!Category.SIGNS.containsBlock(block)) { return null; } for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(GameSign.class)) { GameSign gameSign = (GameSign) protection; Block start = gameSign.startSign; if (start == block || (start.getX() == block.getX() && start.getZ() == block.getZ() && (start.getY() >= block.getY() && start.getY() - gameSign.verticalSigns <= block.getY()))) { return gameSign; } } return null; }
Example 5
Source File: NMSHandler.java From askyblock with GNU General Public License v2.0 | 5 votes |
@Override public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) { net.minecraft.server.v1_10_R1.World w = ((CraftWorld) b.getWorld()).getHandle(); net.minecraft.server.v1_10_R1.Chunk chunk = w.getChunkAt(b.getX() >> 4, b.getZ() >> 4); BlockPosition bp = new BlockPosition(b.getX(), b.getY(), b.getZ()); int combined = blockId + (data << 12); IBlockData ibd = net.minecraft.server.v1_10_R1.Block.getByCombinedId(combined); if (applyPhysics) { w.setTypeAndData(bp, ibd, 3); } else { w.setTypeAndData(bp, ibd, 2); } chunk.a(bp, ibd); }
Example 6
Source File: TreePopulator.java From GiantTrees with GNU General Public License v3.0 | 5 votes |
int getHighestSoil(Block highestBlock) { while ((highestBlock.getY() > 0) && (highestBlock.getType() != Material.DIRT) && // Includes podzol (highestBlock.getType() != Material.GRASS) && (highestBlock.getType() != Material.MYCELIUM) && (highestBlock.getType() != Material.SAND)) { highestBlock = highestBlock.getRelative(BlockFace.DOWN); } return highestBlock.getY(); }
Example 7
Source File: CraftBlock.java From Thermos with GNU General Public License v3.0 | 5 votes |
public BlockFace getFace(final Block block) { BlockFace[] values = BlockFace.values(); for (BlockFace face : values) { if ((this.getX() + face.getModX() == block.getX()) && (this.getY() + face.getModY() == block.getY()) && (this.getZ() + face.getModZ() == block.getZ()) ) { return face; } } return null; }
Example 8
Source File: ActiveMiner.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
public ActiveMiner(IndustrialMiner miner, UUID owner, Block chest, Block[] pistons, Block start, Block end) { this.miner = miner; this.owner = owner; this.chest = chest; this.pistons = pistons; this.start = new BlockPosition(start); this.end = new BlockPosition(end); this.height = start.getY(); this.x = start.getX(); this.z = start.getZ(); }
Example 9
Source File: LaneMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private static Vector getSafeLocationUnder(Block block) { World world = block.getWorld(); for(int y = block.getY() - 2; y >= 0; y--) { Block feet = world.getBlockAt(block.getX(), y, block.getZ()); Block head = world.getBlockAt(block.getX(), y + 1, block.getZ()); if(feet.getType() == Material.AIR && head.getType() == Material.AIR) { return new Vector(block.getX() + 0.5, y, block.getZ() + 0.5); } } return new Vector(block.getX() + 0.5, -2, block.getZ() + 0.5); }
Example 10
Source File: NMSHandler.java From askyblock with GNU General Public License v2.0 | 5 votes |
@Override public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) { net.minecraft.server.v1_9_R2.World w = ((CraftWorld) b.getWorld()).getHandle(); net.minecraft.server.v1_9_R2.Chunk chunk = w.getChunkAt(b.getX() >> 4, b.getZ() >> 4); BlockPosition bp = new BlockPosition(b.getX(), b.getY(), b.getZ()); int combined = blockId + (data << 12); IBlockData ibd = net.minecraft.server.v1_9_R2.Block.getByCombinedId(combined); if (applyPhysics) { w.setTypeAndData(bp, ibd, 3); } else { w.setTypeAndData(bp, ibd, 2); } chunk.a(bp, ibd); }
Example 11
Source File: CreateTreeCommand.java From GiantTrees with GNU General Public License v3.0 | 5 votes |
Block getHighestSoil(Block highestBlock) { while ((highestBlock.getY() > 0) && (highestBlock.getType() != Material.DIRT) && // Includes podzol (highestBlock.getType() != Material.GRASS) && (highestBlock.getType() != Material.MYCELIUM) && (highestBlock.getType() != Material.SAND)) { highestBlock = highestBlock.getRelative(BlockFace.DOWN); } return highestBlock; }
Example 12
Source File: NMSHandler.java From askyblock with GNU General Public License v2.0 | 5 votes |
@Override public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) { net.minecraft.server.v1_8_R2.World w = ((CraftWorld) b.getWorld()).getHandle(); net.minecraft.server.v1_8_R2.Chunk chunk = w.getChunkAt(b.getX() >> 4, b.getZ() >> 4); BlockPosition bp = new BlockPosition(b.getX(), b.getY(), b.getZ()); int combined = blockId + (data << 12); IBlockData ibd = net.minecraft.server.v1_8_R2.Block.getByCombinedId(combined); chunk.a(bp, ibd); if (applyPhysics) { net.minecraft.server.v1_8_R2.Block block = chunk.getType(bp); w.update(bp, block); } }
Example 13
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockPlaceEvent event!"); Player p = e.getPlayer(); Block b = e.getBlockPlaced(); World w = p.getWorld(); Material m = e.getItemInHand().getType(); boolean antih = RedProtect.get().config.configRoot().region_settings.anti_hopper; Region r = RedProtect.get().rm.getTopRegion(b.getLocation()); if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass") && antih && (m.equals(Material.HOPPER) || m.name().contains("RAIL"))) { int x = b.getX(); int y = b.getY(); int z = b.getZ(); Block ib = w.getBlockAt(x, y + 1, z); if (!cont.canBreak(p, ib) || !cont.canBreak(p, b)) { RedProtect.get().lang.sendMessage(p, "blocklistener.container.chestinside"); e.setCancelled(true); return; } } if (r == null && canPlaceList(p.getWorld(), b.getType().name())) { return; } if (r != null) { if (!r.canMinecart(p) && (m.name().contains("MINECART") || m.name().contains("BOAT"))) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantplace"); e.setCancelled(true); return; } if ((b.getType().name().equals("MOB_SPAWNER") || b.getType().name().equals("SPAWNER")) && r.canPlaceSpawner(p)) { return; } if ((m.name().contains("_HOE") || r.canCrops(b)) && r.canCrops()) { return; } Material type = b.getType(); if (!r.blockTransform() && type.isBlock() && ( type.name().contains("SNOW") || type.name().contains("ICE") || type.name().contains("CORAL") || type.name().contains("POWDER"))) { b.setType(m); } if (!r.canBuild(p) && !r.canPlace(b.getType())) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild"); e.setCancelled(true); } } }
Example 14
Source File: Util.java From ObsidianDestroyer with GNU General Public License v3.0 | 4 votes |
public static boolean isTargetsPathBlocked(Location tLoc, Location dLoc, boolean useOnlyMaterialListing) { // check world if (!dLoc.getWorld().getName().equalsIgnoreCase(tLoc.getWorld().getName())) { return false; } // if the distance is too close... the path is not blocked ;) if (dLoc.distance(tLoc) <= 0.9) { return false; } // try to iterate through blocks between dLoc and tLoc try { // Create a vector block trace from the detonator location to damaged block's location final BlockIterator blocksInPath = new BlockIterator(tLoc.getWorld(), dLoc.toVector(), tLoc.toVector().subtract(dLoc.toVector()).normalize(), 0.5, (int) dLoc.distance(tLoc)); // iterate through the blocks in the path int over = 0; // prevents rare case of infinite loop and server crash while (blocksInPath.hasNext() && over < 128) { over++; // the next block final Block block = blocksInPath.next(); if (block == null) { continue; } // check if next block is the target block if (tLoc.getWorld().getName().equals(block.getWorld().getName()) && tLoc.getBlockX() == block.getX() && tLoc.getBlockY() == block.getY() && tLoc.getBlockZ() == block.getZ()) { // ignore target block continue; } // check if the block material is being handled if (useOnlyMaterialListing) { // only handle for certain case as to not interfere with all explosions if (MaterialManager.getInstance().contains(block.getType().name(), block.getData())) { return true; } else { continue; } } // check if the block material is a solid if (!isNonSolid(block.getType())) { return true; } } } catch (Exception e) { // ignore the error and return no targets in path } return false; }
Example 15
Source File: DGameWorld.java From DungeonsXL with GNU General Public License v3.0 | 4 votes |
/** * Handles what happens when a player places a block. * * @param player * @param block * @param against * @param hand the event parameters. * @return if the event is cancelled */ public boolean onPlace(Player player, Block block, Block against, ItemStack hand) { Game game = getGame(); if (game == null) { return true; } PlaceableBlock placeableBlock = null; for (PlaceableBlock gamePlaceableBlock : placeableBlocks) { if (gamePlaceableBlock.canPlace(block, caliburn.getExItem(hand))) { placeableBlock = gamePlaceableBlock; break; } } if (!getRules().getState(GameRule.PLACE_BLOCKS) && placeableBlock == null) { // Workaround for a bug that would allow 3-Block-high jumping Location loc = player.getLocation(); if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) { if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) { if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) { loc.setX(block.getX() + 0.5); loc.setY(block.getY()); loc.setZ(block.getZ() + 0.5); player.teleport(loc); } } } return true; } if (placeableBlock != null) { placeableBlock.onPlace(); } Set<ExItem> whitelist = getRules().getState(GameRule.PLACE_WHITELIST); if (whitelist == null || whitelist.contains(VanillaItem.get(block.getType()))) { placedBlocks.add(block); return false; } return true; }
Example 16
Source File: BlockQuery.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
public BlockQuery(@Nullable Event event, Block block) { this(event, block.getWorld(), block.getX(), block.getY(), block.getZ()); }
Example 17
Source File: WarCamp.java From civcraft with GNU General Public License v2.0 | 4 votes |
protected void checkBlockPermissionsAndRestrictions(Player player, Block centerBlock, int regionX, int regionY, int regionZ) throws CivException { if (!War.isWarTime()) { throw new CivException("Can only build War Camps during war time."); } if (player.getLocation().getY() >= 200) { throw new CivException("You're too high to build camps."); } if ((regionY + centerBlock.getLocation().getBlockY()) >= 255) { throw new CivException("Cannot build war camp here, would go over the minecraft height limit."); } int minsLeft = this.isWarCampCooldownLeft(); if (minsLeft > 0) { throw new CivException("Building a War Camp is on cooldown. You must wait "+minsLeft+" mins before you can build another."); } if (!player.isOp()) { Buildable.validateDistanceFromSpawn(centerBlock.getLocation()); } int yTotal = 0; int yCount = 0; for (int x = 0; x < regionX; x++) { for (int y = 0; y < regionY; y++) { for (int z = 0; z < regionZ; z++) { Block b = centerBlock.getRelative(x, y, z); if (ItemManager.getId(b) == CivData.CHEST) { throw new CivException("Cannot build here, would destroy chest."); } BlockCoord coord = new BlockCoord(b); ChunkCoord chunkCoord = new ChunkCoord(coord.getLocation()); TownChunk tc = CivGlobal.getTownChunk(chunkCoord); if (tc != null && !tc.perms.hasPermission(PlotPermissions.Type.DESTROY, CivGlobal.getResident(player))) { // Make sure we have permission to destroy any block in this area. throw new CivException("Cannot build here, you need DESTROY permissions to the block at "+b.getX()+","+b.getY()+","+b.getZ()); } if (CivGlobal.getProtectedBlock(coord) != null) { throw new CivException("Cannot build here, protected blocks in the way."); } if (CivGlobal.getStructureBlock(coord) != null) { throw new CivException("Cannot build here, structure blocks in the way."); } if (CivGlobal.getFarmChunk(chunkCoord) != null) { throw new CivException("Cannot build here, in the same chunk as a farm improvement."); } if (CivGlobal.getWallChunk(chunkCoord) != null) { throw new CivException("Cannot build here, in the same chunk as a wall improvement."); } if (CivGlobal.getCampBlock(coord) != null) { throw new CivException("Cannot build here, a camp is in the way."); } yTotal += b.getWorld().getHighestBlockYAt(centerBlock.getX()+x, centerBlock.getZ()+z); yCount++; if (CivGlobal.getRoadBlock(coord) != null) { throw new CivException("Cannot build a war camp on top of an existing road block."); } } } } double highestAverageBlock = (double)yTotal / (double)yCount; if (((centerBlock.getY() > (highestAverageBlock+10)) || (centerBlock.getY() < (highestAverageBlock-10)))) { throw new CivException("Cannot build here, you must be closer to the surface."); } }
Example 18
Source File: ContainerManager.java From RedProtect with GNU General Public License v3.0 | 4 votes |
public boolean canOpen(Block b, Player p) { if (!RedProtect.get().config.configRoot().private_cat.use || p.hasPermission("redprotect.bypass")) { return true; } String blocktype = b.getType().name(); List<String> blocks = RedProtect.get().config.configRoot().private_cat.allowed_blocks; boolean deny = true; if (blocks.stream().anyMatch(blocktype::matches)) { int x = b.getX(); int y = b.getY(); int z = b.getZ(); World w = p.getWorld(); for (int sx = -1; sx <= 1; sx++) { for (int sz = -1; sz <= 1; sz++) { Block bs = w.getBlockAt(x + sx, y, z + sz); if (isSign(bs) && (validatePrivateSign(bs))) { deny = false; if (validateOpenBlock(bs, p)) { return true; } } int x2 = bs.getX(); int y2 = bs.getY(); int z2 = bs.getZ(); String blocktype2 = b.getType().name(); if (blocks.stream().anyMatch(blocktype2::matches)) { for (int ux = -1; ux <= 1; ux++) { for (int uz = -1; uz <= 1; uz++) { Block bu = w.getBlockAt(x2 + ux, y2, z2 + uz); if (isSign(bu) && (validatePrivateSign(bu))) { deny = false; if (validateOpenBlock(bu, p)) { return true; } } } } } } } } return deny; }
Example 19
Source File: Utils.java From Shopkeepers with GNU General Public License v3.0 | 4 votes |
/** * Determines the exact intersection point of a players view and a targeted block. * * @param player * the player * @param targetBlock * the block the player is looking at * @return the intersection point of the players view and the target block, * or null if no intersection was found */ public static Location getBlockIntersection(Player player, Block targetBlock) { if (player == null || targetBlock == null) return null; // block bounds: double minX = targetBlock.getX(); double minY = targetBlock.getY(); double minZ = targetBlock.getZ(); double maxX = minX + 1.0D; double maxY = minY + 1.0D; double maxZ = minZ + 1.0D; // ray origin: Location origin = player.getEyeLocation(); double originX = origin.getX(); double originY = origin.getY(); double originZ = origin.getZ(); // ray direction Vector dir = origin.getDirection(); double dirX = dir.getX(); double dirY = dir.getY(); double dirZ = dir.getZ(); // tiny improvement to save a few divisions below: double divX = 1.0D / dirX; double divY = 1.0D / dirY; double divZ = 1.0D / dirZ; // intersection interval: double t0 = 0.0D; double t1 = Double.MAX_VALUE; double tmin; double tmax; double tymin; double tymax; double tzmin; double tzmax; if (dirX >= 0.0D) { tmin = (minX - originX) * divX; tmax = (maxX - originX) * divX; } else { tmin = (maxX - originX) * divX; tmax = (minX - originX) * divX; } if (dirY >= 0.0D) { tymin = (minY - originY) * divY; tymax = (maxY - originY) * divY; } else { tymin = (maxY - originY) * divY; tymax = (minY - originY) * divY; } if ((tmin > tymax) || (tymin > tmax)) { return null; } if (tymin > tmin) tmin = tymin; if (tymax < tmax) tmax = tymax; if (dirZ >= 0.0D) { tzmin = (minZ - originZ) * divZ; tzmax = (maxZ - originZ) * divZ; } else { tzmin = (maxZ - originZ) * divZ; tzmax = (minZ - originZ) * divZ; } if ((tmin > tzmax) || (tzmin > tmax)) { return null; } if (tzmin > tmin) tmin = tzmin; if (tzmax < tmax) tmax = tzmax; if ((tmin >= t1) || (tmax <= t0)) { return null; } // intersection: Location intersection = origin.add(dir.multiply(tmin)); return intersection; }
Example 20
Source File: LWC.java From Modern-LWC with MIT License | 2 votes |
/** * Compares two blocks if they are equal * * @param block * @param block2 * @return */ @SuppressWarnings("deprecation") public boolean blockEquals(Block block, Block block2) { return block.getType() == block2.getType() && block.getX() == block2.getX() && block.getY() == block2.getY() && block.getZ() == block2.getZ() && block.getData() == block2.getData(); }