Java Code Examples for cn.nukkit.math.NukkitRandom#nextFloat()

The following examples show how to use cn.nukkit.math.NukkitRandom#nextFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Perlin.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
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];
    }
}
 
Example 2
Source File: PerlinD.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public PerlinD(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];
    }
}
 
Example 3
Source File: PerlinF.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public PerlinF(NukkitRandom random, float octaves, float persistence, float 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];
    }
}
 
Example 4
Source File: SimplexF.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public SimplexF(NukkitRandom random, float octaves, float persistence) {
    super(random, octaves, persistence);
    this.offsetW = random.nextFloat() * 256;
    SQRT_3 = (float) Math.sqrt(3);
    SQRT_5 = (float) Math.sqrt(5);
    F2 = 0.5f * (SQRT_3 - 1f);
    G2 = (3f - SQRT_3) / 6f;
    G22 = G2 * 2.0f - 1f;
    F3 = 1.0f / 3.0f;
    G3 = 1.0f / 6.0f;
    F4 = (SQRT_5 - 1.0f) / 4.0f;
    G4 = (5.0f - SQRT_5) / 20.0f;
    G42 = G4 * 2.0f;
    G43 = G4 * 3.0f;
    G44 = G4 * 4.0f - 1.0f;
}
 
Example 5
Source File: SimplexF.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public SimplexF(NukkitRandom random, float octaves, float persistence, float expansion) {
    super(random, octaves, persistence, expansion);
    this.offsetW = random.nextFloat() * 256;
    SQRT_3 = (float) Math.sqrt(3);
    SQRT_5 = (float) Math.sqrt(5);
    F2 = 0.5f * (SQRT_3 - 1f);
    G2 = (3f - SQRT_3) / 6f;
    G22 = G2 * 2.0f - 1f;
    F3 = 1.0f / 3.0f;
    G3 = 1.0f / 6.0f;
    F4 = (SQRT_5 - 1.0f) / 4.0f;
    G4 = (5.0f - SQRT_5) / 20.0f;
    G42 = G4 * 2.0f;
    G43 = G4 * 3.0f;
    G44 = G4 * 4.0f - 1.0f;
}
 
Example 6
Source File: NoiseGeneratorImprovedF.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public NoiseGeneratorImprovedF(NukkitRandom p_i45469_1_) {
    this.permutations = new int[512];
    this.xCoord = p_i45469_1_.nextFloat() * 256.0f;
    this.yCoord = p_i45469_1_.nextFloat() * 256.0f;
    this.zCoord = p_i45469_1_.nextFloat() * 256.0f;

    int i = 0;
    while (i < 256) {
        this.permutations[i] = i++;
    }

    for (int l = 0; l < 256; ++l) {
        int j = p_i45469_1_.nextBoundedInt(256 - l) + l;
        int k = this.permutations[l];
        this.permutations[l] = this.permutations[j];
        this.permutations[j] = k;
        this.permutations[l + 256] = this.permutations[l];
    }
}
 
Example 7
Source File: NoiseGeneratorSimplexF.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public NoiseGeneratorSimplexF(NukkitRandom p_i45471_1_) {
    this.p = new int[512];
    this.xo = p_i45471_1_.nextFloat() * 256.0f;
    this.yo = p_i45471_1_.nextFloat() * 256.0f;
    this.zo = p_i45471_1_.nextFloat() * 256.0f;

    int i = 0;
    while (i < 256) {
        this.p[i] = i++;
    }

    for (int l = 0; l < 256; ++l) {
        int j = p_i45471_1_.nextBoundedInt(256 - l) + l;
        int k = this.p[l];
        this.p[l] = this.p[j];
        this.p[j] = k;
        this.p[l + 256] = this.p[l];
    }
}
 
Example 8
Source File: Perlin.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
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];
    }
}
 
Example 9
Source File: ObjectJungleBigTree.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public boolean generate(ChunkManager level, NukkitRandom rand, Vector3 position) {
    int height = this.getHeight(rand);

    if (!this.ensureGrowable(level, rand, position, height)) {
        return false;
    } else {
        this.createCrown(level, position.up(height), 2);

        for (int j = (int) position.getY() + height - 2 - rand.nextBoundedInt(4); j > position.getY() + height / 2; j -= 2 + rand.nextBoundedInt(4)) {
            float f = rand.nextFloat() * ((float) Math.PI * 2F);
            int k = (int) (position.getX() + (0.5F + MathHelper.cos(f) * 4.0F));
            int l = (int) (position.getZ() + (0.5F + MathHelper.sin(f) * 4.0F));

            for (int i1 = 0; i1 < 5; ++i1) {
                k = (int) (position.getX() + (1.5F + MathHelper.cos(f) * (float) i1));
                l = (int) (position.getZ() + (1.5F + MathHelper.sin(f) * (float) i1));
                this.setBlockAndNotifyAdequately(level, new Vector3(k, j - 3 + i1 / 2, l), this.woodMetadata);
            }

            int j2 = 1 + rand.nextBoundedInt(2);
            int j1 = j;

            for (int k1 = j - j2; k1 <= j1; ++k1) {
                int l1 = k1 - j1;
                this.growLeavesLayer(level, new Vector3(k, k1, l), 1 - l1);
            }
        }

        for (int i2 = 0; i2 < height; ++i2) {
            Vector3 blockpos = position.up(i2);

            if (this.canGrowInto(level.getBlockIdAt((int) blockpos.x, (int) blockpos.y, (int) blockpos.z))) {
                this.setBlockAndNotifyAdequately(level, blockpos, this.woodMetadata);

                if (i2 > 0) {
                    this.placeVine(level, rand, blockpos.west(), 8);
                    this.placeVine(level, rand, blockpos.north(), 1);
                }
            }

            if (i2 < height - 1) {
                Vector3 blockpos1 = blockpos.east();

                if (this.canGrowInto(level.getBlockIdAt((int) blockpos1.x, (int) blockpos1.y, (int) blockpos1.z))) {
                    this.setBlockAndNotifyAdequately(level, blockpos1, this.woodMetadata);

                    if (i2 > 0) {
                        this.placeVine(level, rand, blockpos1.east(), 2);
                        this.placeVine(level, rand, blockpos1.north(), 1);
                    }
                }

                Vector3 blockpos2 = blockpos.south().east();

                if (this.canGrowInto(level.getBlockIdAt((int) blockpos2.x, (int) blockpos2.y, (int) blockpos2.z))) {
                    this.setBlockAndNotifyAdequately(level, blockpos2, this.woodMetadata);

                    if (i2 > 0) {
                        this.placeVine(level, rand, blockpos2.east(), 2);
                        this.placeVine(level, rand, blockpos2.south(), 4);
                    }
                }

                Vector3 blockpos3 = blockpos.south();

                if (this.canGrowInto(level.getBlockIdAt((int) blockpos3.x, (int) blockpos3.y, (int) blockpos3.z))) {
                    this.setBlockAndNotifyAdequately(level, blockpos3, this.woodMetadata);

                    if (i2 > 0) {
                        this.placeVine(level, rand, blockpos3.west(), 8);
                        this.placeVine(level, rand, blockpos3.south(), 4);
                    }
                }
            }
        }

        return true;
    }
}
 
Example 10
Source File: ObjectJungleBigTree.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean generate(ChunkManager level, NukkitRandom rand, Vector3 position) {
    int height = this.getHeight(rand);

    if (!this.ensureGrowable(level, rand, position, height)) {
        return false;
    } else {
        this.createCrown(level, position.up(height), 2);

        for (int j = (int) position.getY() + height - 2 - rand.nextBoundedInt(4); j > position.getY() + height / 2; j -= 2 + rand.nextBoundedInt(4)) {
            float f = rand.nextFloat() * ((float) Math.PI * 2F);
            int k = (int) (position.getX() + (0.5F + MathHelper.cos(f) * 4.0F));
            int l = (int) (position.getZ() + (0.5F + MathHelper.sin(f) * 4.0F));

            for (int i1 = 0; i1 < 5; ++i1) {
                k = (int) (position.getX() + (1.5F + MathHelper.cos(f) * (float) i1));
                l = (int) (position.getZ() + (1.5F + MathHelper.sin(f) * (float) i1));
                this.setBlockAndNotifyAdequately(level, new BlockVector3(k, j - 3 + i1 / 2, l), this.woodMetadata);
            }

            int j2 = 1 + rand.nextBoundedInt(2);

            for (int k1 = j - j2; k1 <= j; ++k1) {
                int l1 = k1 - j;
                this.growLeavesLayer(level, new Vector3(k, k1, l), 1 - l1);
            }
        }

        for (int i2 = 0; i2 < height; ++i2) {
            Vector3 blockpos = position.up(i2);

            if (this.canGrowInto(level.getBlockIdAt((int) blockpos.x, (int) blockpos.y, (int) blockpos.z))) {
                this.setBlockAndNotifyAdequately(level, blockpos, this.woodMetadata);

                if (i2 > 0) {
                    this.placeVine(level, rand, blockpos.west(), 8);
                    this.placeVine(level, rand, blockpos.north(), 1);
                }
            }

            if (i2 < height - 1) {
                Vector3 blockpos1 = blockpos.east();

                if (this.canGrowInto(level.getBlockIdAt((int) blockpos1.x, (int) blockpos1.y, (int) blockpos1.z))) {
                    this.setBlockAndNotifyAdequately(level, blockpos1, this.woodMetadata);

                    if (i2 > 0) {
                        this.placeVine(level, rand, blockpos1.east(), 2);
                        this.placeVine(level, rand, blockpos1.north(), 1);
                    }
                }

                Vector3 blockpos2 = blockpos.south().east();

                if (this.canGrowInto(level.getBlockIdAt((int) blockpos2.x, (int) blockpos2.y, (int) blockpos2.z))) {
                    this.setBlockAndNotifyAdequately(level, blockpos2, this.woodMetadata);

                    if (i2 > 0) {
                        this.placeVine(level, rand, blockpos2.east(), 2);
                        this.placeVine(level, rand, blockpos2.south(), 4);
                    }
                }

                Vector3 blockpos3 = blockpos.south();

                if (this.canGrowInto(level.getBlockIdAt((int) blockpos3.x, (int) blockpos3.y, (int) blockpos3.z))) {
                    this.setBlockAndNotifyAdequately(level, blockpos3, this.woodMetadata);

                    if (i2 > 0) {
                        this.placeVine(level, rand, blockpos3.west(), 8);
                        this.placeVine(level, rand, blockpos3.south(), 4);
                    }
                }
            }
        }

        return true;
    }
}
 
Example 11
Source File: OreType.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean spawn(ChunkManager level, NukkitRandom rand, int replaceId, int x, int y, int z) {
    float piScaled = rand.nextFloat() * (float) Math.PI;
    double scaleMaxX = (double) ((float) (x + 8) + MathHelper.sin(piScaled) * (float) clusterSize / 8.0F);
    double scaleMinX = (double) ((float) (x + 8) - MathHelper.sin(piScaled) * (float) clusterSize / 8.0F);
    double scaleMaxZ = (double) ((float) (z + 8) + MathHelper.cos(piScaled) * (float) clusterSize / 8.0F);
    double scaleMinZ = (double) ((float) (z + 8) - MathHelper.cos(piScaled) * (float) clusterSize / 8.0F);
    double scaleMaxY = (double) (y + rand.nextBoundedInt(3) - 2);
    double scaleMinY = (double) (y + rand.nextBoundedInt(3) - 2);

    for (int i = 0; i < clusterSize; ++i) {
        float sizeIncr = (float) i / (float) clusterSize;
        double scaleX = scaleMaxX + (scaleMinX - scaleMaxX) * (double) sizeIncr;
        double scaleY = scaleMaxY + (scaleMinY - scaleMaxY) * (double) sizeIncr;
        double scaleZ = scaleMaxZ + (scaleMinZ - scaleMaxZ) * (double) sizeIncr;
        double randSizeOffset = rand.nextDouble() * (double) clusterSize / 16.0D;
        double randVec1 = (double) (MathHelper.sin((float) Math.PI * sizeIncr) + 1.0F) * randSizeOffset + 1.0D;
        double randVec2 = (double) (MathHelper.sin((float) Math.PI * sizeIncr) + 1.0F) * randSizeOffset + 1.0D;
        int minX = MathHelper.floor(scaleX - randVec1 / 2.0D);
        int minY = MathHelper.floor(scaleY - randVec2 / 2.0D);
        int minZ = MathHelper.floor(scaleZ - randVec1 / 2.0D);
        int maxX = MathHelper.floor(scaleX + randVec1 / 2.0D);
        int maxY = MathHelper.floor(scaleY + randVec2 / 2.0D);
        int maxZ = MathHelper.floor(scaleZ + randVec1 / 2.0D);

        for (int xSeg = minX; xSeg <= maxX; ++xSeg) {
            double xVal = ((double) xSeg + 0.5D - scaleX) / (randVec1 / 2.0D);

            if (xVal * xVal < 1.0D) {
                for (int ySeg = minY; ySeg <= maxY; ++ySeg) {
                    double yVal = ((double) ySeg + 0.5D - scaleY) / (randVec2 / 2.0D);

                    if (xVal * xVal + yVal * yVal < 1.0D) {
                        for (int zSeg = minZ; zSeg <= maxZ; ++zSeg) {
                            double zVal = ((double) zSeg + 0.5D - scaleZ) / (randVec1 / 2.0D);

                            if (xVal * xVal + yVal * yVal + zVal * zVal < 1.0D) {
                                if (level.getBlockIdAt(xSeg, ySeg, zSeg) == replaceBlockId) {
                                    level.setBlockFullIdAt(xSeg, ySeg, zSeg, fullId);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    return true;
}
 
Example 12
Source File: ObjectJungleBigTree.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean generate(ChunkManager level, NukkitRandom rand, Vector3 position) {
    int height = this.getHeight(rand);

    if (!this.ensureGrowable(level, rand, position, height)) {
        return false;
    } else {
        this.createCrown(level, position.up(height), 2);

        for (int j = (int) position.getY() + height - 2 - rand.nextBoundedInt(4); j > position.getY() + height / 2; j -= 2 + rand.nextBoundedInt(4)) {
            float f = rand.nextFloat() * ((float) Math.PI * 2F);
            int k = (int) (position.getX() + (0.5F + MathHelper.cos(f) * 4.0F));
            int l = (int) (position.getZ() + (0.5F + MathHelper.sin(f) * 4.0F));

            for (int i1 = 0; i1 < 5; ++i1) {
                k = (int) (position.getX() + (1.5F + MathHelper.cos(f) * (float) i1));
                l = (int) (position.getZ() + (1.5F + MathHelper.sin(f) * (float) i1));
                this.setBlockAndNotifyAdequately(level, new Vector3(k, j - 3 + i1 / 2, l), this.woodMetadata);
            }

            int j2 = 1 + rand.nextBoundedInt(2);
            int j1 = j;

            for (int k1 = j - j2; k1 <= j1; ++k1) {
                int l1 = k1 - j1;
                this.growLeavesLayer(level, new Vector3(k, k1, l), 1 - l1);
            }
        }

        for (int i2 = 0; i2 < height; ++i2) {
            Vector3 blockpos = position.up(i2);

            if (this.canGrowInto(level.getBlockIdAt((int) blockpos.x, (int) blockpos.y, (int) blockpos.z))) {
                this.setBlockAndNotifyAdequately(level, blockpos, this.woodMetadata);

                if (i2 > 0) {
                    this.placeVine(level, rand, blockpos.west(), 8);
                    this.placeVine(level, rand, blockpos.north(), 1);
                }
            }

            if (i2 < height - 1) {
                Vector3 blockpos1 = blockpos.east();

                if (this.canGrowInto(level.getBlockIdAt((int) blockpos1.x, (int) blockpos1.y, (int) blockpos1.z))) {
                    this.setBlockAndNotifyAdequately(level, blockpos1, this.woodMetadata);

                    if (i2 > 0) {
                        this.placeVine(level, rand, blockpos1.east(), 2);
                        this.placeVine(level, rand, blockpos1.north(), 1);
                    }
                }

                Vector3 blockpos2 = blockpos.south().east();

                if (this.canGrowInto(level.getBlockIdAt((int) blockpos2.x, (int) blockpos2.y, (int) blockpos2.z))) {
                    this.setBlockAndNotifyAdequately(level, blockpos2, this.woodMetadata);

                    if (i2 > 0) {
                        this.placeVine(level, rand, blockpos2.east(), 2);
                        this.placeVine(level, rand, blockpos2.south(), 4);
                    }
                }

                Vector3 blockpos3 = blockpos.south();

                if (this.canGrowInto(level.getBlockIdAt((int) blockpos3.x, (int) blockpos3.y, (int) blockpos3.z))) {
                    this.setBlockAndNotifyAdequately(level, blockpos3, this.woodMetadata);

                    if (i2 > 0) {
                        this.placeVine(level, rand, blockpos3.west(), 8);
                        this.placeVine(level, rand, blockpos3.south(), 4);
                    }
                }
            }
        }

        return true;
    }
}