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


Java NukkitRandom类代码示例

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


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

示例1: Simplex

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
public Simplex(NukkitRandom random, double octaves, double persistence) {
    super(random, octaves, persistence);
    this.offsetW = random.nextDouble() * 256;
    SQRT_3 = Math.sqrt(3);
    SQRT_5 = Math.sqrt(5);
    F2 = 0.5 * (SQRT_3 - 1);
    G2 = (3 - SQRT_3) / 6;
    G22 = G2 * 2.0 - 1;
    F3 = 1.0 / 3.0;
    G3 = 1.0 / 6.0;
    F4 = (SQRT_5 - 1.0) / 4.0;
    G4 = (5.0 - SQRT_5) / 20.0;
    G42 = G4 * 2.0;
    G43 = G4 * 3.0;
    G44 = G4 * 4.0 - 1.0;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:17,代码来源:Simplex.java

示例2: onUpdate

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().isTransparent()) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) { //Growth
        if (new NukkitRandom().nextRange(1, 7) == 1) {
            if ((this.meta & 0x08) == 0x08) {
                ObjectTree.growTree(this.getLevel(), (int) this.x, (int) this.y, (int) this.z, new NukkitRandom(), this.meta & 0x07);
            } else {
                this.meta |= 0x08;
                this.getLevel().setBlock(this, this, true);
                return Level.BLOCK_UPDATE_RANDOM;
            }
        } else {
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }
    return 1;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:22,代码来源:BlockSapling.java

示例3: onActivate

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0F) {
        item.count--;
        ObjectTallGrass.growGrass(this.getLevel(), this, new NukkitRandom(), 15, 10);
        return true;
    } else if (item.isHoe()) {
        item.useOn(this);
        this.getLevel().setBlock(this, new BlockFarmland());
        return true;
    } else if (item.isShovel()) {
        item.useOn(this);
        this.getLevel().setBlock(this, new BlockGrassPath());
        return true;
    }

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

示例4: populate

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX * 16, chunkX * 16 + 15);
        int z = NukkitMath.randomRange(random, chunkZ * 16, chunkZ * 16 + 15);
        int y = this.getHighestWorkableBlock(x, z);

        if (y != -1 && this.canTallGrassStay(x, y, z)) {
            this.level.setBlockIdAt(x, y, z, Block.DOUBLE_PLANT);
            this.level.setBlockDataAt(x, y, z, 2);
            this.level.setBlockIdAt(x, y + 1, z, Block.DOUBLE_PLANT);
            this.level.setBlockDataAt(x, y + 1, z, 10);
        }
    }
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:18,代码来源:PopulatorTallGrass.java

示例5: Perlin

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
public Perlin(NukkitRandom random, double octaves, double persistence, double expansion) {
    this.octaves = octaves;
    this.persistence = persistence;
    this.expansion = expansion;
    this.offsetX = random.nextFloat() * 256;
    this.offsetY = random.nextFloat() * 256;
    this.offsetZ = random.nextFloat() * 256;
    this.perm = new int[512];
    for (int i = 0; i < 256; ++i) {
        this.perm[i] = random.nextBoundedInt(256);
    }
    for (int i = 0; i < 256; ++i) {
        int pos = random.nextBoundedInt(256 - i) + i;
        int old = this.perm[i];
        this.perm[i] = this.perm[pos];
        this.perm[pos] = old;
        this.perm[i + 256] = this.perm[i];
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:20,代码来源:Perlin.java

示例6: onActivate

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0F) { //BoneMeal
        if ((player.gamemode & 0x01) == 0) {
            item.count--;
        }

        if (this.level.rand.nextFloat() >= 0.45) {
            this.level.addParticle(new BoneMealParticle(this));
            return true;
        }

        ObjectTree.growTree(this.getLevel(), (int) this.x, (int) this.y, (int) this.z, new NukkitRandom(), this.meta & 0x07);
        return true;
    }
    this.getLevel().loadChunk((int) this.x >> 4, (int) this.z >> 4);
    return false;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:18,代码来源:BlockSapling.java

示例7: populate

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.random = new Random();
    this.random.setSeed(level.getSeed());
    worldLong1 = this.random.nextLong();
    worldLong2 = this.random.nextLong();

    int i = this.checkAreaSize;

    for (int x = chunkX - i; x <= chunkX + i; x++)
        for (int z = chunkZ - i; z <= chunkZ + i; z++) {
            long l3 = x * worldLong1;
            long l4 = z * worldLong2;
            this.random.setSeed(l3 ^ l4 ^ level.getSeed());
            generateChunk(chunkX, chunkZ, level.getChunk(chunkX, chunkZ));
        }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:18,代码来源:PopulatorRavines.java

示例8: placeObject

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
public void placeObject(ChunkManager level, int x, int y, int z, NukkitRandom random) {

        this.placeTrunk(level, x, y, z, random, this.getTreeHeight() - 1);

        for (int yy = y - 3 + this.getTreeHeight(); yy <= y + this.getTreeHeight(); ++yy) {
            double yOff = yy - (y + this.getTreeHeight());
            int mid = (int) (1 - yOff / 2);
            for (int xx = x - mid; xx <= x + mid; ++xx) {
                int xOff = Math.abs(xx - x);
                for (int zz = z - mid; zz <= z + mid; ++zz) {
                    int zOff = Math.abs(zz - z);
                    if (xOff == mid && zOff == mid && (yOff == 0 || random.nextBoundedInt(2) == 0)) {
                        continue;
                    }
                    if (!Block.solid[level.getBlockIdAt(xx, yy, zz)]) {

                        level.setBlockIdAt(xx, yy, zz, this.getLeafBlock());
                        level.setBlockDataAt(xx, yy, zz, this.getType());
                    }
                }
            }
        }
    }
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:24,代码来源:ObjectTree.java

示例9: populate

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectJungleBigTree(10, 20, new BlockWood(BlockWood.JUNGLE), new BlockLeaves(BlockLeaves.JUNGLE)).generate(this.level, random, v.setComponents(x, y, z));
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:17,代码来源:JungleBigTreePopulator.java

示例10: populate

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;

    if (flowerTypes.size() == 0) {
        this.addType(Block.RED_FLOWER, BlockFlower.TYPE_POPPY);
        this.addType(Block.DANDELION, 0);
    }

    int endNum = this.flowerTypes.size();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX * 16, chunkX * 16 + 15);
        int z = NukkitMath.randomRange(random, chunkZ * 16, chunkZ * 16 + 15);
        int y = this.getHighestWorkableBlock(x, z);


        if (y != -1 && this.canFlowerStay(x, y, z)) {
            int[] type = this.flowerTypes.get(random.nextRange(0, endNum - 1));
            this.level.setBlockIdAt(x, y, z, type[0]);
            this.level.setBlockDataAt(x, y, z, type[1]);
        }
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:26,代码来源:PopulatorFlower.java

示例11: canPlaceObject

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
public boolean canPlaceObject(ChunkManager level, int x, int y, int z, NukkitRandom random) {
    int radiusToCheck = 0;
    for (int yy = 0; yy < this.getTreeHeight() + 3; ++yy) {
        if (yy == 1 || yy == this.getTreeHeight()) {
            ++radiusToCheck;
        }
        for (int xx = -radiusToCheck; xx < (radiusToCheck + 1); ++xx) {
            for (int zz = -radiusToCheck; zz < (radiusToCheck + 1); ++zz) {
                if (!this.overridable.containsKey(level.getBlockIdAt(x + xx, y + yy, z + zz))) {
                    return false;
                }
            }
        }
    }

    return true;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:18,代码来源:ObjectTree.java

示例12: prime

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
public void prime(int fuse) {
    this.getLevel().setBlock(this, new BlockAir(), true);
    double mot = (new NukkitRandom()).nextSignedFloat() * Math.PI * 2;
    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", this.x + 0.5))
                    .add(new DoubleTag("", this.y))
                    .add(new DoubleTag("", this.z + 0.5)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", -Math.sin(mot) * 0.02))
                    .add(new DoubleTag("", 0.2))
                    .add(new DoubleTag("", -Math.cos(mot) * 0.02)))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", 0))
                    .add(new FloatTag("", 0)))
            .putByte("Fuse", fuse);
    Entity tnt = new EntityPrimedTNT(
            this.getLevel().getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4),
            nbt
    );
    tnt.spawnToAll();
    this.level.addSound(new TNTPrimeSound(this));
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:24,代码来源:BlockTNT.java

示例13: 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:Rsplwe,项目名称:Nukkit-Java9,代码行数:22,代码来源:ObjectTallGrass.java

示例14: populate

import cn.nukkit.math.NukkitRandom; //导入依赖的package包/类
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
        int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new BigMushroom(type).generate(level, random, v.setComponents(x, y, z));
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:17,代码来源:MushroomPopulator.java

示例15: 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:Rsplwe,项目名称:Nukkit-Java9,代码行数:22,代码来源:BlockMycelium.java


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