mirror of
https://github.com/chylex/Hardcore-Ender-Expansion-2.git
synced 2025-04-11 03:15:44 +02:00
Add a way to generate and validate particle data array
This commit is contained in:
parent
a5fb760fd0
commit
4d932dff42
src/main/java/chylex/hee/game/particle/spawner
@ -1,7 +1,6 @@
|
||||
package chylex.hee.game.particle.spawner
|
||||
import chylex.hee.game.particle.util.IShape
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.world.IWorldEventListener
|
||||
import net.minecraftforge.fml.relauncher.Side
|
||||
import net.minecraftforge.fml.relauncher.SideOnly
|
||||
import java.util.Random
|
||||
@ -9,9 +8,9 @@ import java.util.Random
|
||||
interface IParticleSpawner{
|
||||
fun spawn(shape: IShape, rand: Random)
|
||||
|
||||
companion object{
|
||||
val world: IWorldEventListener // TODO make protected and JvmStatic in kotlin 1.3
|
||||
companion object{ // TODO make properties protected and JvmStatic in kotlin 1.3
|
||||
val mc: Minecraft
|
||||
@SideOnly(Side.CLIENT)
|
||||
get() = Minecraft.getMinecraft().renderGlobal!!
|
||||
get() = Minecraft.getMinecraft()
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package chylex.hee.game.particle.spawner
|
||||
import chylex.hee.game.particle.spawner.IParticleSpawner.Companion.world
|
||||
import chylex.hee.game.particle.spawner.IParticleSpawner.Companion.mc
|
||||
import chylex.hee.game.particle.spawner.factory.IParticleData
|
||||
import chylex.hee.game.particle.spawner.factory.IParticleData.Empty
|
||||
import chylex.hee.game.particle.util.IOffset
|
||||
import chylex.hee.game.particle.util.IOffset.MutableOffsetPoint
|
||||
import chylex.hee.game.particle.util.IOffset.None
|
||||
@ -9,6 +11,7 @@ import java.util.Random
|
||||
|
||||
class ParticleSpawnerVanilla(
|
||||
type: EnumParticleTypes,
|
||||
private val data: IParticleData = Empty,
|
||||
private val pos: IOffset = None,
|
||||
private val mot: IOffset = None,
|
||||
private val ignoreRangeLimit: Boolean = false,
|
||||
@ -21,13 +24,13 @@ class ParticleSpawnerVanilla(
|
||||
private val tmpOffsetMot = MutableOffsetPoint()
|
||||
|
||||
override fun spawn(shape: IShape, rand: Random){
|
||||
val world = world
|
||||
val renderer = mc.renderGlobal
|
||||
|
||||
for(point in shape.points){
|
||||
pos.next(tmpOffsetPos, rand)
|
||||
mot.next(tmpOffsetMot, rand)
|
||||
|
||||
world.spawnParticle(
|
||||
renderer.spawnParticle(
|
||||
particleID,
|
||||
ignoreRangeLimit,
|
||||
showSomeParticlesEvenOnMinimalSetting,
|
||||
@ -36,7 +39,8 @@ class ParticleSpawnerVanilla(
|
||||
point.z + tmpOffsetPos.z,
|
||||
tmpOffsetMot.x.toDouble(),
|
||||
tmpOffsetMot.y.toDouble(),
|
||||
tmpOffsetMot.z.toDouble()
|
||||
tmpOffsetMot.z.toDouble(),
|
||||
*data.generate(rand)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package chylex.hee.game.particle.spawner.factory
|
||||
import org.apache.commons.lang3.ArrayUtils.EMPTY_INT_ARRAY
|
||||
import java.util.Random
|
||||
|
||||
interface IParticleData{
|
||||
fun generate(rand: Random): IntArray
|
||||
|
||||
object Empty : IParticleData{
|
||||
override fun generate(rand: Random): IntArray = EMPTY_INT_ARRAY
|
||||
}
|
||||
|
||||
open class Static(private val data: IntArray) : IParticleData{
|
||||
override fun generate(rand: Random): IntArray = data
|
||||
|
||||
/**
|
||||
* Performs validation of [inputData], using itself as the fallback value.
|
||||
*
|
||||
* The intended use is creating an instance with valid default values, and calling [validate] with the [IntArray] provided to [IParticleMaker.create].
|
||||
* By default, the returned array is guaranteed to have at least as many elements as the internal [data] array, removing the need to check bounds.
|
||||
*/
|
||||
open fun validate(inputData: IntArray): IntArray{
|
||||
return if (inputData.size < data.size)
|
||||
data
|
||||
else
|
||||
inputData
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user