tried adding config option to ManageEmitters
This commit is contained in:
@@ -18,6 +18,7 @@ import net.minecraft.util.ActionResult
|
|||||||
import net.minecraft.util.Hand
|
import net.minecraft.util.Hand
|
||||||
import net.minecraft.util.TypedActionResult
|
import net.minecraft.util.TypedActionResult
|
||||||
import net.minecraft.world.World
|
import net.minecraft.world.World
|
||||||
|
import org.joml.Vector3f
|
||||||
|
|
||||||
|
|
||||||
// TODO: finish the particle ticking
|
// TODO: finish the particle ticking
|
||||||
@@ -77,7 +78,7 @@ fun onRightClick(player: PlayerEntity, world: ServerWorld, hand: Hand) : TypedAc
|
|||||||
val handItem = player.getStackInHand(hand)
|
val handItem = player.getStackInHand(hand)
|
||||||
val (isEmitterTool, emitterId) = ParticleEmitterTool.getToolDetails(handItem)
|
val (isEmitterTool, emitterId) = ParticleEmitterTool.getToolDetails(handItem)
|
||||||
val hitResult = raycastFromPlayer(player as ServerPlayerEntity, 50.0)
|
val hitResult = raycastFromPlayer(player as ServerPlayerEntity, 50.0)
|
||||||
val emitterParams = getParticleEmitterParams(emitterId)
|
val emitterParams = getEmitterParams(emitterId)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!isEmitterTool
|
!isEmitterTool
|
||||||
@@ -94,7 +95,7 @@ fun onRightClick(player: PlayerEntity, world: ServerWorld, hand: Hand) : TypedAc
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun emitterParamsToJSON(params: ParticleEmitterParams) : Map<String, Any> {
|
fun emitterParamsToJson(params: ParticleEmitterParams) : Map<String, Any> {
|
||||||
val allParticleParamsJSON: MutableList<Map<String, Any?>> = mutableListOf()
|
val allParticleParamsJSON: MutableList<Map<String, Any?>> = mutableListOf()
|
||||||
|
|
||||||
for (particle in params.particleTypes) {
|
for (particle in params.particleTypes) {
|
||||||
@@ -129,3 +130,53 @@ fun emitterParamsToJSON(params: ParticleEmitterParams) : Map<String, Any> {
|
|||||||
|
|
||||||
return emitterParamsJSON
|
return emitterParamsJSON
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun jsonToEmitterParams(json: Map<String, Any>): ParticleEmitterParams {
|
||||||
|
val particleTypes = json["particleTypes"] as? List<*>
|
||||||
|
?: throw IllegalArgumentException("particleTypes must be a list of ParticleParams")
|
||||||
|
|
||||||
|
val allParticleTypes: MutableList<ParticleParams> = mutableListOf()
|
||||||
|
|
||||||
|
for (particle in particleTypes.iterator()) {
|
||||||
|
val particleParams = particle as? ParticleParams ?: ParticleParams.DEFAULT
|
||||||
|
|
||||||
|
val updatedParticle = ParticleParams(
|
||||||
|
shape = (particleParams.shape ?: ParticleParams.DEFAULT.shape),
|
||||||
|
blockCurve = (json["blockCurve"] as? Array<String>) ?: particleParams.blockCurve,
|
||||||
|
rotRandom = (json["rotRandom"] as? Pair<Vector3f, Vector3f>) ?: particleParams.rotRandom,
|
||||||
|
rotVelRandom = (json["rotVelRandom"] as? Pair<Vector3f, Vector3f>) ?: particleParams.rotVelRandom,
|
||||||
|
rotVelCurve = (json["rotVelCurve"] as? Array<Vector3f>) ?: particleParams.rotVelCurve,
|
||||||
|
sizeRandom = (json["sizeRandom"] as? Pair<Vector3f, Vector3f>) ?: particleParams.sizeRandom,
|
||||||
|
uniformSize = (json["uniformSize"] as? Boolean) ?: particleParams.uniformSize,
|
||||||
|
sizeCurve = (json["sizeCurve"] as? Array<Vector3f>) ?: particleParams.sizeCurve,
|
||||||
|
velRandom = (json["velRandom"] as? Pair<Vector3f, Vector3f>) ?: particleParams.velRandom,
|
||||||
|
forceFields = (json["forceFields"] as? Array<ForceField>) ?: particleParams.forceFields,
|
||||||
|
gravity = (json["gravity"] as? Vector3f) ?: particleParams.gravity,
|
||||||
|
drag = (json["drag"] as? Float) ?: particleParams.drag,
|
||||||
|
minVel = (json["minVel"] as? Float) ?: particleParams.minVel,
|
||||||
|
lifeTime = (json["lifeTime"] as? Pair<Int, Int>) ?: particleParams.lifeTime
|
||||||
|
)
|
||||||
|
|
||||||
|
allParticleTypes.add(updatedParticle)
|
||||||
|
}
|
||||||
|
|
||||||
|
val params = ParticleEmitterParams(
|
||||||
|
maxCount = (json["maxCount"] as? Int) ?: ParticleEmitterParams.DEFAULT.maxCount,
|
||||||
|
spawnsPerTick = (json["spawnsPerTick"] as? Int) ?: ParticleEmitterParams.DEFAULT.spawnsPerTick,
|
||||||
|
loopDur = (json["loopDur"] as? Int) ?: ParticleEmitterParams.DEFAULT.loopDur,
|
||||||
|
loopDelay = (json["loopDelay"] as? Int) ?: ParticleEmitterParams.DEFAULT.loopDelay,
|
||||||
|
loopCount = (json["loopCount"] as? Int) ?: ParticleEmitterParams.DEFAULT.loopCount,
|
||||||
|
particleTypes = allParticleTypes.toTypedArray()
|
||||||
|
)
|
||||||
|
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fun stringToMap(input: String): Map<String, String> {
|
||||||
|
return input.split(",")
|
||||||
|
.map { it.split("=") }
|
||||||
|
.associate { it[0].trim() to it[1].trim() }
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.bytedice.bde_particles.commands
|
package com.bytedice.bde_particles.commands
|
||||||
|
|
||||||
import com.bytedice.bde_particles.emitterParamsToJSON
|
import com.bytedice.bde_particles.emitterParamsToJson
|
||||||
|
import com.bytedice.bde_particles.jsonToEmitterParams
|
||||||
import com.bytedice.bde_particles.particle.*
|
import com.bytedice.bde_particles.particle.*
|
||||||
|
import com.bytedice.bde_particles.stringToMap
|
||||||
import com.mojang.brigadier.Command
|
import com.mojang.brigadier.Command
|
||||||
import com.mojang.brigadier.CommandDispatcher
|
import com.mojang.brigadier.CommandDispatcher
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType
|
import com.mojang.brigadier.arguments.StringArgumentType
|
||||||
@@ -34,12 +36,12 @@ import java.util.concurrent.CompletableFuture
|
|||||||
// [emitter id]
|
// [emitter id]
|
||||||
// output -> removes the particle with that id
|
// output -> removes the particle with that id
|
||||||
|
|
||||||
// config // TODO
|
// config
|
||||||
// [emitter id]
|
// [emitter id]
|
||||||
// <[particle index] / EMITTER>
|
// <[particle index] / EMITTER>
|
||||||
|
|
||||||
// <single param / JSON>
|
// <single param / JSON>
|
||||||
// single param (if EMITTER, use emitter params instead)
|
// single param (if EMITTER, use emitter params instead) // TODO
|
||||||
// [param key]
|
// [param key]
|
||||||
// [new param value]
|
// [new param value]
|
||||||
// output -> update the selected parameter of the selected emitter id to the new value
|
// output -> update the selected parameter of the selected emitter id to the new value
|
||||||
@@ -97,7 +99,7 @@ fun argCreate() : LiteralArgumentBuilder<ServerCommandSource> {
|
|||||||
.executes { context ->
|
.executes { context ->
|
||||||
val emitterIdVal = StringArgumentType.getString(context, "Emitter ID")
|
val emitterIdVal = StringArgumentType.getString(context, "Emitter ID")
|
||||||
val emitterPresetVal = StringArgumentType.getString(context, "Registered Emitter ID") ?: "DEFAULT"
|
val emitterPresetVal = StringArgumentType.getString(context, "Registered Emitter ID") ?: "DEFAULT"
|
||||||
val emitterPresetParams = getParticleEmitterParams(emitterPresetVal)
|
val emitterPresetParams = getEmitterParams(emitterPresetVal)
|
||||||
|
|
||||||
var newEmitterId = "NULL"
|
var newEmitterId = "NULL"
|
||||||
val emitterRegisterData: Pair<String, Boolean>
|
val emitterRegisterData: Pair<String, Boolean>
|
||||||
@@ -130,6 +132,7 @@ fun argCreate() : LiteralArgumentBuilder<ServerCommandSource> {
|
|||||||
fun argRemove() : LiteralArgumentBuilder<ServerCommandSource> {
|
fun argRemove() : LiteralArgumentBuilder<ServerCommandSource> {
|
||||||
return CommandManager.literal("remove")
|
return CommandManager.literal("remove")
|
||||||
.then(
|
.then(
|
||||||
|
// [emitter id]
|
||||||
emitterIdSuggestion
|
emitterIdSuggestion
|
||||||
.executes { context ->
|
.executes { context ->
|
||||||
val emitterIdVal = StringArgumentType.getString(context, "Registered Emitter ID") ?: "NULL"
|
val emitterIdVal = StringArgumentType.getString(context, "Registered Emitter ID") ?: "NULL"
|
||||||
@@ -152,13 +155,65 @@ fun argRemove() : LiteralArgumentBuilder<ServerCommandSource> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// config
|
||||||
|
// [emitter id]
|
||||||
|
// <[particle index] / EMITTER>
|
||||||
|
|
||||||
|
// <single param / JSON>
|
||||||
|
// single param (if EMITTER, use emitter params instead)
|
||||||
|
// [param key]
|
||||||
|
// [new param value]
|
||||||
|
// output -> update the selected parameter of the selected emitter id to the new value
|
||||||
|
|
||||||
|
// JSON
|
||||||
|
// [new params] (unspecified values is treated as current)
|
||||||
|
// output -> parse the JSON and update all params
|
||||||
|
|
||||||
|
|
||||||
fun argConfig() : LiteralArgumentBuilder<ServerCommandSource> {
|
fun argConfig() : LiteralArgumentBuilder<ServerCommandSource> {
|
||||||
return CommandManager.literal("config")
|
return CommandManager.literal("config")
|
||||||
|
.then(
|
||||||
|
// [emitter id]
|
||||||
|
emitterIdSuggestion
|
||||||
|
.then(
|
||||||
|
// <[particle index] / EMITTER>
|
||||||
|
makeIndexSuggestion()
|
||||||
|
// <single param / JSON>
|
||||||
|
//.then(argSingleParam())
|
||||||
|
.then(argJson())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
fun argSingleParam() {
|
||||||
|
CommandManager.literal("SingleParam")
|
||||||
|
.then(
|
||||||
|
// [param key]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
fun argJson() : LiteralArgumentBuilder<ServerCommandSource> {
|
||||||
|
return CommandManager.literal("JSON")
|
||||||
|
.then(
|
||||||
|
// [new params]
|
||||||
|
CommandManager.argument("JSON Value", StringArgumentType.string())
|
||||||
.executes { context ->
|
.executes { context ->
|
||||||
val feedback = Text.literal("remove")
|
val jsonString = StringArgumentType.getString(context, "JSON Value")
|
||||||
context.source.sendFeedback({ feedback }, false)
|
val jsonMap = stringToMap(jsonString)
|
||||||
|
val jsonParams = jsonToEmitterParams(jsonMap)
|
||||||
|
|
||||||
|
val emitterIdVal = StringArgumentType.getString(context, "Registered Emitter ID")
|
||||||
|
|
||||||
|
updateEmitterParams(emitterIdVal, jsonParams)
|
||||||
|
|
||||||
|
val feedback = Text.literal("BPS - Updated parameters of Emitter ID \"$emitterIdVal\"!\n")
|
||||||
|
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(200, 0, 0).rgb)))
|
||||||
|
|
||||||
Command.SINGLE_SUCCESS
|
Command.SINGLE_SUCCESS
|
||||||
}
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -184,12 +239,13 @@ fun argList() : LiteralArgumentBuilder<ServerCommandSource> {
|
|||||||
fun argCopy() : LiteralArgumentBuilder<ServerCommandSource> {
|
fun argCopy() : LiteralArgumentBuilder<ServerCommandSource> {
|
||||||
return CommandManager.literal("copy")
|
return CommandManager.literal("copy")
|
||||||
.then(
|
.then(
|
||||||
|
// [emitter id]
|
||||||
emitterIdSuggestion
|
emitterIdSuggestion
|
||||||
.executes { context ->
|
.executes { context ->
|
||||||
val emitterIdVal = StringArgumentType.getString(context, "Registered Emitter ID")
|
val emitterIdVal = StringArgumentType.getString(context, "Registered Emitter ID")
|
||||||
val commandBlock = makeCommandBlock(
|
val commandBlock = makeCommandBlock(
|
||||||
emitterParamsToJSON(
|
emitterParamsToJson(
|
||||||
getParticleEmitterParams(
|
getEmitterParams(
|
||||||
emitterIdVal
|
emitterIdVal
|
||||||
)!!
|
)!!
|
||||||
)
|
)
|
||||||
@@ -237,3 +293,60 @@ fun makeCommandBlock(emitterData: Map<String, Any>): ItemStack {
|
|||||||
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun makeIndexSuggestion() : RequiredArgumentBuilder<ServerCommandSource, String> {
|
||||||
|
return CommandManager.argument("Particle Index", StringArgumentType.string())
|
||||||
|
.suggests { context, builder ->
|
||||||
|
val emitterParams = getEmitterParams(StringArgumentType.getString(context, "Registered Emitter ID"))!!
|
||||||
|
val suggestionsBuilder = SuggestionsBuilder(builder.remaining, 0)
|
||||||
|
|
||||||
|
emitterParams.particleTypes.indices.forEach { i ->
|
||||||
|
suggestionsBuilder.suggest(i.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
suggestionsBuilder.suggest("EMITTER")
|
||||||
|
|
||||||
|
CompletableFuture.completedFuture(suggestionsBuilder.build())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
fun paramSuggestion(particleIndex: Int, emitterId: String) : RequiredArgumentBuilder<ServerCommandSource, String> {
|
||||||
|
val emitterParams = getParticleEmitterParams(emitterId)
|
||||||
|
|
||||||
|
val particleParams = if (emitterParams?.particleTypes!!.isNotEmpty()) {
|
||||||
|
emitterParams.particleTypes[particleIndex]
|
||||||
|
}
|
||||||
|
else { null }
|
||||||
|
|
||||||
|
val emitterProperties = emitterParams::class.memberProperties
|
||||||
|
val emitterPropertyNames: MutableList<String> = mutableListOf()
|
||||||
|
val emitterPropertyTypes: MutableList<KType> = mutableListOf()
|
||||||
|
|
||||||
|
var particleProperties: Collection<KProperty1<out ParticleParams, *>>? = null
|
||||||
|
|
||||||
|
if (particleParams != null) {
|
||||||
|
particleProperties = particleParams::class.memberProperties
|
||||||
|
}
|
||||||
|
|
||||||
|
if (particleIndex != -1) {
|
||||||
|
for (property in emitterProperties) {
|
||||||
|
emitterPropertyNames.add(property.name)
|
||||||
|
emitterPropertyTypes.add(property.returnType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (particleProperties != null) {
|
||||||
|
for (property in particleProperties) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return CommandManager.argument("Param Key", StringArgumentType.string())
|
||||||
|
.suggests { context, builder ->
|
||||||
|
val suggestionsBuilder = SuggestionsBuilder(builder.remaining, 0)
|
||||||
|
|
||||||
|
CompletableFuture.completedFuture(suggestionsBuilder.build())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -30,22 +30,7 @@ data class ParticleEmitterParams (
|
|||||||
25,
|
25,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
arrayOf(ParticleParams(
|
arrayOf(ParticleParams.FIRE_GEYSER)
|
||||||
null,
|
|
||||||
arrayOf("minecraft:shroomlight", "minecraft:orange_concrete", "minecraft:orange_stained_glass", "minecraft:gray_stained_glass", "minecraft:light_gray_stained_glass"),
|
|
||||||
Pair(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(360.0f, 360.0f, 360.0f)),
|
|
||||||
Pair(Vector3f(-0.2f, -0.2f, -0.2f), Vector3f(0.2f, 0.2f, 0.2f)),
|
|
||||||
arrayOf(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(0.0f, 0.0f, 0.0f)),
|
|
||||||
Pair(Vector3f(0.5f, 0.5f, 0.5f), Vector3f(1.0f, 1.0f, 1.0f)),
|
|
||||||
true,
|
|
||||||
arrayOf(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(0.5f, 0.5f, 0.5f)),
|
|
||||||
Pair(Vector3f(-0.1f, 0.4f, -0.1f), Vector3f(0.1f, 0.8f, 0.1f)),
|
|
||||||
emptyArray(),
|
|
||||||
Vector3f(0.0f, -0.01f, 0.0f),
|
|
||||||
0.075f,
|
|
||||||
0.0f,
|
|
||||||
Pair(15, 45)
|
|
||||||
))
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,4 +35,24 @@ data class ParticleParams (
|
|||||||
val drag: Float = 0.075f,
|
val drag: Float = 0.075f,
|
||||||
val minVel: Float = 0.0f,
|
val minVel: Float = 0.0f,
|
||||||
val lifeTime: Pair<Int, Int> = Pair(15, 45)
|
val lifeTime: Pair<Int, Int> = Pair(15, 45)
|
||||||
)
|
) {
|
||||||
|
companion object Presets {
|
||||||
|
val DEFAULT = ParticleParams()
|
||||||
|
val FIRE_GEYSER = ParticleParams(
|
||||||
|
null,
|
||||||
|
arrayOf("minecraft:shroomlight", "minecraft:orange_concrete", "minecraft:orange_stained_glass", "minecraft:gray_stained_glass", "minecraft:light_gray_stained_glass"),
|
||||||
|
Pair(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(360.0f, 360.0f, 360.0f)),
|
||||||
|
Pair(Vector3f(-0.2f, -0.2f, -0.2f), Vector3f(0.2f, 0.2f, 0.2f)),
|
||||||
|
arrayOf(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(0.0f, 0.0f, 0.0f)),
|
||||||
|
Pair(Vector3f(0.5f, 0.5f, 0.5f), Vector3f(1.0f, 1.0f, 1.0f)),
|
||||||
|
true,
|
||||||
|
arrayOf(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(0.5f, 0.5f, 0.5f)),
|
||||||
|
Pair(Vector3f(-0.1f, 0.4f, -0.1f), Vector3f(0.1f, 0.8f, 0.1f)),
|
||||||
|
emptyArray(),
|
||||||
|
Vector3f(0.0f, -0.01f, 0.0f),
|
||||||
|
0.075f,
|
||||||
|
0.0f,
|
||||||
|
Pair(15, 45)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,11 @@ fun removeFromEmitterRegister(id: String) : Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun getParticleEmitterParams(id: String) : ParticleEmitterParams? {
|
fun getEmitterParams(id: String) : ParticleEmitterParams? {
|
||||||
return emitterIdRegister[id]
|
return emitterIdRegister[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun updateEmitterParams(id: String, newParams: ParticleEmitterParams) {
|
||||||
|
emitterIdRegister[id] = newParams
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user