Java Code Examples for cn.nukkit.math.MathHelper#sin()
The following examples show how to use
cn.nukkit.math.MathHelper#sin() .
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: Entity.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void moveFlying(float strafe, float forward, float friction) { float speed = strafe * strafe + forward * forward; if (speed >= 1.0E-4F) { speed = MathHelper.sqrt(speed); if (speed < 1.0F) { speed = 1.0F; } speed = friction / speed; strafe *= speed; forward *= speed; float nest = MathHelper.sin((float) (this.yaw * 3.1415927F / 180.0F)); float place = MathHelper.cos((float) (this.yaw * 3.1415927F / 180.0F)); this.motionX += strafe * place - forward * nest; this.motionZ += forward * place + strafe * nest; } }
Example 2
Source File: ObjectJungleBigTree.java From Jupiter with GNU General Public License v3.0 | 4 votes |
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 3
Source File: ObjectJungleBigTree.java From Nukkit with GNU General Public License v3.0 | 4 votes |
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 4
Source File: OreType.java From Nukkit with GNU General Public License v3.0 | 4 votes |
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 5
Source File: ObjectJungleBigTree.java From Nukkit with GNU General Public License v3.0 | 4 votes |
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; } }