Improved particle animations
This commit is contained in:
@@ -1,19 +1,15 @@
|
||||
package com.willfp.ecocrates.crate.placed.particle
|
||||
|
||||
import com.willfp.eco.util.NumberUtils
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.util.Vector
|
||||
import kotlin.math.PI
|
||||
|
||||
class CircleParticleAnimation : ParticleAnimation("circle") {
|
||||
override fun getSpawnLocation(center: Location, tick: Int): Location {
|
||||
val x = center.x + (NumberUtils.fastSin(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius"))
|
||||
val y = center.y + config.getDouble("height")
|
||||
val z = center.z + (NumberUtils.fastCos(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius"))
|
||||
|
||||
return center.clone().apply {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
}
|
||||
override fun getOffset(tick: Int): Vector {
|
||||
return Vector(
|
||||
NumberUtils.fastSin(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius"),
|
||||
config.getDouble("height"),
|
||||
NumberUtils.fastCos(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
package com.willfp.ecocrates.crate.placed.particle
|
||||
|
||||
import com.willfp.eco.util.NumberUtils
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.util.Vector
|
||||
import kotlin.math.PI
|
||||
|
||||
class DoubleSpiralParticleAnimation : ParticleAnimation("double_spiral") {
|
||||
override fun getSpawnLocation(center: Location, tick: Int): Location {
|
||||
var x = center.x + (NumberUtils.fastSin(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius"))
|
||||
var y = center.y + (-NumberUtils.fastCos(config.getDouble("rises-per-second") * 2 * PI * tick / 20) * config.getDouble("height"))
|
||||
var z = center.z + (NumberUtils.fastCos(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius"))
|
||||
|
||||
if (tick % 2 == 0) {
|
||||
x *= -1
|
||||
y *= -1
|
||||
z *= -1
|
||||
}
|
||||
|
||||
return center.clone().apply {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
override fun getOffset(tick: Int): Vector {
|
||||
return Vector(
|
||||
NumberUtils.fastSin(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius"),
|
||||
-NumberUtils.fastCos(config.getDouble("rises-per-second") * 2 * PI * tick / 20) * config.getDouble("height"),
|
||||
NumberUtils.fastCos(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius")
|
||||
).apply {
|
||||
if (tick % 2 == 0) {
|
||||
this.multiply(-1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.willfp.ecocrates.crate.placed.particle
|
||||
import com.willfp.ecocrates.EcoCratesPlugin
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.Particle
|
||||
import org.bukkit.util.Vector
|
||||
|
||||
abstract class ParticleAnimation(
|
||||
val id: String
|
||||
@@ -18,10 +19,10 @@ abstract class ParticleAnimation(
|
||||
}
|
||||
|
||||
fun spawnParticle(center: Location, tick: Int, particle: Particle) {
|
||||
val location = getSpawnLocation(center.clone(), tick)
|
||||
val location = center.clone().add(getOffset(tick))
|
||||
val world = location.world ?: return
|
||||
world.spawnParticle(particle, location, 1, 0.0, 0.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
protected abstract fun getSpawnLocation(center: Location, tick: Int): Location
|
||||
}
|
||||
protected abstract fun getOffset(tick: Int): Vector
|
||||
}
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
package com.willfp.ecocrates.crate.placed.particle
|
||||
|
||||
import com.willfp.eco.util.NumberUtils
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.util.Vector
|
||||
import kotlin.math.PI
|
||||
|
||||
class SpiralParticleAnimation : ParticleAnimation("spiral") {
|
||||
override fun getSpawnLocation(center: Location, tick: Int): Location {
|
||||
val x = center.x + (NumberUtils.fastSin(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius"))
|
||||
val y = center.y + (-NumberUtils.fastCos(config.getDouble("rises-per-second") * 2 * PI * tick / 20) * config.getDouble("height"))
|
||||
val z = center.z + (NumberUtils.fastCos(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius"))
|
||||
|
||||
return center.clone().apply {
|
||||
this.x = x
|
||||
this.y = y
|
||||
this.z = z
|
||||
}
|
||||
override fun getOffset(tick: Int): Vector {
|
||||
return Vector(
|
||||
NumberUtils.fastSin(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius"),
|
||||
-NumberUtils.fastCos(config.getDouble("rises-per-second") * 2 * PI * tick / 20) * config.getDouble("height"),
|
||||
NumberUtils.fastCos(config.getDouble("spirals-per-second") * 2 * PI * tick / 20) * config.getDouble("radius")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user