Search in sources :

Example 21 with GlowServer

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;
}
Also used : LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) GlowServer(net.glowstone.GlowServer)

Example 22 with GlowServer

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);
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) Animals(org.bukkit.entity.Animals) Block(org.bukkit.block.Block) GlowServer(net.glowstone.GlowServer) Location(org.bukkit.Location)

Example 23 with GlowServer

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;
}
Also used : CLProgram(com.jogamp.opencl.CLProgram) SimplexOctaveGenerator(net.glowstone.util.noise.SimplexOctaveGenerator) FloatBuffer(java.nio.FloatBuffer) GlowServer(net.glowstone.GlowServer) CLKernel(com.jogamp.opencl.CLKernel)

Example 24 with GlowServer

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--;
        }
    }
}
Also used : GlowServer(net.glowstone.GlowServer) Vector(org.bukkit.util.Vector) BlockDataManager(net.glowstone.block.data.BlockDataManager)

Example 25 with GlowServer

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;
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag) Arrays(java.util.Arrays) NamespacedKey(org.bukkit.NamespacedKey) BlockData(org.bukkit.block.data.BlockData) BlockDataManager(net.glowstone.block.data.BlockDataManager) UUID(java.util.UUID) GlowItemFactory(net.glowstone.inventory.GlowItemFactory) InventoryUtil(net.glowstone.util.InventoryUtil) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) ItemIds(net.glowstone.constants.ItemIds) Vector(org.bukkit.util.Vector) List(java.util.List) Location(org.bukkit.Location) World(org.bukkit.World) Optional(java.util.Optional) GlowServer(net.glowstone.GlowServer) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) Material(org.bukkit.Material) GlowServer(net.glowstone.GlowServer) ItemStack(org.bukkit.inventory.ItemStack) BlockDataManager(net.glowstone.block.data.BlockDataManager)

Aggregations

GlowServer (net.glowstone.GlowServer)29 BlockDataManager (net.glowstone.block.data.BlockDataManager)8 Vector (org.bukkit.util.Vector)5 RecipeManager (net.glowstone.datapack.RecipeManager)4 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)4 ByteBuf (io.netty.buffer.ByteBuf)3 GlowChunk (net.glowstone.chunk.GlowChunk)3 FuelManager (net.glowstone.datapack.FuelManager)3 BlockChangeMessage (net.glowstone.net.message.play.game.BlockChangeMessage)3 Material (org.bukkit.Material)3 ItemStack (org.bukkit.inventory.ItemStack)3 DatagramPacket (io.netty.channel.socket.DatagramPacket)2 UUID (java.util.UUID)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 GlowFurnaceInventory (net.glowstone.inventory.GlowFurnaceInventory)2 HandshakeProtocol (net.glowstone.net.protocol.HandshakeProtocol)2 LoginProtocol (net.glowstone.net.protocol.LoginProtocol)2 PlayProtocol (net.glowstone.net.protocol.PlayProtocol)2 ProtocolProvider (net.glowstone.net.protocol.ProtocolProvider)2 StatusProtocol (net.glowstone.net.protocol.StatusProtocol)2