1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion-2.git synced 2025-02-27 15:46:01 +01:00

Add custom versions of hit particles

This commit is contained in:
chylex 2021-03-13 14:30:52 +01:00
parent da934f6922
commit e9e31fbdf5
6 changed files with 172 additions and 0 deletions

View File

@ -0,0 +1,57 @@
package chylex.hee.game.particle
import chylex.hee.game.particle.base.ParticleBaseHit
import chylex.hee.game.particle.data.ParticleDataColorLifespanScale
import chylex.hee.game.particle.spawner.IParticleMaker
import chylex.hee.system.color.IntColor
import chylex.hee.system.color.IntColor.Companion.RGB
import chylex.hee.system.forge.Side
import chylex.hee.system.forge.Sided
import chylex.hee.system.random.IRandomColor
import chylex.hee.system.random.nextInt
import net.minecraft.client.particle.Particle
import net.minecraft.world.World
import java.util.Random
object ParticleCriticalHitCustom : IParticleMaker.WithData<ParticleDataColorLifespanScale>() {
private val rand = Random()
@Sided(Side.CLIENT)
override fun create(world: World, posX: Double, posY: Double, posZ: Double, motX: Double, motY: Double, motZ: Double, data: ParticleDataColorLifespanScale?): Particle {
return Instance(world, posX, posY, posZ, motX, motY, motZ, data ?: DEFAULT_DATA.generate(rand))
}
fun Data(
color: IRandomColor = DefaultColor,
lifespan: IntRange = DEFAULT_LIFESPAN,
scale: ClosedFloatingPointRange<Float>,
) = ParticleDataColorLifespanScale.Generator(color, lifespan, scale)
fun Data(
color: IntColor,
scale: Float,
) = ParticleDataColorLifespanScale.Generator(IRandomColor.Static(color), DEFAULT_LIFESPAN, scale..scale)
private object DefaultColor : IRandomColor {
override fun next(rand: Random): IntColor {
return RGB(rand.nextInt(153, 230).toUByte())
}
}
private val DEFAULT_DATA = Data(scale = (1F)..(1F))
private val DEFAULT_LIFESPAN = (-1)..(-1)
@Sided(Side.CLIENT)
private class Instance(world: World, posX: Double, posY: Double, posZ: Double, motX: Double, motY: Double, motZ: Double, data: ParticleDataColorLifespanScale) : ParticleBaseHit(world, posX, posY, posZ, motX, motY, motZ) {
init {
selectSpriteRandomly(ParticleCriticalHitCustom.sprite)
loadColor(data.color)
particleScale = data.scale
if (data.lifespan != -1) {
maxAge = data.lifespan
}
}
}
}

View File

@ -0,0 +1,57 @@
package chylex.hee.game.particle
import chylex.hee.game.particle.base.ParticleBaseHit
import chylex.hee.game.particle.data.ParticleDataColorLifespanScale
import chylex.hee.game.particle.spawner.IParticleMaker
import chylex.hee.system.color.IntColor
import chylex.hee.system.color.IntColor.Companion.RGB
import chylex.hee.system.forge.Side
import chylex.hee.system.forge.Sided
import chylex.hee.system.random.IRandomColor
import chylex.hee.system.random.nextInt
import net.minecraft.client.particle.Particle
import net.minecraft.world.World
import java.util.Random
object ParticleEnchantedHitCustom : IParticleMaker.WithData<ParticleDataColorLifespanScale>() {
private val rand = Random()
@Sided(Side.CLIENT)
override fun create(world: World, posX: Double, posY: Double, posZ: Double, motX: Double, motY: Double, motZ: Double, data: ParticleDataColorLifespanScale?): Particle {
return Instance(world, posX, posY, posZ, motX, motY, motZ, data ?: DEFAULT_DATA.generate(rand))
}
fun Data(
color: IRandomColor = DefaultColor,
lifespan: IntRange = DEFAULT_LIFESPAN,
scale: Float,
) = ParticleDataColorLifespanScale.Generator(color, lifespan, scale..scale)
fun Data(
color: IntColor,
scale: Float,
) = ParticleDataColorLifespanScale.Generator(IRandomColor.Static(color), DEFAULT_LIFESPAN, scale..scale)
private object DefaultColor : IRandomColor {
override fun next(rand: Random): IntColor {
return RGB(rand.nextInt(46, 69), rand.nextInt(122, 184), rand.nextInt(153, 230))
}
}
private val DEFAULT_DATA = Data(scale = 1F)
private val DEFAULT_LIFESPAN = (-1)..(-1)
@Sided(Side.CLIENT)
private class Instance(world: World, posX: Double, posY: Double, posZ: Double, motX: Double, motY: Double, motZ: Double, data: ParticleDataColorLifespanScale) : ParticleBaseHit(world, posX, posY, posZ, motX, motY, motZ) {
init {
selectSpriteRandomly(ParticleEnchantedHitCustom.sprite)
loadColor(data.color)
particleScale = data.scale
if (data.lifespan != -1) {
maxAge = data.lifespan
}
}
}
}

View File

@ -0,0 +1,44 @@
package chylex.hee.game.particle.base
import net.minecraft.world.World
abstract class ParticleBaseHit(world: World, posX: Double, posY: Double, posZ: Double, motX: Double, motY: Double, motZ: Double) : ParticleBase(world, posX, posY, posZ, motX, motY, motZ) {
init {
maxAge = (6.0 / (Math.random() * 0.8 + 0.6)).toInt().coerceAtLeast(1)
canCollide = false
motionX = motX
motionY = motY
motionZ = motZ
}
override fun getScale(partialTicks: Float): Float {
return particleScale * ((age + partialTicks) / maxAge.toFloat() * 32F).coerceIn(0F, 1F)
}
override fun tick() {
prevPosX = posX
prevPosY = posY
prevPosZ = posZ
if (age++ >= maxAge) {
setExpired()
return
}
particleRed *= 0.99F
particleGreen *= 0.99F
particleBlue *= 0.99F
move(motionX, motionY, motionZ)
motionX *= 0.9
motionY *= 0.9
motionZ *= 0.9
motionY -= particleGravity
if (onGround) {
motionX *= 0.7
motionZ *= 0.7
}
}
}

View File

@ -3,8 +3,10 @@ package chylex.hee.init
import chylex.hee.HEE
import chylex.hee.client.MC
import chylex.hee.game.particle.ParticleBubbleCustom
import chylex.hee.game.particle.ParticleCriticalHitCustom
import chylex.hee.game.particle.ParticleDeathFlowerHeal
import chylex.hee.game.particle.ParticleDust
import chylex.hee.game.particle.ParticleEnchantedHitCustom
import chylex.hee.game.particle.ParticleEnderGoo
import chylex.hee.game.particle.ParticleEnergyCluster
import chylex.hee.game.particle.ParticleEnergyClusterRevitalization
@ -41,8 +43,10 @@ object ModParticles {
fun onRegister(e: RegistryEvent.Register<ParticleType<*>>) {
with(e.registry) {
register(ParticleBubbleCustom.makeType named "bubble")
register(ParticleCriticalHitCustom.makeType named "critical_hit")
register(ParticleDeathFlowerHeal.makeType named "death_flower_heal")
register(ParticleDust.makeType named "dust")
register(ParticleEnchantedHitCustom.makeType named "enchanted_hit")
register(ParticleEnderGoo.makeType named "ender_goo")
register(ParticleEnergyCluster.makeType named "energy_cluster")
register(ParticleEnergyClusterRevitalization.makeType named "energy_cluster_revitalization")

View File

@ -0,0 +1,5 @@
{
"textures": [
"minecraft:critical_hit"
]
}

View File

@ -0,0 +1,5 @@
{
"textures": [
"minecraft:enchanted_hit"
]
}