Skip to content

Commit

Permalink
ready for 1.0! Idc that it may be buggy, I want 1.0 now!
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteDice committed Dec 29, 2024
1 parent 46498d2 commit 2423efb
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 117 deletions.
4 changes: 4 additions & 0 deletions src/main/kotlin/com/bytedice/bde_particles/Bde_particles.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ import kotlin.reflect.full.declaredMemberProperties
// Copying particle params in-game.
// Custom curve equation command args (parse from strings).
// Force field "config" option.
// add rotation offset to transformWithVel

// TODO: (now)
// nothing lmao


var ALL_PARTICLE_EMITTERS: Array<ParticleEmitter> = emptyArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DisplayEntity(var properties: DisplayEntityProperties?) {
putString("billboard", properties.billboard)

if (properties.customName != null) {
putString("CustomName", properties.customName)
putString("CustomName", "{\"text\":\"${properties.customName}\"}")
putByte("CustomNameVisible", 1)
}

Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/com/bytedice/bde_particles/Math.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class LerpCurves(val function: (Float) -> Float) {

fun custom(equation: (Float) -> Float) = LerpCurves(equation)
}

fun deepCopy() : LerpCurves {
return LerpCurves(this.function)
}
}


Expand Down Expand Up @@ -72,12 +76,16 @@ fun raycastFromPlayer(player: ServerPlayerEntity, maxDistance: Double): HitResul


fun randomFloatBetween(min: Float, max: Float) : Float {
return Random.nextFloat() * (max - min) + min
return if (min == max) { max }
else if (min > max) { Random.nextFloat() * (min - max) + max }
else { Random.nextFloat() * (max - min) + min }
}


fun randomIntBetween(min: Int, max: Int) : Int {
return Random.nextInt(max - min) + min
return if (min == max) { max }
else if (min > max) { Random.nextInt(min - max) + max }
else { Random.nextInt(max - min) + min }
}


Expand Down
114 changes: 77 additions & 37 deletions src/main/kotlin/com/bytedice/bde_particles/commands/ConfigArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,25 @@ fun pairVec3fArg(access: KProperty1<EmitterParams,ParamClasses.PairVec3f>,
)
)
)
.then(CommandManager.literal("Constant")
.then(CommandManager.argument("X", FloatArgumentType.floatArg())
.then(CommandManager.argument("Y", FloatArgumentType.floatArg())
.then(CommandManager.argument("Z", FloatArgumentType.floatArg())
.executes { context ->
val id = StringArgumentType.getString(context, "Emitter ID")
val x = FloatArgumentType.getFloat(context, "X")
val y = FloatArgumentType.getFloat(context, "Y")
val z = FloatArgumentType.getFloat(context, "Z")

updateParam(id, access, ParamClasses.PairVec3f.Constant(Vector3f(x, y, z)))

successText(access, "Constant", id, context)
Command.SINGLE_SUCCESS
}
)
)
)
)
.then(CommandManager.literal("Null")
.executes { context ->
val id = StringArgumentType.getString(context, "Emitter ID")
Expand Down Expand Up @@ -430,12 +449,12 @@ fun transformWithVelArg(access: KProperty1<EmitterParams, ParamClasses.Transform
}
)
)
.then(CommandManager.literal("None")
.then(CommandManager.literal("Null")
.executes { context ->
val id = StringArgumentType.getString(context, "Emitter ID")

updateParam(id, access, ParamClasses.TransformWithVel.None)
successText(access, "None", id, context)
updateParam(id, access, ParamClasses.TransformWithVel.Null)
successText(access, "Null", id, context)
Command.SINGLE_SUCCESS
}
)
Expand All @@ -458,7 +477,7 @@ fun stringCurveArg(access: KProperty1<EmitterParams, ParamClasses.StringCurve>,
}
)
.executes { context ->
stringCurveAddArg(context, access, -1)
stringCurveAddArg(context, access, null)
Command.SINGLE_SUCCESS
}
)
Expand All @@ -472,7 +491,7 @@ fun stringCurveArg(access: KProperty1<EmitterParams, ParamClasses.StringCurve>,
}
)
.executes { context ->
stringCurveRemoveArg(context, access, -1)
stringCurveRemoveArg(context, access, null)
Command.SINGLE_SUCCESS
}
)
Expand All @@ -492,7 +511,6 @@ fun stringCurveArg(access: KProperty1<EmitterParams, ParamClasses.StringCurve>,
Command.SINGLE_SUCCESS
}
else {
println("$modelCurve, $curve, $curveName")
negativeFeedback("Failed to update param \"modelCurve.curve\"! The curve is invalid!", context)
Command.SINGLE_SUCCESS
}
Expand All @@ -505,20 +523,20 @@ fun stringCurveArg(access: KProperty1<EmitterParams, ParamClasses.StringCurve>,

fun stringCurveAddArg(context: CommandContext<ServerCommandSource>,
access: KProperty1<EmitterParams, ParamClasses.StringCurve>,
index: Int
index: Int?
) {
val id = StringArgumentType.getString(context, "Emitter ID")
val item = ItemStackArgumentType.getItemStackArgument(context, "Item").item
val itemId = Registries.ITEM.getId(item).toString()

val modelCurve = getEmitterDataById(id)?.modelCurve

if (index == -1 && modelCurve != null) {
if (index == null && modelCurve != null) {
modelCurve.array = modelCurve.array.toMutableList().apply { add(itemId) }.toTypedArray()
updateParam(id, access, modelCurve)
}
else if (modelCurve != null) {
modelCurve.array = modelCurve.array.toMutableList().apply { add(index.coerceIn(0, modelCurve.array.lastIndex), itemId) }.toTypedArray()
modelCurve.array = modelCurve.array.toMutableList().apply { add(index!!.coerceIn(0, modelCurve.array.lastIndex), itemId) }.toTypedArray()
updateParam(id, access, modelCurve)
}

Expand All @@ -527,21 +545,21 @@ fun stringCurveAddArg(context: CommandContext<ServerCommandSource>,

fun stringCurveRemoveArg(context: CommandContext<ServerCommandSource>,
access: KProperty1<EmitterParams, ParamClasses.StringCurve>,
index: Int
index: Int?
) {
val id = StringArgumentType.getString(context, "Emitter ID")

val modelCurve = getEmitterDataById(id)?.modelCurve

val item: String

if (index == -1 && modelCurve != null && modelCurve.array.isNotEmpty()) {
if (index == null && modelCurve != null && modelCurve.array.isNotEmpty()) {
item = modelCurve.array.last()
modelCurve.array = modelCurve.array.toMutableList().apply { removeLast() }.toTypedArray()
updateParam(id, access, modelCurve)
}
else if (modelCurve != null && modelCurve.array.isNotEmpty()) {
item = modelCurve.array[index.coerceIn(0, modelCurve.array.lastIndex)]
item = modelCurve.array[index!!.coerceIn(0, modelCurve.array.lastIndex)]
modelCurve.array = modelCurve.array.toMutableList().apply { removeAt(index.coerceIn(0, modelCurve.array.lastIndex)) }.toTypedArray()
updateParam(id, access, modelCurve)
}
Expand Down Expand Up @@ -698,8 +716,15 @@ fun forceFieldArg(access: KProperty1<EmitterParams,ParamClasses.ForceFieldArray>
.then(CommandManager.argument("Radius", FloatArgumentType.floatArg())
.then(CommandManager.argument("Min Force", FloatArgumentType.floatArg())
.then(CommandManager.argument("Max Force", FloatArgumentType.floatArg())
.then(CommandManager.argument("Index", IntegerArgumentType.integer())
.executes { context ->
val index = IntegerArgumentType.getInteger(context, "Index")
forceFieldAddArg(context, access, "Sphere", index)
Command.SINGLE_SUCCESS
}
)
.executes { context ->
forceFieldAddArg(context, access, "Sphere")
forceFieldAddArg(context, access, "Sphere", null)
Command.SINGLE_SUCCESS
}
)
Expand All @@ -710,15 +735,20 @@ fun forceFieldArg(access: KProperty1<EmitterParams,ParamClasses.ForceFieldArray>
.then(CommandManager.argument("Size X", FloatArgumentType.floatArg())
.then(CommandManager.argument("Size Y", FloatArgumentType.floatArg())
.then(CommandManager.argument("Size Z", FloatArgumentType.floatArg())
.then(CommandManager.argument("Dir X", FloatArgumentType.floatArg())
.then(CommandManager.argument("Dir Y", FloatArgumentType.floatArg())
.then(CommandManager.argument("Dir Z", FloatArgumentType.floatArg())
.then(CommandManager.argument("Force", FloatArgumentType.floatArg())
.then(CommandManager.argument("Force X", FloatArgumentType.floatArg())
.then(CommandManager.argument("Force Y", FloatArgumentType.floatArg())
.then(CommandManager.argument("Force Z", FloatArgumentType.floatArg())
.then(CommandManager.argument("Index", IntegerArgumentType.integer())
.executes { context ->
forceFieldAddArg(context, access, "Cube")
val index = IntegerArgumentType.getInteger(context, "Index")
forceFieldAddArg(context, access, "Cube", index)
Command.SINGLE_SUCCESS
}
)
.executes { context ->
forceFieldAddArg(context, access, "Cube", null)
Command.SINGLE_SUCCESS
}
)
)
)
Expand All @@ -742,15 +772,16 @@ fun forceFieldArg(access: KProperty1<EmitterParams,ParamClasses.ForceFieldArray>
}
)
.executes { context ->
forceFieldRemoveArg(context, access, -1)
forceFieldRemoveArg(context, access, null)
Command.SINGLE_SUCCESS
}
)
}

fun forceFieldAddArg(context: CommandContext<ServerCommandSource>,
access: KProperty1<EmitterParams, ParamClasses.ForceFieldArray>,
shape: String
shape: String,
index: Int?
) {
val id = StringArgumentType.getString(context, "Emitter ID")
val x = FloatArgumentType.getFloat(context, "X")
Expand All @@ -775,21 +806,29 @@ fun forceFieldAddArg(context: CommandContext<ServerCommandSource>,
val sizeX = FloatArgumentType.getFloat(context, "Size X")
val sizeY = FloatArgumentType.getFloat(context, "Size Y")
val sizeZ = FloatArgumentType.getFloat(context, "Size Z")
val dirX = FloatArgumentType.getFloat(context, "Dir X")
val dirY = FloatArgumentType.getFloat(context, "Dir Y")
val dirZ = FloatArgumentType.getFloat(context, "Dir Z")
val force = FloatArgumentType.getFloat(context, "Force")
val forceX = FloatArgumentType.getFloat(context, "Force X")
val forceY = FloatArgumentType.getFloat(context, "Force Y")
val forceZ = FloatArgumentType.getFloat(context, "Force Z")

forceField = ForceField(
Vector3f(x, y, z),
ForceFieldShape.Cube(Vector3f(sizeX, sizeY, sizeZ), Vector3f(dirX, dirY, dirZ), force)
ForceFieldShape.Cube(Vector3f(sizeX, sizeY, sizeZ), Vector3f(forceX, forceY, forceZ))
)
}

if (forceFields != null && forceField != null) {
forceFields.array = forceFields.array.toMutableList().apply { add(forceField) }.toTypedArray()
if (forceFields != null && forceField != null) {
if (index == null) {
forceFields.array = forceFields.array.toMutableList().apply { add(forceField) }.toTypedArray()
}
else {
val newIndex = index.coerceIn(0, forceFields.array.size)
forceFields.array = forceFields.array.toMutableList().apply { add(newIndex, forceField) }.toTypedArray()
}

val calcIndex = index?.coerceIn(0, forceFields.array.size)

updateParam(id, access, forceFields)
successText(access, "++ForceField", id, context)
successText(access, "++ForceField at $calcIndex", id, context)
}
else {
negativeFeedback("Failed to update param \"forceFields\"! The Emitter ID is most likely invalid!", context)
Expand All @@ -798,26 +837,27 @@ fun forceFieldAddArg(context: CommandContext<ServerCommandSource>,

fun forceFieldRemoveArg(context: CommandContext<ServerCommandSource>,
access: KProperty1<EmitterParams, ParamClasses.ForceFieldArray>,
index: Int
index: Int?
) {
val id = StringArgumentType.getString(context, "Emitter ID")

val forceFields = getEmitterDataById(id)?.forceFields

if (index == -1 && forceFields != null && forceFields.array.isNotEmpty()) {
if (index == null && forceFields != null && forceFields.array.isNotEmpty()) {
forceFields.array = forceFields.array.toMutableList().apply { removeLast() }.toTypedArray()
updateParam(id, access, forceFields)
}
else if (forceFields != null && forceFields.array.isNotEmpty()) {
forceFields.array = forceFields.array.toMutableList().apply { removeAt(index.coerceIn(0, forceFields.array.lastIndex)) }.toTypedArray()
val newIndex = index?.coerceIn(0, forceFields.array.lastIndex) ?: forceFields.array.lastIndex
forceFields.array = forceFields.array.toMutableList().apply { removeAt(newIndex) }.toTypedArray()
updateParam(id, access, forceFields)
}
else {
negativeFeedback("Couldn't remove ForceField. There are no ForceFields in the Emitter.", context)
return
}

val calcIndex = if (index == -1) { forceFields.array.size } else { index.coerceIn(0, forceFields.array.size) }
val calcIndex = index?.coerceIn(0, forceFields.array.size) ?: forceFields.array.size

successText(access, "--ForceField at $calcIndex", id, context)
}
Expand All @@ -828,18 +868,18 @@ fun lerpValIntArg(access: KProperty1<EmitterParams, ParamClasses.LerpValInt>,
{
return configArg
.then(CommandManager.literal("LerpInt")
.then(CommandManager.argument("Min", IntegerArgumentType.integer())
.then(CommandManager.argument("Max", IntegerArgumentType.integer())
.then(CommandManager.argument("From", IntegerArgumentType.integer())
.then(CommandManager.argument("To", IntegerArgumentType.integer())
.then(curveListArg("Curve")
.executes { context ->
val id = StringArgumentType.getString(context, "Emitter ID")
val min = IntegerArgumentType.getInteger(context, "Min")
val max = IntegerArgumentType.getInteger(context, "Max")
val from = IntegerArgumentType.getInteger(context, "From")
val to = IntegerArgumentType.getInteger(context, "To")
val curveName = StringArgumentType.getString(context, "Curve")

val curve = stringToCurve(curveName)

updateParam(id, access, ParamClasses.LerpValInt.LerpInt(min, max, curve!!))
updateParam(id, access, ParamClasses.LerpValInt.LerpInt(from, to, curve!!))

successText(access, "LerpInt", id, context)
Command.SINGLE_SUCCESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import com.bytedice.bde_particles.particles.idRegister
import com.mojang.brigadier.Command
import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.arguments.StringArgumentType
import com.mojang.brigadier.context.CommandContext
import net.minecraft.command.CommandRegistryAccess
import net.minecraft.command.argument.ItemStackArgumentType
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
import net.minecraft.server.command.CommandManager
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.text.Style
Expand All @@ -33,26 +37,42 @@ object GiveEmitterTool {
CompletableFuture.completedFuture(builder.build())
}

dispatcher.register(
command
.then(itemNameArg
.then(itemTypeArg
.then(emitterIdSuggestion
.executes { context ->
val name = StringArgumentType.getString(context, "Item Name")
val item = ItemStackArgumentType.getItemStackArgument(context, "Item Type")
val emitterId = StringArgumentType.getString(context, "Emitter ID")

val feedback = Text.literal("BPS - You like fancy particles. Don't you?\nBPS - gave particle emitter, bound to ID: \"${emitterId}\".")
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 200, 0).rgb)))

context.source.player?.inventory?.insertStack(ParticleEmitterTool.makeData(item.item, name, emitterId))
context.source.sendFeedback({ feedback }, false)
Command.SINGLE_SUCCESS
}
)
dispatcher.register(command
.then(emitterIdSuggestion
.then(itemTypeArg
.then(itemNameArg
.executes { context ->
val name = StringArgumentType.getString(context, "Item Name")
val item = ItemStackArgumentType.getItemStackArgument(context, "Item Type")
val emitterId = StringArgumentType.getString(context, "Emitter ID")

exec(context, emitterId, item.item, name)
Command.SINGLE_SUCCESS
}
)
.executes { context ->
val item = ItemStackArgumentType.getItemStackArgument(context, "Item Type")
val emitterId = StringArgumentType.getString(context, "Emitter ID")

exec(context, emitterId, item.item, emitterId)
Command.SINGLE_SUCCESS
}
)
.executes { context ->
val emitterId = StringArgumentType.getString(context, "Emitter ID")

exec(context, emitterId, Items.AMETHYST_SHARD, emitterId)
Command.SINGLE_SUCCESS
}
)
)
}

private fun exec(context: CommandContext<ServerCommandSource>, emitterId: String, itemType: Item, itemName: String) {
val feedback = Text.literal("BPS - You like fancy particles. Don't you?\nBPS - gave particle emitter, bound to ID: \"${emitterId}\".")
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 200, 0).rgb)))

context.source.player?.inventory?.insertStack(ParticleEmitterTool.makeData(itemType, itemName, emitterId))
context.source.sendFeedback({ feedback }, false)
}
}
Loading

0 comments on commit 2423efb

Please sign in to comment.