11package com.lambda.module.modules.render
22
3+ import com.lambda.Lambda.mc
4+ import com.lambda.context.SafeContext
35import com.lambda.event.events.AttackEvent
46import com.lambda.event.events.MovementEvent
57import com.lambda.event.events.RenderEvent
@@ -10,22 +12,25 @@ import com.lambda.graphics.buffer.vao.vertex.VertexAttrib
1012import com.lambda.graphics.buffer.vao.vertex.VertexMode
1113import com.lambda.graphics.gl.GlStateUtils.withBlendFunc
1214import com.lambda.graphics.gl.GlStateUtils.withDepth
15+ import com.lambda.graphics.gl.Matrices
1316import com.lambda.graphics.gl.Matrices.buildWorldProjection
1417import com.lambda.graphics.gl.Matrices.withVertexTransform
1518import com.lambda.graphics.shader.Shader
19+ import com.lambda.interaction.rotation.Rotation
1620import com.lambda.module.Module
1721import com.lambda.module.modules.client.GuiSettings
1822import com.lambda.module.modules.client.GuiSettings.colorSpeed
1923import com.lambda.module.tag.ModuleTag
20- import com.lambda.threading.runSafe
2124import com.lambda.util.math.ColorUtils.multAlpha
2225import com.lambda.util.math.MathUtils.lerp
2326import com.lambda.util.math.MathUtils.random
27+ import com.lambda.util.math.VecUtils
28+ import com.lambda.util.math.VecUtils.plus
29+ import com.lambda.util.math.VecUtils.times
2430import com.lambda.util.math.transform
2531import com.lambda.util.player.MovementUtils.moveDelta
26- import com.lambda.util.player.MovementUtils.movementVector
27- import com.lambda.util.player.MovementUtils.randomDirection
2832import com.lambda.util.primitives.extension.partialTicks
33+ import com.lambda.util.world.raycast.RayCastMask
2934import net.minecraft.entity.Entity
3035import net.minecraft.util.math.Vec3d
3136
@@ -38,26 +43,33 @@ object Particles : Module(
3843 description = " Spawns fancy particles" ,
3944 defaultTags = setOf(ModuleTag .RENDER )
4045) {
46+ // ToDo: resort, cleanup settings
4147 private val duration by setting(" Duration" , 5.0 , 1.0 .. 500.0 , 1.0 )
4248 private val fadeDuration by setting(" Fade Ticks" , 5.0 , 1.0 .. 30.0 , 1.0 )
43- private val spawnAmount by setting(" Spawn Amount" , 30.0 , 3.0 .. 500.0 , 1.0 )
44- private val size by setting(" Size" , 2.0 , 0.1 .. 50.0 , 0.1 )
49+ private val spawnAmount by setting(" Spawn Amount" , 20 , 3 .. 500 , 1 )
50+ private val sizeSetting by setting(" Size" , 2.0 , 0.1 .. 50.0 , 0.1 )
4551 private val alphaSetting by setting(" Alpha" , 1.5 , 0.01 .. 2.0 , 0.01 )
4652 private val speedH by setting(" Speed H" , 1.0 , 0.0 .. 10.0 , 0.1 )
4753 private val speedV by setting(" Speed V" , 1.0 , 0.0 .. 10.0 , 0.1 )
4854 private val inertia by setting(" Inertia" , 0.0 , 0.0 .. 1.0 , 0.01 )
4955 private val gravity by setting(" Gravity" , 0.2 , 0.0 .. 1.0 , 0.01 )
56+ private val onMove by setting(" On Move" , false )
5057
51- private val onMove by setting(" On Move" , true )
58+ private val environment by setting(" Environment" , true )
59+ private val environmentSpawnAmount by setting(" E Spawn Amount" , 10 , 3 .. 100 , 1 ) { environment }
60+ private val environmentSize by setting(" E Size" , 2.0 , 0.1 .. 50.0 , 0.1 ) { environment }
61+ private val environmentRange by setting(" E Spread" , 5.0 , 1.0 .. 20.0 , 0.1 ) { environment }
62+ private val environmentSpeedH by setting(" E Speed H" , 0.0 , 0.0 .. 10.0 , 0.1 ) { environment }
63+ private val environmentSpeedV by setting(" E Speed V" , 0.1 , 0.0 .. 10.0 , 0.1 ) { environment }
5264
5365 private var particles = mutableListOf<Particle >()
5466 private val vao = VAO (VertexMode .TRIANGLES , VertexAttrib .Group .PARTICLE )
5567 private val shader = Shader (" renderer/particle" , " renderer/particle" )
5668
5769 init {
5870 listener<TickEvent .Pre > {
59- particles.forEach( Particle ::tick )
60- particles.removeIf(Particle ::shouldRemove )
71+ if (environment) spawnForEnvironment( )
72+ particles.removeIf(Particle ::update )
6173 }
6274
6375 listener<RenderEvent .World > {
@@ -85,77 +97,91 @@ object Particles : Module(
8597 }
8698
8799 private fun spawnForEntity (entity : Entity ) {
88- repeat(spawnAmount.toInt() ) {
89- val i = (it + 1 ) / spawnAmount
100+ repeat(spawnAmount) {
101+ val i = (it + 1 ) / spawnAmount.toDouble()
90102
91103 val pos = entity.pos
92104 val height = entity.boundingBox.lengthY
93105 val spawnHeight = height * transform(i, 0.0 , 1.0 , 0.2 , 0.8 )
94106 val particlePos = pos.add(0.0 , spawnHeight, 0.0 )
107+ val particleMotion = Rotation (
108+ random(- 180.0 , 180.0 ),
109+ random(- 90.0 , 90.0 )
110+ ).vector * Vec3d (speedH, speedV, speedH) * 0.1
95111
96- particles.add( Particle (particlePos) )
112+ particles + = Particle (particlePos, particleMotion, false )
97113 }
98114 }
99115
100- private class Particle ( posIn : Vec3d ) {
101- var initTick = 0
102- var maxAge = 0
103- var fadeTicks = fadeDuration
116+ private fun SafeContext. spawnForEnvironment ( ) {
117+ if (mc.paused) return
118+ repeat(environmentSpawnAmount) {
119+ var particlePos = player.pos + Rotation (random( - 180.0 , 180.0 ), 0.0 ).vector * random( 0.0 , environmentRange)
104120
105- var shouldRemove = false
121+ Rotation .DOWN .rayCast(6.0 , particlePos + VecUtils .UP * 2.0 , true , RayCastMask .BLOCK )?.pos?.let {
122+ particlePos = it + VecUtils .UP * 0.03
123+ } ? : return @repeat
106124
107- var prevPos = posIn
108- var pos = posIn
125+ val particleMotion = Rotation (
126+ random(- 180.0 , 180.0 ),
127+ random(- 90.0 , 90.0 )
128+ ).vector * Vec3d (environmentSpeedH, environmentSpeedV, environmentSpeedH) * 0.1
109129
110- var motion: Vec3d = Vec3d .ZERO
130+ particles + = Particle (particlePos, particleMotion, true )
131+ }
132+ }
111133
112- init {
113- runSafe {
114- initTick = player.age
115- maxAge = (duration + random(0.0 , 20.0 )).toInt()
134+ private class Particle (
135+ initialPosition : Vec3d ,
136+ initialMotion : Vec3d ,
137+ val lay : Boolean
138+ ) {
139+ private val fadeTicks = fadeDuration
116140
141+ private var age = 0
142+ private val maxAge = (duration + random(0.0 , 20.0 )).toInt()
117143
118- motion = movementVector(randomDirection(), sin(random(0.0 , Math .PI )))
119- .multiply(random(0.0 , 1.0 ), random(0.0 , 1.0 ), random(0.0 , 1.0 ))
120- .multiply(
121- speedH * random(0.9 , 1.1 ),
122- speedV * random(0.9 , 1.1 ),
123- speedH * random(0.9 , 1.1 )
124- ).multiply(0.1 )
125- }
126- }
144+ private var prevPos = initialPosition
145+ private var position = initialPosition
146+ private var motion = initialMotion
127147
128- fun tick () = runSafe {
129- prevPos = pos
130- pos = pos.add(motion)
148+ private val projRotation = if (lay) Matrices .ProjRotationMode .UP else Matrices .ProjRotationMode .TO_CAMERA
131149
132- motion = motion
133- .subtract( 0.0 , gravity * 0.01 , 0.0 )
134- .multiply( 0.9 + inertia * 0.1 )
150+ fun update (): Boolean {
151+ if (mc.paused) return false
152+ age ++
135153
136- shouldRemove = player.age - initTick > 5.0 + maxAge + fadeTicks * 2
154+ prevPos = position
155+
156+ if (! lay) motion + = VecUtils .DOWN * gravity * 0.01
157+ motion * = 0.9 + inertia * 0.1
158+
159+ position + = motion
160+
161+ return age > maxAge + fadeTicks * 2 + 5
137162 }
138163
139- fun build () = runSafe {
140- val age = player. age - initTick + mc.partialTicks
141- val colorTicks = age * 0.1 / colorSpeed
164+ fun build () {
165+ val smoothAge = age + mc.partialTicks
166+ val colorTicks = smoothAge * 0.1 / colorSpeed
142167
143168 val alpha = when {
144- age < fadeTicks -> age / fadeTicks
145- age in fadeTicks.. fadeTicks + maxAge -> 1.0
169+ smoothAge < fadeTicks -> smoothAge / fadeTicks
170+ smoothAge in fadeTicks.. fadeTicks + maxAge -> 1.0
146171 else -> {
147172 val min = fadeTicks + maxAge
148173 val max = fadeTicks * 2 + maxAge
149- transform(age , min, max, 1.0 , 0.0 )
174+ transform(smoothAge , min, max, 1.0 , 0.0 )
150175 }
151- } * alphaSetting
176+ }
152177
153178 val (c1, c2) = GuiSettings .primaryColor to GuiSettings .secondaryColor
154- val color = lerp(c1, c2, sin(colorTicks) * 0.5 + 0.5 ).multAlpha(alpha)
179+ val color = lerp(c1, c2, sin(colorTicks) * 0.5 + 0.5 ).multAlpha(alpha * alphaSetting )
155180
156- val position = lerp(prevPos, pos, mc.partialTicks)
181+ val position = lerp(prevPos, position, mc.partialTicks)
182+ val size = if (lay) environmentSize else sizeSetting * lerp(0.5 , 1.0 , alpha)
157183
158- withVertexTransform(buildWorldProjection(position, size)) {
184+ withVertexTransform(buildWorldProjection(position, size, projRotation )) {
159185 vao.use {
160186 grow(4 ) // DO NOT FUCKING FORGOTEOIJTOWKET TO GROW (cost me an hour)
161187 putQuad(
0 commit comments