generated from Polyfrost/OneConfigExampleMod
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- "Cleaner Particles" feature
- Loading branch information
Showing
9 changed files
with
106 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 47 additions & 10 deletions
57
src/main/kotlin/org/polyfrost/overflowparticles/utils/Util.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,58 @@ | ||
package org.polyfrost.overflowparticles.utils | ||
|
||
import net.minecraft.world.IWorldAccess | ||
import org.polyfrost.overflowparticles.config.MainConfig | ||
import org.polyfrost.overflowparticles.config.ParticleConfig | ||
|
||
fun color(color: Int, targetColor: Float, cfg: ParticleConfig) : Float = | ||
fun color(color: Int, targetColor: Float, cfg: ParticleConfig): Float = | ||
if (cfg.entry.customColor) color / 255f * if (cfg.entry.colorMode) 1f else targetColor else targetColor | ||
|
||
fun colorInt(color: Int, targetColor: Float, cfg: ParticleConfig) : Int = | ||
(color(color, targetColor, cfg) * 255f).toInt() | ||
fun colorInt(color: Int, targetColor: Float, cfg: ParticleConfig): Int = (color(color, targetColor, cfg) * 255f).toInt() | ||
|
||
fun spawn(config: ParticleConfig, worldAccesses: List<IWorldAccess>, particleID: Int, ignoreRange: Boolean, x: Double, y: Double, z: Double, xOffset: Double, yOffset: Double, zOffset: Double, vararg arguments: Int) { | ||
repeat(config.entry.multiplier) { | ||
for (worldAccess in worldAccesses) { | ||
val modX = x - 0.5 + Math.random() | ||
val modY = y - 0.5 + Math.random() | ||
val modZ = z - 0.5 + Math.random() | ||
worldAccess.spawnParticle(particleID, ignoreRange, modX, modY, modZ, xOffset, yOffset, zOffset, *arguments); | ||
fun spawn( | ||
config: ParticleConfig, | ||
worldAccesses: List<IWorldAccess>, | ||
particleID: Int, | ||
ignoreRange: Boolean, | ||
x: Double, | ||
y: Double, | ||
z: Double, | ||
xOffset: Double, | ||
yOffset: Double, | ||
zOffset: Double, | ||
vararg arguments: Int | ||
) { | ||
val multiplier = config.entry.multiplier | ||
val integerPart = multiplier.toInt() | ||
val fractionalPart = multiplier - integerPart | ||
|
||
repeat(integerPart) { | ||
spawnParticle(worldAccesses, particleID, ignoreRange, x, y, z, xOffset, yOffset, zOffset, *arguments) | ||
} | ||
|
||
if (fractionalPart > 0) { | ||
if (Math.random() < fractionalPart) { | ||
spawnParticle(worldAccesses, particleID, ignoreRange, x, y, z, xOffset, yOffset, zOffset, *arguments) | ||
} | ||
} | ||
} | ||
|
||
private fun spawnParticle( | ||
worldAccesses: List<IWorldAccess>, | ||
particleID: Int, | ||
ignoreRange: Boolean, | ||
x: Double, | ||
y: Double, | ||
z: Double, | ||
xOffset: Double, | ||
yOffset: Double, | ||
zOffset: Double, | ||
vararg arguments: Int | ||
) { | ||
for (worldAccess in worldAccesses) { | ||
val modX = x - (if (!MainConfig.settings.cleanerParticles) 0.5 + Math.random() else 0.0) | ||
val modY = y - (if (!MainConfig.settings.cleanerParticles) 0.5 + Math.random() else 0.0) | ||
val modZ = z - (if (!MainConfig.settings.cleanerParticles) 0.5 + Math.random() else 0.0) | ||
worldAccess.spawnParticle(particleID, ignoreRange, modX, modY, modZ, xOffset, yOffset, zOffset, *arguments) | ||
} | ||
} |