Refine search
@Override public void sendSignChange(Location location, String[] lines) throws IllegalArgumentException { checkNotNull(location, "location cannot be null"); checkNotNull(lines, "lines cannot be null"); checkArgument(lines.length == 4, "lines.length must equal 4"); afterBlockChanges.add(UpdateSignMessage .fromPlainText(location.getBlockX(), location.getBlockY(), location .getBlockZ(), lines)); }
/** * Send a block entity change to the given location. * * @param location The location of the block entity. * @param type The type of block entity being sent. * @param nbt The NBT structure to send to the client. */ public void sendBlockEntityChange(Location location, GlowBlockEntity type, CompoundTag nbt) { checkNotNull(location, "Location cannot be null"); checkNotNull(type, "Type cannot be null"); checkNotNull(nbt, "NBT cannot be null"); afterBlockChanges.add(new UpdateBlockEntityMessage(location.getBlockX(), location .getBlockY(), location.getBlockZ(), type.getValue(), nbt)); }
private void prepareSpawn() { int centerX = spawnLocation.getBlockX() >> 4; int centerZ = spawnLocation.getBlockZ() >> 4; int radius = 4 * server.getViewDistance() / 3; long loadTime = System.currentTimeMillis(); int total = ((radius << 1) + 1) * ((radius << 1) + 1); int current = 0; for (int x = centerX - radius; x <= centerX + radius; ++x) { for (int z = centerZ - radius; z <= centerZ + radius; ++z) { ++current; if (populateAnchoredChunks) { getChunkManager().forcePopulation(x, z); } else { loadChunk(x, z); } spawnChunkLock.acquire(GlowChunk.Key.of(x, z)); if (System.currentTimeMillis() >= loadTime + 1000) { int progress = 100 * current / total; GlowServer.logger.info("Preparing spawn for " + name + ": " + progress + "%"); loadTime = System.currentTimeMillis(); } } } }
private void updateActiveChunkCollection(GlowEntity entity) { // build a set of chunkManager around each player in this world, the // server view distance is taken here int radius = server.getViewDistance(); Location playerLocation = entity.getLocation(); if (playerLocation.getWorld() == this) { int cx = playerLocation.getBlockX() >> 4; int cz = playerLocation.getBlockZ() >> 4; for (int x = cx - radius; x <= cx + radius; x++) { for (int z = cz - radius; z <= cz + radius; z++) { if (isChunkLoaded(cx, cz)) { activeChunksSet.add(GlowChunk.Key.of(x, z)); } } } } }
protected BlockFace calculateFace(GlowPlayer player, GlowBlockState state) { Location playerLoc = player.getLocation(); // the location of the player Location blockLoc = state.getLocation(); // the location of the block if (Math.abs(playerLoc.getBlockX() - blockLoc.getBlockX()) < 2.0F && Math.abs(playerLoc.getBlockZ() - blockLoc.getBlockZ()) < 2.0F) { double offset = playerLoc.getBlockY() + player.getEyeHeight(); if (offset - blockLoc.getBlockY() > 2.0) { return BlockFace.UP; } if (blockLoc.getBlockY() - offset > 0.0) { return DOWN; } } return player.getCardinalFacing().getOppositeFace(); } }
@Override public void render(MapView map, MapCanvas canvas, Player player) { World world = map.getWorld(); int scaleShift = map.getScale().getValue(); Location playerLoc = player.getLocation(); int playerX = playerLoc.getBlockX(); int playerZ = playerLoc.getBlockZ(); int cornerX = map.getCenterX() - ((MAP_SIZE / 2) << scaleShift); int cornerZ = map.getCenterZ() - ((MAP_SIZE / 2) << scaleShift); for (int pixelX = 0; pixelX < MAP_SIZE; pixelX++) { for (int pixelY = 0; pixelY < MAP_SIZE; pixelY++) { int worldX = cornerX + (pixelX << scaleShift); int worldZ = cornerZ + (pixelY << scaleShift); if (((worldX - playerX) * (worldX - playerX) + (worldZ - playerZ) * (worldZ - playerZ)) < MAP_SIGHT_DISTANCE_SQUARED) { // TODO: Should the highest block be skipped over if it's e.g. a flower or a // technical block? byte blockColor = colorFor(world.getHighestBlockAt(worldX, worldZ), worldX, worldZ); canvas.setPixel(pixelX, pixelY, blockColor); } } } }
/** * Attempts to grow this tree at its current location. If successful, the associated {@link * BlockStateDelegate} is instructed to set blocks to wood and leaves. * * @param loc the base of the trunk * @return true if successfully grown; false otherwise * @deprecated use {@link #generate(World, Random, int, int, int)} */ @Deprecated public boolean generate(Location loc) { return generate(loc.getWorld(), ThreadLocalRandom.current(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); }