I got too carried away
This commit is contained in:
@@ -1,10 +1,70 @@
|
||||
package com.bytedice.bde_particles
|
||||
|
||||
import com.bytedice.bde_particles.commands.GiveParticleEmitter
|
||||
import com.bytedice.bde_particles.items.getToolDetails
|
||||
import com.bytedice.bde_particles.particle.Particle
|
||||
import com.bytedice.bde_particles.particle.returnParticleFunction
|
||||
import net.fabricmc.api.ModInitializer
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents
|
||||
import net.fabricmc.fabric.api.event.player.UseItemCallback
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.text.Text
|
||||
import net.minecraft.util.ActionResult
|
||||
import net.minecraft.util.Hand
|
||||
import net.minecraft.util.TypedActionResult
|
||||
|
||||
|
||||
// const val ALL_PARTICLE_EMITTERS: Array<> // ParticleEmitter
|
||||
|
||||
data class Config(
|
||||
val cooldown: Int = 1
|
||||
)
|
||||
|
||||
|
||||
val cfg = Config()
|
||||
|
||||
|
||||
class Bde_particles : ModInitializer {
|
||||
|
||||
override fun onInitialize() {
|
||||
|
||||
ServerTickEvents.START_SERVER_TICK.register { _ ->
|
||||
tick()
|
||||
}
|
||||
|
||||
CommandRegistrationCallback.EVENT.register { dispatcher, registryAccess, _ ->
|
||||
GiveParticleEmitter.register(dispatcher, registryAccess)
|
||||
}
|
||||
|
||||
UseItemCallback.EVENT.register(UseItemCallback { player: PlayerEntity, _, hand: Hand ->
|
||||
onRightClick(player, hand)
|
||||
})
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(ServerLifecycleEvents.ServerStarted { server: MinecraftServer ->
|
||||
|
||||
server.playerManager.broadcast(Text.of("BDAT - Loaded"), false)
|
||||
print("BDAT - Loaded")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun tick() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun onRightClick(player: PlayerEntity, hand: Hand) : TypedActionResult<ItemStack> {
|
||||
val handItem = player.getStackInHand(hand)
|
||||
val (isEmitterTool, particleId) = getToolDetails(handItem)
|
||||
|
||||
if (isEmitterTool) {
|
||||
val particleFunction = returnParticleFunction(particleId)
|
||||
if (particleFunction != null) { /* spawn particle with params */ }
|
||||
}
|
||||
|
||||
return TypedActionResult(ActionResult.PASS, handItem)
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.bytedice.bde_particles.commands
|
||||
|
||||
import com.bytedice.bde_particles.items.ParticleEmitter
|
||||
import com.bytedice.bde_particles.items.makeData
|
||||
import com.mojang.brigadier.Command
|
||||
import com.mojang.brigadier.CommandDispatcher
|
||||
import com.mojang.brigadier.arguments.StringArgumentType
|
||||
import net.minecraft.command.CommandRegistryAccess
|
||||
import net.minecraft.command.argument.ItemStackArgumentType
|
||||
import net.minecraft.item.Items
|
||||
import net.minecraft.server.command.CommandManager
|
||||
import net.minecraft.server.command.ServerCommandSource
|
||||
import net.minecraft.text.Style
|
||||
@@ -16,25 +15,32 @@ import java.awt.Color
|
||||
|
||||
object GiveParticleEmitter {
|
||||
fun register(dispatcher: CommandDispatcher<ServerCommandSource>, registryAccess: CommandRegistryAccess) {
|
||||
val command = CommandManager.literal("giveParticleEmitter")
|
||||
.requires { source -> source.hasPermissionLevel(2) }
|
||||
|
||||
val itemNameArg = CommandManager.argument("item name", StringArgumentType.string())
|
||||
val itemTypeArg = CommandManager.argument("item type", ItemStackArgumentType.itemStack(registryAccess))
|
||||
val particleIdArg = CommandManager.argument("particle id", StringArgumentType.string())
|
||||
|
||||
dispatcher.register(
|
||||
CommandManager.literal("giveParticleEmitter")
|
||||
.requires { source -> source.hasPermissionLevel(2) }
|
||||
.then(CommandManager.argument("item name", StringArgumentType.string()))
|
||||
.then(CommandManager.argument("item type", ItemStackArgumentType.itemStack(registryAccess)))
|
||||
.then(CommandManager.argument("particle id", StringArgumentType.string()))
|
||||
command.then(
|
||||
itemNameArg.then(
|
||||
itemTypeArg.then(
|
||||
particleIdArg.executes { context ->
|
||||
val name = StringArgumentType.getString(context, "item name")
|
||||
val item = ItemStackArgumentType.getItemStackArgument(context, "item type")
|
||||
val particleId = StringArgumentType.getString(context, "particle id")
|
||||
|
||||
.executes { context ->
|
||||
val name = StringArgumentType.getString(context, "item name")
|
||||
val item = Items.AMETHYST_SHARD // ItemStackArgumentType.getItemStackArgument(context, "item type")
|
||||
val particleId = StringArgumentType.getString(context, "particle id")
|
||||
val feedback = Text.literal("BPS - You like fancy particles. Don't you?\nBPS - [gave particle emitter, bound to id: \"${particleId}\"]")
|
||||
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 125, 0).rgb)).withItalic(true))
|
||||
|
||||
val feedback = Text.literal("BPS - You like fancy particles. Don't you?\nBPS - [gave particle emitter, bound to id: \"${context}\"]")
|
||||
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 125, 0).rgb)).withItalic(true))
|
||||
|
||||
context.source.player?.inventory?.insertStack(ParticleEmitter().makeData(item, name, particleId))
|
||||
context.source.sendFeedback({ feedback }, false)
|
||||
Command.SINGLE_SUCCESS
|
||||
}
|
||||
context.source.player?.inventory?.insertStack(makeData(item.item, name, particleId))
|
||||
context.source.sendFeedback({ feedback }, false)
|
||||
Command.SINGLE_SUCCESS
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.bytedice.bde_particles.items
|
||||
|
||||
import com.bytedice.bde_particles.math.raycastFromPlayer
|
||||
import net.minecraft.component.DataComponentTypes
|
||||
import net.minecraft.component.type.LoreComponent
|
||||
import net.minecraft.component.type.NbtComponent
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.server.network.ServerPlayerEntity
|
||||
import net.minecraft.text.Style
|
||||
import net.minecraft.text.Text
|
||||
import net.minecraft.text.TextColor
|
||||
import java.awt.Color
|
||||
|
||||
|
||||
class ParticleEmitter {
|
||||
fun makeData(itemId: Item, name: String, particleId: String): ItemStack {
|
||||
val i = ItemStack(itemId)
|
||||
|
||||
val nbt = NbtCompound()
|
||||
nbt.putByte("BPS_particleTool", 1)
|
||||
nbt.putString("BPS_particleId", particleId)
|
||||
|
||||
val component: NbtComponent = NbtComponent.of(nbt)
|
||||
|
||||
val displayName = Text.literal(name)
|
||||
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 125, 0).rgb)).withItalic(true))
|
||||
|
||||
val loreLines = Text.literal("BPS - Bound to id \"$particleId\"")
|
||||
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 125, 0).rgb)).withItalic(true))
|
||||
|
||||
val lore = LoreComponent(listOf(loreLines))
|
||||
|
||||
i.set(DataComponentTypes.ITEM_NAME, displayName)
|
||||
i.set(DataComponentTypes.CUSTOM_DATA, component)
|
||||
i.set(DataComponentTypes.LORE, lore)
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
fun onRightCLick(player: ServerPlayerEntity) {
|
||||
val hitResult = raycastFromPlayer(player, 4.5) ?: return
|
||||
|
||||
// spawn particle at hitResult
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.bytedice.bde_particles.items
|
||||
|
||||
import net.minecraft.component.DataComponentTypes
|
||||
import net.minecraft.component.type.LoreComponent
|
||||
import net.minecraft.component.type.NbtComponent
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.text.Style
|
||||
import net.minecraft.text.Text
|
||||
import net.minecraft.text.TextColor
|
||||
import java.awt.Color
|
||||
|
||||
|
||||
fun makeData(itemId: Item, name: String, particleId: String): ItemStack {
|
||||
val i = ItemStack(itemId)
|
||||
|
||||
val nbt = NbtCompound()
|
||||
nbt.putByte("BPS_particleTool", 1)
|
||||
nbt.putString("BPS_particleId", particleId)
|
||||
|
||||
val component: NbtComponent = NbtComponent.of(nbt)
|
||||
|
||||
val displayName = Text.literal(name)
|
||||
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 125, 0).rgb)).withItalic(true))
|
||||
|
||||
val loreLines = Text.literal("BPS - Bound to id \"$particleId\"")
|
||||
.setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 125, 0).rgb)).withItalic(true))
|
||||
|
||||
val lore = LoreComponent(listOf(loreLines))
|
||||
|
||||
i.set(DataComponentTypes.ITEM_NAME, displayName)
|
||||
i.set(DataComponentTypes.CUSTOM_DATA, component)
|
||||
i.set(DataComponentTypes.LORE, lore)
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
|
||||
fun getToolDetails(item: ItemStack) : Pair<Boolean, String> {
|
||||
val customData = item.get(DataComponentTypes.CUSTOM_DATA)
|
||||
val isParticleEmitterTool = customData?.nbt?.getByte("BPS_particleTool") == 1.toByte()
|
||||
val particleId = customData?.nbt?.getString("BPS_particleId")
|
||||
|
||||
if (particleId == null) { return Pair(isParticleEmitterTool, "") }
|
||||
|
||||
else { return Pair(isParticleEmitterTool, particleId) }
|
||||
}
|
||||
@@ -4,28 +4,12 @@ import net.minecraft.util.math.Vec3d
|
||||
import org.joml.Vector3f
|
||||
import org.joml.Vector4f
|
||||
|
||||
class Particle(
|
||||
// during init
|
||||
count: Int = 20,
|
||||
spawnDur: Int = 20,
|
||||
lifetime: Int = 20,
|
||||
offset: Vector3f = Vector3f(-0.5f, -0.5f, -0.5f),
|
||||
rotation: Vector3f = Vector3f(0.0f, 0.0f, 0.0f),
|
||||
//shape: Shape, // add later, start with single point
|
||||
|
||||
// during ticking
|
||||
// transformation
|
||||
forceFields: Array<Vector4f> = arrayOf(Vector4f(0.0f, 0.0f, 0.0f, 0.0f)), // x y z force
|
||||
rotVel: Vector3f = Vector3f(0.0f, 0.0f, 0.0f),
|
||||
sizeCurve: Array<Vector3f> = arrayOf(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(0.0f, 0.0f, 0.0f)),
|
||||
// physics
|
||||
gravity: Vec3d = Vec3d(0.0, -9.0, 0.0),
|
||||
drag: Float = 0.2f,
|
||||
minVel: Float = 0.003f,
|
||||
// rendering
|
||||
blockCurve: Array<String> = arrayOf("minecraft:black_concrete", "minecraft:green_concrete")
|
||||
) {
|
||||
class Particle(particleParams: ParticleParams) {
|
||||
fun init() {
|
||||
|
||||
}
|
||||
|
||||
fun registerEmitter(id: String, params: ParticleEmitterParams) {
|
||||
addToParticleRegister(id, params)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.bytedice.bde_particles.particle
|
||||
|
||||
class ParticleEmitterParams {
|
||||
data class init (
|
||||
val maxCount: Int = 20,
|
||||
val spawnDur: Int = 20,
|
||||
val particleTypes: Array<Particle> = emptyArray(),
|
||||
val loop: Boolean = false,
|
||||
val loopDelay: Int = 10,
|
||||
val loopCount: Int = 2,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.bytedice.bde_particles.particle
|
||||
|
||||
import net.minecraft.util.math.Vec3d
|
||||
import org.joml.Vector3f
|
||||
|
||||
data class ParticleParams (
|
||||
//val shape: Shape, // add later, start with single point
|
||||
val blockCurve: Array<String> = arrayOf("minecraft:black_concrete", "minecraft:green_concrete"),
|
||||
val rotVelRandom: Pair<Vector3f, Vector3f> = Pair(Vector3f(0.0f, 0.0f, 0.0f), Vector3f(360.0f, 360.0f, 360.0f)),
|
||||
val rotVelCurve: Array<Vector3f> = arrayOf(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(0.0f, 0.0f, 0.0f)),
|
||||
val sizeRandom: Pair<Vector3f, Vector3f> = Pair(Vector3f(0.5f, 0.5f, 0.5f), Vector3f(1.0f, 1.0f, 1.0f)),
|
||||
val sizeCurve: Array<Vector3f> = arrayOf(Vector3f(1.0f, 1.0f, 1.0f), Vector3f(0.0f, 0.0f, 0.0f)),
|
||||
val forceFields: ForceField = ForceField(),
|
||||
val gravity: Vec3d = Vec3d(0.0, -9.0, 0.0),
|
||||
val drag: Float = 0.2f,
|
||||
val minVel: Float = 0.003f
|
||||
)
|
||||
|
||||
|
||||
data class ForceField (
|
||||
val x: Float = 0.0f,
|
||||
val y: Float = 0.0f,
|
||||
val z: Float = 0.0f,
|
||||
val minForce: Float = 0.0f,
|
||||
val maxForce: Float = 0.0f,
|
||||
val radius: Float = -1.0f,
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.bytedice.bde_particles.particle
|
||||
|
||||
val particleIdRegister: MutableMap<String, ParticleEmitterParams> = mutableMapOf()
|
||||
|
||||
fun returnParticleFunction(id: String) : ParticleEmitterParams? {
|
||||
if (particleIdRegister.containsKey(id)) {
|
||||
return particleIdRegister[id]
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
fun addToParticleRegister(id: String, params: ParticleEmitterParams) {
|
||||
particleIdRegister[id] = params
|
||||
}
|
||||
Reference in New Issue
Block a user