particles suck
This commit is contained in:
parent
b47a97e838
commit
3fb5f0d1b2
3 changed files with 38 additions and 21 deletions
|
@ -2,13 +2,19 @@ package at.petrak.hexcasting.common.casting
|
|||
|
||||
import at.petrak.hexcasting.api.RenderedSpell
|
||||
import at.petrak.hexcasting.api.SpellDatum
|
||||
import at.petrak.hexcasting.common.particles.HexParticles
|
||||
import at.petrak.hexcasting.datagen.Advancements
|
||||
import com.mojang.math.Quaternion
|
||||
import com.mojang.math.Vector3f
|
||||
import net.minecraft.Util
|
||||
import net.minecraft.core.particles.DustParticleOptions
|
||||
import net.minecraft.network.chat.TextComponent
|
||||
import net.minecraft.network.chat.TranslatableComponent
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import kotlin.math.acos
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
import kotlin.math.sqrt
|
||||
import kotlin.random.Random
|
||||
import kotlin.random.nextInt
|
||||
|
||||
|
@ -50,7 +56,8 @@ sealed class OperatorSideEffect {
|
|||
}
|
||||
}
|
||||
|
||||
data class Particles(val position: Vec3) : OperatorSideEffect() {
|
||||
data class Particles(val position: Vec3, val velocity: Vec3, val fuzziness: Double, val spread: Double) :
|
||||
OperatorSideEffect() {
|
||||
override fun performEffect(harness: CastingHarness): Boolean {
|
||||
val colorizer = harness.getColorizer()
|
||||
|
||||
|
@ -58,16 +65,32 @@ sealed class OperatorSideEffect {
|
|||
// For the colors, pick any random time to get a mix of colors
|
||||
val color = colorizer.getColor(Random.nextFloat() * 256f, Vec3.ZERO)
|
||||
|
||||
harness.ctx.world.sendParticles(
|
||||
DustParticleOptions(Vector3f(Vec3.fromRGB24(color)), 1f),
|
||||
position.x,
|
||||
position.y,
|
||||
position.z,
|
||||
1,
|
||||
0.1,
|
||||
0.1,
|
||||
0.1,
|
||||
0.1,
|
||||
// https://math.stackexchange.com/questions/44689/how-to-find-a-random-axis-or-unit-vector-in-3d
|
||||
fun randomInCircle(maxTh: Double = Mth.TWO_PI.toDouble()): Vec3 {
|
||||
val th = Random.nextDouble(0.0, maxTh)
|
||||
val z = Random.nextDouble(-1.0, 1.0)
|
||||
return Vec3(sqrt(1.0 - z * z) * cos(th), sqrt(1.0 - z * z) * sin(th), z)
|
||||
}
|
||||
|
||||
val offset = randomInCircle().scale(fuzziness)
|
||||
val pos = position.add(offset)
|
||||
|
||||
// https://math.stackexchange.com/questions/56784/generate-a-random-direction-within-a-cone
|
||||
val northCone = randomInCircle(spread)
|
||||
val velNorm = velocity.normalize()
|
||||
val zp = Vec3(0.0, 0.0, 1.0)
|
||||
val rotAxis = velNorm.cross(zp)
|
||||
val th = acos(velNorm.dot(zp))
|
||||
val dagn = Quaternion(Vector3f(rotAxis), th.toFloat(), false)
|
||||
val velf = Vector3f(northCone)
|
||||
velf.transform(dagn)
|
||||
val vel = Vec3(velf).scale(velocity.length())
|
||||
|
||||
// TODO: this doesn't work because xyz velocity is a lie
|
||||
harness.ctx.world.addParticle(
|
||||
HexParticles.CONJURE_BLOCK_PARTICLE.get(),
|
||||
pos.x, pos.y, pos.z,
|
||||
vel.x, vel.y, vel.z,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
{
|
||||
"textures": [
|
||||
"hexcasting:spin_cube_7",
|
||||
"hexcasting:spin_cube_6",
|
||||
"hexcasting:spin_cube_5",
|
||||
"hexcasting:spin_cube_4",
|
||||
"hexcasting:spin_cube_3",
|
||||
"hexcasting:spin_cube_2",
|
||||
"hexcasting:spin_cube_1"
|
||||
]
|
||||
"textures": [
|
||||
"hexcasting:cloud"
|
||||
]
|
||||
}
|
BIN
src/main/resources/assets/hexcasting/textures/particle/cloud.png
Normal file
BIN
src/main/resources/assets/hexcasting/textures/particle/cloud.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 459 B |
Loading…
Reference in a new issue