use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.
the class DeopCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages messages) {
if (!testPermission(sender, messages.getPermissionMessage())) {
return true;
}
if (args.length != 1) {
sendUsageMessage(sender, messages);
return false;
}
String name = args[0];
GlowServer server = (GlowServer) ServerProvider.getServer();
// asynchronously lookup player
server.getOfflinePlayerAsync(name).whenCompleteAsync((player, ex) -> {
if (ex != null) {
new LocalizedStringImpl("deop.failed", messages.getResourceBundle()).sendInColor(ChatColor.RED, sender, name, ex.getMessage());
ConsoleMessages.Error.Command.DEOP_FAILED.log(ex, name);
return;
}
if (player.isOp()) {
player.setOp(false);
new LocalizedStringImpl("deop.done", messages.getResourceBundle()).send(sender, name);
} else {
new LocalizedStringImpl("deop.not-op", messages.getResourceBundle()).sendInColor(ChatColor.RED, sender, name);
}
});
// todo: asynchronous command callbacks?
return true;
}
use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.
the class EntityDecorator method populate.
@Override
public void populate(World world, Random random, Chunk chunk) {
GlowServer server = (GlowServer) Bukkit.getServer();
boolean allowAnimals = world.getAllowAnimals() && server.getAnimalsSpawnEnabled();
boolean allowMonsters = world.getAllowMonsters() && server.getMonstersSpawnEnabled();
if (entityTypes.length == 0) {
return;
}
if (random.nextFloat() >= rarity) {
return;
}
int sourceX = chunk.getX() << 4;
int sourceZ = chunk.getZ() << 4;
EntityType type = entityTypes[random.nextInt(entityTypes.length)];
if ((!allowAnimals && Animals.class.isAssignableFrom(type.getEntityClass())) || !allowMonsters && Monster.class.isAssignableFrom(type.getEntityClass())) {
return;
}
int centerX = sourceX + random.nextInt(16);
int centerZ = sourceZ + random.nextInt(16);
int count = minGroup == maxGroup ? minGroup : random.nextInt(maxGroup - minGroup) + minGroup;
int range = 5;
int attempts = 5;
for (int i = 0; i < count; i++) {
if (attempts == 0) {
continue;
}
double radius = (double) range * random.nextDouble();
double angle = random.nextDouble() * Math.PI;
double x = radius * Math.sin(angle) + centerX;
double z = radius * Math.cos(angle) + centerZ;
Block block = world.getHighestBlockAt(new Location(world, x, 0, z));
if (block.getType() == Material.WATER || block.getType() == Material.LAVA) {
i--;
attempts--;
continue;
}
attempts = 5;
Location location = block.getLocation().clone().add(0, 1, 0);
location.setYaw(random.nextFloat() * 360 - 180);
if (location.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) {
location.subtract(0, 1, 0);
}
world.spawnEntity(location, type);
}
}
use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.
the class OverworldGenerator method generateChunkData.
@Override
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomes) {
ChunkData chunkData = generateRawTerrain(world, chunkX, chunkZ);
int cx = chunkX << 4;
int cz = chunkZ << 4;
SimplexOctaveGenerator octaveGenerator = ((SimplexOctaveGenerator) getWorldOctaves(world).get("surface"));
int sizeX = octaveGenerator.getSizeX();
int sizeZ = octaveGenerator.getSizeZ();
if (((GlowServer) ServerProvider.getServer()).doesUseGraphicsCompute()) {
CLKernel noiseGen = null;
CLBuffer<FloatBuffer> noise = null;
try {
// Initialize OpenCL stuff and put args
CLProgram program = OpenCompute.getProgram("net/glowstone/CLRandom.cl");
int workSize = sizeX * octaveGenerator.getSizeY() * sizeZ;
noise = OpenCompute.getContext().createFloatBuffer(workSize, CLMemory.Mem.WRITE_ONLY);
noiseGen = OpenCompute.getKernel(program, "GenerateNoise");
noiseGen.putArg(random.nextFloat()).putArg(random.nextFloat()).putArg(noise).putArg(workSize);
// Calculate noise on GPU
OpenCompute.getQueue().put1DRangeKernel(noiseGen, 0, OpenCompute.getGlobalSize(workSize), OpenCompute.getLocalSize()).putReadBuffer(noise, true);
// Use noise
for (int x = 0; x < sizeX; x++) {
for (int z = 0; z < sizeZ; z++) {
if (GROUND_MAP.containsKey(biomes.getBiome(x, z))) {
GROUND_MAP.get(biomes.getBiome(x, z)).generateTerrainColumn(chunkData, world, random, cx + x, cz + z, biomes.getBiome(x, z), noise.getBuffer().get(x | z << 4));
} else {
groundGen.generateTerrainColumn(chunkData, world, random, cx + x, cz + z, biomes.getBiome(x, z), noise.getBuffer().get(x | z << 4));
}
}
}
} finally {
// Clean up
if (noise != null) {
ServerProvider.getServer().getScheduler().runTaskAsynchronously(null, noise::release);
}
if (noiseGen != null) {
noiseGen.rewind();
}
}
} else {
double[] surfaceNoise = octaveGenerator.getFractalBrownianMotion(cx, cz, 0.5D, 0.5D);
for (int x = 0; x < sizeX; x++) {
for (int z = 0; z < sizeZ; z++) {
if (GROUND_MAP.containsKey(biomes.getBiome(x, z))) {
GROUND_MAP.get(biomes.getBiome(x, z)).generateTerrainColumn(chunkData, world, random, cx + x, cz + z, biomes.getBiome(x, z), surfaceNoise[x | z << 4]);
} else {
groundGen.generateTerrainColumn(chunkData, world, random, cx + x, cz + z, biomes.getBiome(x, z), surfaceNoise[x | z << 4]);
}
}
}
}
return chunkData;
}
use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.
the class StructureBuilder method setBlockDownward.
/**
* Builds a 1x1 column out of the given block, replacing non-solid blocks starting at a given
* location and proceeding downward until a solid block is reached.
*
* @param pos the highest point to possibly replace, relative to this structure's root
* point
* @param type the block type to fill
* @param data the block data
*/
public void setBlockDownward(Vector pos, Material type, MaterialData data) {
Vector vec = translate(pos);
BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
if (boundingBox.isVectorInside(vec)) {
int x = vec.getBlockX();
int y = vec.getBlockY();
int z = vec.getBlockZ();
while (!world.getBlockAt(x, y, z).getType().isSolid() && y > 1) {
delegate.setTypeAndData(world, x, y, z, type, blockDataManager.createBlockData(type));
y--;
}
}
}
use of net.glowstone.GlowServer in project Glowstone by GlowstoneMC.
the class NbtSerialization method readItem.
/**
* Read an item stack in from an NBT tag.
*
* <p>Returns null if no item exists.
*
* @param tag The tag to read from.
* @return The resulting ItemStack, or null.
*/
public static ItemStack readItem(CompoundTag tag) {
BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
final Material[] material = { null };
if ((!tag.readString("id", id -> material[0] = ItemIds.getItem(id)) && !tag.readShort("id", id -> material[0] = blockDataManager.convertToBlockData(id).getMaterial())) || material[0] == null || material[0] == Material.AIR) {
return null;
}
final byte[] count = { 0 };
tag.readByte("Count", x -> count[0] = x);
if (count[0] == 0) {
return null;
}
final short[] damage = { 0 };
tag.readShort("Damage", x -> damage[0] = x);
ItemStack stack = new ItemStack(material[0], count[0], damage[0]);
// This is slightly different than what tag.readItem would do, since we specify the
// material separately.
tag.readCompound("tag", subtag -> stack.setItemMeta(GlowItemFactory.instance().readNbt(material[0], subtag)));
return stack;
}
Aggregations