@Override public void onEmission(EnergyRangeGeneratorComponent component, ParticleData particleData, Random random) { particleData.energy = random.nextFloat(component.minEnergy, component.maxEnergy); } }
/** * @return Random boolean */ public boolean nextBoolean() { return nextInt() < 0; }
/** * Returns a unit vector (length = 1) Vector3f whose components range from -1 (inclusive) to 1 (inclusive) * * @return The vector */ public Vector3f nextUnitVector3f() { return nextVector3f(1.0f); }
@ReceiveEvent public void onDeath(DoDestroyEvent event, EntityRef entity, CharacterSoundComponent characterSounds) { if (characterSounds.deathSounds.size() > 0) { StaticSound sound = random.nextItem(characterSounds.deathSounds); entity.send(new PlaySoundEvent(entity, sound, characterSounds.deathVolume)); } }
Vector3f direction = random.nextVector3f(); Vector3f impulse = new Vector3f(direction); impulse.scale(tunnelActionComponent.explosiveForce); particleEffects++; if (random.nextFloat() < tunnelActionComponent.thoroughness) { EntityRef blockEntity = blockEntityRegistry.getEntityAt(blockPos); blockEntity.send(new DoDamageEvent(tunnelActionComponent.damageAmount, tunnelActionComponent.damageType));
dangerChangeTime = (long) (ai.dangerUpdateTime * random.nextDouble() * ai.hectic); if (ai.hunter) { if (distanceToPlayer > ai.playerdistance if (ai.forgiving != 0) { ai.movementTarget.set(new Vector3f( tempTarget.x + random.nextFloat(-ai.forgiving, ai.forgiving), tempTarget.y + random.nextFloat(-ai.forgiving, ai.forgiving), tempTarget.z + random.nextFloat(-ai.forgiving, ai.forgiving) )); } else { idleChangeTime = (long) (ai.idlingUpdateTime * random.nextDouble() * ai.hectic); idling = false; moveChangeTime = (long) (ai.moveUpdateTime * random.nextDouble() * ai.hectic); idling = true; entity.saveComponent(location); directionChangeTime = (long) (ai.moveUpdateTime * random.nextDouble() * ai.straightLined); randomWalk(worldPos, ai); entity.saveComponent(ai);
/** * @param max * @return Random integer from 0 (inclusive) to max (exclusive) */ public int nextInt(int max) { return (int) (max * nextDouble()); }
/** * @return Random double from 0 (inclusive) to 1 (exclusive) */ public double nextDouble() { return (nextLong() & 0x7FFFFFFFFFFFFFFFL) / (Long.MAX_VALUE + 1.0); }
/** * Calculates a normal distributed value (using the polar method). * * <code>nextGuassian(1,1)</code> is equivalent to {@link #nextGaussian()}. * * @param mean the mean value of the distribution * @param stdDev the standard deviation of the distribution * * @return The value */ public double nextGaussian(double mean, double stdDev) { return mean + stdDev * nextGaussian(); } }
@ReceiveEvent public void onRespawn(OnPlayerRespawnedEvent event, EntityRef character, CharacterSoundComponent characterSounds) { if (characterSounds.respawnSounds.size() > 0) { StaticSound sound = random.nextItem(characterSounds.respawnSounds); character.send(new PlaySoundEvent(character, sound, characterSounds.respawnVolume)); } }
/** * @param max * @return Random long from 0 (inclusive) to max (exclusive) */ public long nextLong(long max) { return (long) (max * nextDouble()); }
/** * @param min * @param max * @return Random long from min (inclusive) to max (inclusive) */ public long nextLong(long min, long max) { return min + nextLong(max - min + 1); }
/** * @return Random float from 0 (inclusive) to 1 (exclusive) */ public float nextFloat() { return (nextInt() & 0x7FFFFFFF) / (Integer.MAX_VALUE + 1.0f); }
@ReceiveEvent public void onJump(JumpEvent event, EntityRef entity, CharacterSoundComponent characterSounds) { if (characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) { StaticSound sound = null; if (characterSounds.jumpSounds.size() > 0) { sound = random.nextItem(characterSounds.jumpSounds); } else if (characterSounds.footstepSounds.size() > 0) { sound = random.nextItem(characterSounds.footstepSounds); } if (sound != null) { entity.send(new PlaySoundEvent(entity, sound, characterSounds.jumpVolume)); characterSounds.lastSoundTime = time.getGameTimeInMs(); entity.saveComponent(characterSounds); } } }
/** * Randomises a provided Vector3f so its components range from -1.0 (inclusive) to 1.0 (inclusive) * * @param output * @return */ public Vector3f nextVector3f(Vector3f output) { return nextVector3f(-1.0f, 1.0f, output); }
/** * Calculates a standardized normal distributed value (using the polar method). * * @return The value */ public double nextGaussian() { double q = Double.MAX_VALUE; double u1 = 0; double u2; while (q >= 1d || q == 0) { u1 = nextDouble(-1.0, 1.0); u2 = nextDouble(-1.0, 1.0); q = TeraMath.pow(u1, 2) + TeraMath.pow(u2, 2); } double p = Math.sqrt(-2d * Math.log(q) / q); return u1 * p; // or u2 * p }
/** * @param min * @param max * @return Random double from min (inclusive) to max (inclusive) */ public double nextDouble(double min, double max) { return min + (max - min) * (nextLong() & 0x7FFFFFFFFFFFFFFFL) / Long.MAX_VALUE; }
/** * Randomises a provided Vector3f so its components range from min (inclusive) to max * * @param min * @param max * @param output * @return */ public Vector3f nextVector3f(float min, float max, Vector3f output) { output.set(nextFloat(min, max), nextFloat(min, max), nextFloat(min, max)); return output; }
/** * @param min * @param max * @return Random float from min (inclusive) to max (inclusive) */ public float nextFloat(float min, float max) { return min + (max - min) * (nextInt() & 0x7FFFFFFF) / Integer.MAX_VALUE; }