当前位置: 首页>>代码示例>>Java>>正文


Java NukkitRandom.nextRange方法代码示例

本文整理汇总了Java中cn.nukkit.math.NukkitRandom.nextRange方法的典型用法代码示例。如果您正苦于以下问题:Java NukkitRandom.nextRange方法的具体用法?Java NukkitRandom.nextRange怎么用?Java NukkitRandom.nextRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cn.nukkit.math.NukkitRandom的用法示例。


在下文中一共展示了NukkitRandom.nextRange方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onUpdate

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_RANDOM) {
        //TODO: light levels
        NukkitRandom random = new NukkitRandom();
        x = random.nextRange((int) x - 1, (int) x + 1);
        y = random.nextRange((int) y - 1, (int) y + 1);
        z = random.nextRange((int) z - 1, (int) z + 1);
        Block block = this.getLevel().getBlock(new Vector3(x, y, z));
        if (block.getId() == Block.DIRT) {
            if (block.up() instanceof BlockTransparent) {
                BlockSpreadEvent ev = new BlockSpreadEvent(block, this, new BlockMycelium());
                Server.getInstance().getPluginManager().callEvent(ev);
                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(block, ev.getNewState());
                }
            }
        }
    }
    return 0;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:22,代码来源:BlockMycelium.java

示例2: populate

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    BaseFullChunk chunk = level.getChunk(chunkX, chunkZ);
    int bx = chunkX << 4;
    int bz = chunkZ << 4;
    int tx = bx + 15;
    int tz = bz + 15;
    ObjectOre ore = new ObjectOre(random, type, Block.AIR);
    for (int i = 0; i < ore.type.clusterCount; ++i) {
        int x = random.nextRange(0, 15);
        int z = random.nextRange(0, 15);
        int y = this.getHighestWorkableBlock(chunk, x, z);
        if (y != -1) {
            ore.placeObject(level, bx + x, y, bz + z);
        }
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:19,代码来源:PopulatorGlowStone.java

示例3: populate

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    BaseFullChunk chunk = level.getChunk(chunkX, chunkZ);
    int bx = chunkX << 4;
    int bz = chunkZ << 4;
    int tx = bx + 15;
    int tz = bz + 15;
    int amount = random.nextRange(0, this.randomAmount + 1) + this.baseAmount;
    for (int i = 0; i < amount; ++i) {
        int x = random.nextRange(0, 15);
        int z = random.nextRange(0, 15);
        int y = this.getHighestWorkableBlock(chunk, x, z);
        if (y != -1 && this.canGroundFireStay(chunk, x, y, z)) {
            chunk.setBlock(x, y, z, Block.FIRE);
            chunk.setBlockLight(x, y, z, Block.light[Block.FIRE]);
        }
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:20,代码来源:PopulatorGroundFire.java

示例4: growGrass

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
public static void growGrass(ChunkManager level, Vector3 pos, NukkitRandom random, int count, int radius) {
    int[][] arr = {
            {Block.DANDELION, 0},
            {Block.POPPY, 0},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1}
    };
    int arrC = arr.length - 1;
    for (int c = 0; c < count; c++) {
        int x = random.nextRange((int) (pos.x - radius), (int) (pos.x + radius));
        int z = random.nextRange((int) (pos.z) - radius, (int) (pos.z + radius));

        if (level.getBlockIdAt(x, (int) (pos.y + 1), z) == Block.AIR && level.getBlockIdAt(x, (int) (pos.y), z) == Block.GRASS) {
            int[] t = arr[random.nextRange(0, arrC)];
            level.setBlockIdAt(x, (int) (pos.y + 1), z, t[0]);
            level.setBlockDataAt(x, (int) (pos.y + 1), z, t[1]);
        }
    }
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:22,代码来源:ObjectTallGrass.java

示例5: onOpen

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
@Override
public void onOpen(Player who) {
    super.onOpen(who);

    if (this.levels == null) {
        this.levels = new int[3];
        this.bookshelfAmount = this.countBookshelf();

        if (this.bookshelfAmount < 0) {
            this.bookshelfAmount = 0;
        }

        if (this.bookshelfAmount > 15) {
            this.bookshelfAmount = 15;
        }

        NukkitRandom random = new NukkitRandom();

        double base = (double) random.nextRange(1, 8) + (bookshelfAmount / 2d) + (double) random.nextRange(0, bookshelfAmount);
        this.levels[0] = (int) Math.max(base / 3, 1);
        this.levels[1] = (int) ((base * 2) / 3 + 1);
        this.levels[2] = (int) Math.max(base, bookshelfAmount * 2);
    }

}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:26,代码来源:EnchantInventory.java

示例6: populate

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.random = random;
    if (random.nextRange(0, 100) < 5) {
        this.level = level;
        int amount = random.nextRange(0, this.randomAmount + 1) + this.baseAmount;
        BaseFullChunk chunk = level.getChunk(chunkX, chunkZ);
        int bx = chunkX << 4;
        int bz = chunkZ << 4;
        int tx = bx + 15;
        int tz = bz + 15;
        for (int i = 0; i < amount; ++i) {
            int x = random.nextRange(0, 15);
            int z = random.nextRange(0, 15);
            int y = this.getHighestWorkableBlock(chunk, x, z);
            if (y != -1 && chunk.getBlockId(x, y, z) == Block.AIR) {
                chunk.setBlock(x, y, z, Block.LAVA);
                chunk.setBlockLight(x, y, z, Block.light[Block.LAVA]);
                this.lavaSpread(bx + x, y, bz + z);
            }
        }
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:24,代码来源:PopulatorLava.java

示例7: getDrops

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
@Override
public Item[] getDrops(Item item) {
    NukkitRandom random = new NukkitRandom();
    return new Item[]{
            new ItemSeedsPumpkin(0, random.nextRange(0, 3))
    };
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:8,代码来源:BlockStemPumpkin.java

示例8: getDrops

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
@Override
public int[][] getDrops(Item item) {
    NukkitRandom random = new NukkitRandom();
    return new int[][]{
            {Item.PUMPKIN_SEEDS, 0, random.nextRange(0, 2)}
    };
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:8,代码来源:BlockStemPumpkin.java

示例9: onUpdate

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
@Override
public boolean onUpdate(int currentTick) {
    if (this.closed) {
        return false;
    }

    this.timing.startTiming();

    int tickDiff = currentTick - this.lastUpdate;
    boolean hasUpdate = super.onUpdate(currentTick);

    if (this.age > 1200) {
        this.kill();
        hasUpdate = true;
    }

    if (this.isCollided) {
        this.kill();
        Particle particle1 = new EnchantParticle(this);
        this.getLevel().addParticle(particle1);
        Particle particle2 = new SpellParticle(this, 0x00385dc6);
        this.getLevel().addParticle(particle2);
        hasUpdate = true;

        NukkitRandom random = new NukkitRandom();
        int add = 1;
        for (int ii = 1; ii <= random.nextRange(3, 11); ii += add) {
            getLevel().dropExpOrb(this, add);
            add = random.nextRange(1, 3);
        }
    }

    this.timing.stopTiming();

    return hasUpdate;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:37,代码来源:EntityExpBottle.java

示例10: getDrops

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
@Override
public Item[] getDrops(Item item) {
    NukkitRandom random = new NukkitRandom();
    return new Item[]{
            new ItemSeedsMelon(0, random.nextRange(0, 3))
    };
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:8,代码来源:BlockStemMelon.java

示例11: init

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
@Override
    public void init(ChunkManager level, NukkitRandom random) {
        this.level = level;
        this.nukkitRandom = random;
        this.random = new Random();
        this.nukkitRandom.setSeed(this.level.getSeed());
        this.localSeed1 = this.random.nextLong();
        this.localSeed2 = this.random.nextLong();
        this.noiseSeaFloor = new Simplex(this.nukkitRandom, 1F, 1F / 8F, 1F / 64F);
        this.noiseLand = new Simplex(this.nukkitRandom, 2F, 1F / 8F, 1F / 512F);
        this.noiseMountains = new Simplex(this.nukkitRandom, 4F, 1F, 1F / 500F);
        this.noiseBaseGround = new Simplex(this.nukkitRandom, 4F, 1F / 4F, 1F / 64F);
        this.noiseRiver = new Simplex(this.nukkitRandom, 2F, 1F, 1F / 512F);
        this.nukkitRandom.setSeed(this.level.getSeed());
        this.selector = new BiomeSelector(this.nukkitRandom, Biome.getBiome(Biome.FOREST));
        this.heightOffset = random.nextRange(-5, 3);

        this.selector.addBiome(Biome.getBiome(OCEAN));
        this.selector.addBiome(Biome.getBiome(PLAINS));
        this.selector.addBiome(Biome.getBiome(DESERT));
        this.selector.addBiome(Biome.getBiome(FOREST));
        this.selector.addBiome(Biome.getBiome(TAIGA));
        this.selector.addBiome(Biome.getBiome(RIVER));
        this.selector.addBiome(Biome.getBiome(ICE_PLAINS));
        this.selector.addBiome(Biome.getBiome(BIRCH_FOREST));

        this.selector.addBiome(Biome.getBiome(JUNGLE));
        this.selector.addBiome(Biome.getBiome(SAVANNA));
        this.selector.addBiome(Biome.getBiome(ROOFED_FOREST));
        this.selector.addBiome(Biome.getBiome(ROOFED_FOREST_M));
        this.selector.addBiome(Biome.getBiome(MUSHROOM_ISLAND));
        this.selector.addBiome(Biome.getBiome(SWAMP));

        this.selector.recalculate();


        PopulatorCaves caves = new PopulatorCaves();
        this.populators.add(caves);

        PopulatorRavines ravines = new PopulatorRavines();
        this.populators.add(ravines);

//        PopulatorDungeon dungeons = new PopulatorDungeon();
//        this.populators.add(dungeons);

        PopulatorGroundCover cover = new PopulatorGroundCover();
        this.generationPopulators.add(cover);

        PopulatorOre ores = new PopulatorOre();
        ores.setOreTypes(new OreType[]{
                new OreType(new BlockOreCoal(), 20, 17, 0, 128),
                new OreType(new BlockOreIron(), 20, 9, 0, 64),
                new OreType(new BlockOreRedstone(), 8, 8, 0, 16),
                new OreType(new BlockOreLapis(), 1, 7, 0, 16),
                new OreType(new BlockOreGold(), 2, 9, 0, 32),
                new OreType(new BlockOreDiamond(), 1, 8, 0, 16),
                new OreType(new BlockDirt(), 10, 33, 0, 128),
                new OreType(new BlockGravel(), 8, 33, 0, 128),
                new OreType(new BlockStone(BlockStone.GRANITE), 10, 33, 0, 80),
                new OreType(new BlockStone(BlockStone.DIORITE), 10, 33, 0, 80),
                new OreType(new BlockStone(BlockStone.ANDESITE), 10, 33, 0, 80)
        });
        this.populators.add(ores);
    }
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:65,代码来源:Normal.java

示例12: attack

import cn.nukkit.math.NukkitRandom; //导入方法依赖的package包/类
@Override
public boolean attack(EntityDamageEvent source) {
    if (!this.isAlive()) {
        return false;
    }

    if (this.isCreative()
            && source.getCause() != DamageCause.MAGIC
            && source.getCause() != DamageCause.SUICIDE
            && source.getCause() != DamageCause.VOID
            ) {
            //source.setCancelled();
            return false;
    } else if (this.getAdventureSettings().get(Type.ALLOW_FLIGHT) && source.getCause() == DamageCause.FALL) {
            //source.setCancelled();
            return false;
    } else if (source.getCause() == DamageCause.FALL) {
        if (this.getLevel().getBlock(this.getPosition().floor().add(0.5, -1, 0.5)).getId() == Block.SLIME_BLOCK) {
            if (!this.isSneaking()) {
                //source.setCancelled();
                return false;
            }
        }
    }

    if (source instanceof EntityDamageByEntityEvent) {
        Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
        if (damager instanceof Player) {
            ((Player) damager).getFoodData().updateFoodExpLevel(0.3);
        }

        if (!damager.onGround) {
            NukkitRandom random = new NukkitRandom();
            for (int i = 0; i < 5; i++) {
                CriticalParticle par = new CriticalParticle(new Vector3(this.x + random.nextRange(-15, 15) / 10, this.y + random.nextRange(0, 20) / 10, this.z + random.nextRange(-15, 15) / 10));
                this.getLevel().addParticle(par);
            }

            source.setDamage((float) (source.getDamage() * 1.5));
        }
    }

    if (super.attack(source)) { //!source.isCancelled()
        if (this.getLastDamageCause() == source && this.spawned) {
            this.getFoodData().updateFoodExpLevel(0.3);
            EntityEventPacket pk = new EntityEventPacket();
            pk.entityRuntimeId = this.id;
            pk.event = EntityEventPacket.HURT_ANIMATION;
            this.dataPacket(pk);
        }
        return true;

    } else {
        return false;
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:57,代码来源:Player.java


注:本文中的cn.nukkit.math.NukkitRandom.nextRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。