org.bukkit.World#getHighestBlockYAt ( )源码实例Demo

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

源代码1 项目: civcraft   文件: TradeGoodPopulator.java
@Override
public void populate(World world, Random random, Chunk source) {
   	
   	ChunkCoord cCoord = new ChunkCoord(source);
   	TradeGoodPick pick = CivGlobal.preGenerator.goodPicks.get(cCoord);
   	if (pick != null) {
		int centerX = (source.getX() << 4) + 8;
		int centerZ = (source.getZ() << 4) + 8;
		int centerY = world.getHighestBlockYAt(centerX, centerZ);
		BlockCoord coord = new BlockCoord(world.getName(), centerX, centerY, centerZ);

		if (checkForDuplicateTradeGood(world.getName(), centerX, centerY, centerZ)) {
			return;
		}
		
		// Determine if we should be a water good.
		ConfigTradeGood good;
		if (ItemManager.getBlockTypeIdAt(world, centerX, centerY-1, centerZ) == CivData.WATER || 
			ItemManager.getBlockTypeIdAt(world, centerX, centerY-1, centerZ) == CivData.WATER_RUNNING) {
			good = pick.waterPick;
		}  else {
			good = pick.landPick;
		}
		
		// Randomly choose a land or water good.
		if (good == null) {
			System.out.println("Could not find suitable good type during populate! aborting.");
			return;
		}
		
		// Create a copy and save it in the global hash table.
		buildTradeGoodie(good, coord, world, false);
   	}
	
   }
 
源代码2 项目: TrMenu   文件: TrUtils.java
public Location createLocation(World world, double x, double z) {
    double y = world.getHighestBlockYAt((int) x, (int) z);
    return createLocation(world, x, y, z);
}
 
源代码3 项目: civcraft   文件: MobSpawnerTimer.java
@Override
public void run() {
	String name = null;
	
	for (int i = 0; i < UPDATE_LIMIT; i++) {
		/* Find a player who is out in the wilderness. */
		try {
			name = playerQueue.poll();
			if (name == null) {
				/* Queue empty, return. */
				return;
			}
			
			Player player = CivGlobal.getPlayer(name);
			World world = player.getWorld();
			if (!world.getAllowMonsters()) {
				continue;
			}
							
			for (int j = 0; j < MIN_SPAWN_AMOUNT; j++) {
				Random random = new Random();
				int x = random.nextInt(MAX_SPAWN_DISTANCE)+MIN_SPAWN_DISTANCE;
				if (random.nextBoolean()) {
					x *= -1;
				}
				
				int z = random.nextInt(MAX_SPAWN_DISTANCE)+MIN_SPAWN_DISTANCE;
				if (random.nextBoolean()) {
					z *= -1;
				}
				
				int y = world.getHighestBlockYAt(((Double) player.getLocation().getX()).intValue() + x, ((Double) player.getLocation().getZ()).intValue() + z);
			    Location loc = new Location(world, player.getLocation().getX() + x, y, player.getLocation().getZ() + z);
				if (!loc.getChunk().isLoaded()) {
					continue;
				}
				
				
				TownChunk tc = CivGlobal.getTownChunk(new ChunkCoord(loc));
				if (tc != null) {
					/* Dont spawn in towns. */
					continue;
				}
				
				if ((ItemManager.getId(loc.getBlock().getRelative(BlockFace.DOWN)) == CivData.WATER) ||
				    (ItemManager.getId(loc.getBlock().getRelative(BlockFace.DOWN)) == CivData.WATER_RUNNING) ||
					(ItemManager.getId(loc.getBlock().getRelative(BlockFace.DOWN)) == CivData.LAVA) ||
					(ItemManager.getId(loc.getBlock().getRelative(BlockFace.DOWN)) == CivData.LAVA_RUNNING)) {
					/* Dont spawn mobs in water. */
					continue;
				}

				loc.setY(loc.getY()+Y_SHIFT);
				LinkedList<Entity> entities = EntityProximity.getNearbyEntities(null, loc, MOB_AREA, EntityCreature.class);
				if (entities.size() > MOB_AREA_LIMIT) {
					/* Dont spawn if we've reach the mob limit. */
					continue;
				}
				
				MobSpawner.spawnRandomCustomMob(loc);
			}
			break;
		} catch (CivException e) {
			/* player is offline, don't re-add to queue. */
		} finally {
			if (name != null) {
				/* Re-add to end of queue. */
				playerQueue.add(name);
			}
		}
	}
}
 
源代码4 项目: civcraft   文件: TradeGoodPostGenTask.java
@Override
public void run() {
	World world = Bukkit.getWorld("world");
	BlockCoord bcoord2 = new BlockCoord();

	for(int i = 0; i < amount; i++) {
		TradeGoodPick pick = picksQueue.poll();
		if (pick == null) {
			return;
		}
		
		ChunkCoord coord = pick.chunkCoord;
		Chunk chunk = world.getChunkAt(coord.getX(), coord.getZ());
		
		int centerX = (chunk.getX() << 4) + 8;
		int centerZ = (chunk.getZ() << 4) + 8;
		int centerY = world.getHighestBlockYAt(centerX, centerZ);
		
		
		
		bcoord2.setWorldname("world");
		bcoord2.setX(centerX);
		bcoord2.setY(centerY - 1);
		bcoord2.setZ(centerZ);
		
		/* try to detect already existing trade goods. */
		while(true) {
			Block top = world.getBlockAt(bcoord2.getX(), bcoord2.getY(), bcoord2.getZ());
			
			if (!top.getChunk().isLoaded()) {
				top.getChunk().load();
			}
			
			if (ItemManager.getId(top) == CivData.BEDROCK) {
				ItemManager.setTypeId(top, CivData.AIR);
    			ItemManager.setData(top, 0, true);
    			bcoord2.setY(bcoord2.getY() - 1);
    			
    			top = top.getRelative(BlockFace.NORTH);
    			if (ItemManager.getId(top) == CivData.WALL_SIGN) {
    				ItemManager.setTypeId(top, CivData.AIR);
	    			ItemManager.setData(top, 0, true);	    			
	    		}
    			
    			top = top.getRelative(BlockFace.SOUTH);
    			if (ItemManager.getId(top) == CivData.WALL_SIGN) {
    				ItemManager.setTypeId(top, CivData.AIR);
	    			ItemManager.setData(top, 0, true);	    			
	    		}
    			
    			top = top.getRelative(BlockFace.EAST);
    			if (ItemManager.getId(top) == CivData.WALL_SIGN) {
    				ItemManager.setTypeId(top, CivData.AIR);
	    			ItemManager.setData(top, 0, true);	    			
	    		}
    			
    			top = top.getRelative(BlockFace.WEST);
    			if (ItemManager.getId(top) == CivData.WALL_SIGN) {
    				ItemManager.setTypeId(top, CivData.AIR);
	    			ItemManager.setData(top, 0, true);
	    		}
			} else {
				break;
			}
			
		}
		
		centerY = world.getHighestBlockYAt(centerX, centerZ);
		
		// Determine if we should be a water good.
		ConfigTradeGood good;
		if (ItemManager.getBlockTypeIdAt(world, centerX, centerY-1, centerZ) == CivData.WATER || 
			ItemManager.getBlockTypeIdAt(world, centerX, centerY-1, centerZ) == CivData.WATER_RUNNING) {
			good = pick.waterPick;
		}  else {
			good = pick.landPick;
		}
		
		// Randomly choose a land or water good.
		if (good == null) {
			System.out.println("Could not find suitable good type during populate! aborting.");
			continue;
		}
		
		// Create a copy and save it in the global hash table.
		BlockCoord bcoord = new BlockCoord(world.getName(), centerX, centerY, centerZ);
		TradeGoodPopulator.buildTradeGoodie(good, bcoord, world, true);
		
	}
}