mirror of
https://github.com/chylex/Hardcore-Ender-Expansion-2.git
synced 2025-04-11 03:15:44 +02:00
Add Random extensions for Kotlin ranges & update existing code to use them
This commit is contained in:
parent
2770dc36b7
commit
6fcf9d5e57
src/main/java/chylex/hee
game
entity/living/enderman
particle
world
system/util
@ -228,8 +228,8 @@ class EndermanTeleportHandler(private val enderman: EntityMobAbstractEnderman) :
|
||||
val targetVec = target.posVec
|
||||
|
||||
for(attempt in 1..50){
|
||||
val dir = Vec3.fromYaw(target.rotationYaw + rand.nextFloat(angleRange.start, angleRange.endInclusive))
|
||||
val distance = rand.nextFloat(distanceRange.start, distanceRange.endInclusive)
|
||||
val dir = Vec3.fromYaw(target.rotationYaw + rand.nextFloat(angleRange))
|
||||
val distance = rand.nextFloat(distanceRange)
|
||||
|
||||
val offsetVec = targetVec.add(dir.scale(distance))
|
||||
val targetPos = Pos(offsetVec).add(0, rand.nextInt(-4, 8), 0).offsetUntil(DOWN, 0..4){ it.blocksMovement(world) }?.up()
|
||||
@ -250,7 +250,7 @@ class EndermanTeleportHandler(private val enderman: EntityMobAbstractEnderman) :
|
||||
val endermanPos = Pos(enderman)
|
||||
|
||||
for(attempt in 1..25){
|
||||
val (x, y, z) = rand.nextVector2(xz = rand.nextFloat(distanceRange.start, distanceRange.endInclusive), y = rand.nextFloat(-24.0, 48.0))
|
||||
val (x, y, z) = rand.nextVector2(xz = rand.nextFloat(distanceRange), y = rand.nextFloat(-24.0, 48.0))
|
||||
val targetPos = endermanPos.add(x, y, z).offsetUntil(DOWN, 0..24){ it.blocksMovement(world) }?.up()
|
||||
|
||||
if (targetPos != null && teleportTo(targetPos)){
|
||||
|
@ -28,7 +28,7 @@ object ParticleFadingSpot : IParticleMaker{
|
||||
constructor(color: IColor, lifespan: IntRange = 0..0, scale: ClosedFloatingPointRange<Float> = 0F..0F) : this({ color }, lifespan, scale)
|
||||
|
||||
override fun generate(rand: Random): IntArray{
|
||||
return intArrayOf(color(rand).toInt(), rand.nextInt(lifespan.first, lifespan.last), (rand.nextFloat(scale.start, scale.endInclusive) * 100F).floorToInt())
|
||||
return intArrayOf(color(rand).toInt(), rand.nextInt(lifespan), (rand.nextFloat(scale) * 100F).floorToInt())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ class BlobPattern private constructor(
|
||||
)
|
||||
|
||||
constructor(generators: WeightedList<IBlobGenerator>, populators: WeightedList<IBlobPopulator>, populatorAmount: IntRange) : this(
|
||||
generators, populators to { rand -> rand.nextInt(populatorAmount.first, populatorAmount.last) }
|
||||
generators, populators to { rand -> rand.nextInt(populatorAmount) }
|
||||
)
|
||||
|
||||
fun pickGenerator(rand: Random): IBlobGenerator{
|
||||
|
@ -219,7 +219,7 @@ class Teleporter(
|
||||
val originalBox = entity.entityBoundingBox
|
||||
|
||||
repeat(attempts){
|
||||
val randomPos = position.add(rand.nextVector(rand.nextFloat(distance.start, distance.endInclusive)))
|
||||
val randomPos = position.add(rand.nextVector(rand.nextFloat(distance)))
|
||||
val newPos = Vec3d(randomPos.x, randomPos.y.floorToInt() + 0.01, randomPos.z)
|
||||
|
||||
if (Pos(newPos).down().blocksMovement(world) && world.getCollisionBoxes(entity, originalBox.offset(newPos.subtract(originalPos))).isEmpty()){
|
||||
|
@ -28,6 +28,13 @@ fun Random.nextInt(min: Int, max: Int): Int{
|
||||
return min + this.nextInt(max - min + 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random integer within the specified range.
|
||||
*/
|
||||
fun Random.nextInt(range: IntRange): Int{
|
||||
return this.nextInt(range.first, range.last)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random long integer between `min` and `max` (both inclusive).
|
||||
* @throws IllegalArgumentException if `min` is greater than `max`
|
||||
@ -52,6 +59,13 @@ fun Random.nextFloat(min: Float, max: Float): Float{
|
||||
return min + (this.nextFloat() * (max - min))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random floating point number within the specified range.
|
||||
*/
|
||||
fun Random.nextFloat(range: ClosedFloatingPointRange<Float>): Float{
|
||||
return this.nextFloat(range.start, range.endInclusive)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random floating point number between `min` and `max`, but returns a [Double] for convenience.
|
||||
* @throws IllegalArgumentException if `min` is greater than `max`
|
||||
@ -64,6 +78,13 @@ fun Random.nextFloat(min: Double, max: Double): Double{
|
||||
return min + (this.nextFloat() * (max - min))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random floating point number within the specified range, but returns a [Double] for convenience.
|
||||
*/
|
||||
fun Random.nextFloat(range: ClosedFloatingPointRange<Double>): Double{
|
||||
return this.nextFloat(range.start, range.endInclusive)
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the decimal part of a number as a probability of rounding the number up.
|
||||
* For example, when the provided value is 3.8, the function will have an 80% chance to return 4, and a 20% chance to return 3.
|
||||
|
Loading…
Reference in New Issue
Block a user