"first" commit

This commit is contained in:
2024-11-13 19:35:46 +01:00
parent 90e1cd360f
commit 960672d712
16 changed files with 421 additions and 0 deletions
@@ -0,0 +1,10 @@
package com.bytedice.bde_particles
import net.fabricmc.api.ModInitializer
class Bde_particles : ModInitializer {
override fun onInitialize() {
}
}
@@ -0,0 +1,65 @@
package com.bytedice.bde_particles
import net.minecraft.entity.EntityType
import net.minecraft.entity.decoration.DisplayEntity.BlockDisplayEntity
import net.minecraft.nbt.NbtCompound
import net.minecraft.nbt.NbtFloat
import net.minecraft.nbt.NbtList
import net.minecraft.server.world.ServerWorld
class DisplayEntity(val properties: DisplayEntityProperties?) {
private var hasSpawned = false
fun spawn(world: ServerWorld) : BlockDisplayEntity? {
if (this.hasSpawned || properties == null) { return null }
val e = updateProperties(world, this.properties)
world.spawnEntity(e)
this.hasSpawned = true
return e
}
fun updateProperties(world: ServerWorld, properties: DisplayEntityProperties) : BlockDisplayEntity {
val e = BlockDisplayEntity(EntityType.BLOCK_DISPLAY, world)
val nbt = NbtCompound().apply {
putString("Name", properties.blockType)
put("transformation", NbtCompound().apply {
val offsetList = NbtList().apply {
add(NbtFloat.of(properties.translation.x))
add(NbtFloat.of(properties.translation.y))
add(NbtFloat.of(properties.translation.z))
}
val rotList = NbtList().apply {
add(NbtFloat.of(properties.leftRotation.x))
add(NbtFloat.of(properties.leftRotation.y))
add(NbtFloat.of(properties.leftRotation.z))
add(NbtFloat.of(properties.leftRotation.w))
}
val scaleList = NbtList().apply {
add(NbtFloat.of(properties.scale.x))
add(NbtFloat.of(properties.scale.y))
add(NbtFloat.of(properties.scale.z))
}
val rightRotList = NbtList().apply {
add(NbtFloat.of(properties.rightRotation.x))
add(NbtFloat.of(properties.rightRotation.y))
add(NbtFloat.of(properties.rightRotation.z))
add(NbtFloat.of(properties.rightRotation.w))
}
put("translation", offsetList)
put("left_rotation", rotList)
put("scale", scaleList)
put("right_rotation", rightRotList)
})
}
e.readNbt(nbt)
e.refreshPositionAndAngles(properties.pos.x, properties.pos.y, properties.pos.z, properties.rot.x, properties.rot.y)
return e
}
}
@@ -0,0 +1,18 @@
package com.bytedice.bde_particles
import net.minecraft.util.math.Vec3d
import org.joml.Vector2f
import org.joml.Vector3f
import org.joml.Vector4f
data class DisplayEntityProperties (
val pos: Vec3d = Vec3d(0.0, 0.0, 0.0),
val rot: Vector2f = Vector2f(0.0f, 0.0f),
val blockType: String = "minecraft:purple_concrete",
val translation: Vector3f = Vector3f(-0.5f, -0.5f, -0.5f),
val leftRotation: Vector4f = Vector4f(0.0f, 0.0f, 0.0f, 1.0f),
val scale: Vector3f = Vector3f(1.0f, 1.0f, 1.0f),
val rightRotation: Vector4f = Vector4f(0.0f, 0.0f, 0.0f, 1.0f)
)
@@ -0,0 +1,28 @@
package com.bytedice.bde_particles.commands
import com.bytedice.bde_particles.items.ParticleEmitter
import com.mojang.brigadier.Command
import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.arguments.StringArgumentType
import net.minecraft.command.argument.ItemStackArgumentType
import net.minecraft.server.command.CommandManager
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.text.Text
object GiveParticleEmitter {
fun register(dispatcher: CommandDispatcher<ServerCommandSource>) {
dispatcher.register(
CommandManager.literal("giveParticleEmitter")
.requires { source -> source.hasPermissionLevel(2) }
.then(CommandManager.argument("item name", StringArgumentType.string()))
.then(CommandManager.argument("item type", ItemStackArgumentType.itemStack()))) // error here
.then(CommandManager.argument("particle id", StringArgumentType.string()))
.executes { context ->
context.source.player?.inventory?.insertStack(ParticleEmitter().makeData()) // error here
context.source.sendFeedback({ Text.literal("Gave you 500Kg bomb. Don\'t get too silly with it :3") }, false)
Command.SINGLE_SUCCESS
}
)
}
}
@@ -0,0 +1,49 @@
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 = listOf(
Text.literal("BPS").setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 125, 0).rgb)).withItalic(true)),
Text.literal("Bound to id \"$particleId\"").setStyle(Style.EMPTY.withColor(TextColor.fromRgb(Color(0, 125, 0).rgb)).withItalic(true))
)
val lore = LoreComponent(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,31 @@
package com.bytedice.bde_particles.math
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.util.hit.HitResult
import net.minecraft.util.math.Vec3d
import net.minecraft.world.RaycastContext
import net.minecraft.world.World
fun raycastFromPlayer(player: ServerPlayerEntity, maxDistance: Double): HitResult? {
val world: World = player.world
val eyePos: Vec3d = player.getCameraPosVec(1.0f)
val lookVec: Vec3d = player.getRotationVec(1.0f)
val targetPos: Vec3d = eyePos.add(lookVec.multiply(maxDistance))
val blockHitResult = world.raycast(
RaycastContext(
eyePos,
targetPos,
RaycastContext.ShapeType.OUTLINE,
RaycastContext.FluidHandling.NONE,
player
)
)
return if (blockHitResult.type == HitResult.Type.BLOCK) {
blockHitResult
} else {
null
}
}
@@ -0,0 +1,31 @@
package com.bytedice.bde_particles.particle
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")
) {
fun init() {
}
}
@@ -0,0 +1,5 @@
package com.bytedice.bde_particles.particle
class Shape {
}
@@ -0,0 +1,11 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.bytedice.bde_particles.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
],
"injectors": {
"defaultRequire": 1
}
}
+30
View File
@@ -0,0 +1,30 @@
{
"schemaVersion": 1,
"id": "bde_particles",
"version": "${version}",
"name": "BDE Particle System",
"description": "A server-side particle system ",
"authors": [],
"contact": {},
"license": "All-Rights-Reserved",
"icon": "assets/bde_particles/icon.png",
"environment": "server",
"entrypoints": {
"main": [
"com.bytedice.bde_particles.Bde_particles"
]
},
"mixins": [
"bde_particles.mixins.json",
{
"config": "bde_particles.client.mixins.json",
"environment": "client"
}
],
"depends": {
"fabricloader": ">=${loader_version}",
"fabric-language-kotlin": ">=${kotlin_loader_version}",
"fabric": "*",
"minecraft": "${minecraft_version}"
}
}