Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ application {
repositories {
mavenCentral()
maven("https://mvn.devos.one/releases")
maven("https://mvn.devos.one/snapshots")
maven("https://jitpack.io")
maven("https://repo.spongepowered.org/repository/maven-public/")
maven("https://repo.viaversion.com")
Expand Down Expand Up @@ -62,7 +63,6 @@ dependencies {

// Networking
api("io.ktor:ktor-server-netty:2.3.12")
api("io.ktor:ktor-network:2.3.12")

// Logging
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.11.1")
Expand All @@ -73,7 +73,7 @@ dependencies {
implementation("com.google.guava:guava:33.3.1-jre")
implementation("com.google.code.gson:gson:2.10.1")
api("it.unimi.dsi:fastutil:8.5.13")
api("cz.lukynka:kotlin-bindables:1.5")
api("cz.lukynka:kotlin-bindables:1.6")

api("io.github.dockyardmc:spark-api:1.12-SNAPSHOT")
api("io.github.dockyardmc:spark-common:1.12-SNAPSHOT")
Expand Down
58 changes: 58 additions & 0 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import io.github.dockyardmc.DockyardServer
import io.github.dockyardmc.attributes.AttributeOperation
import io.github.dockyardmc.commands.Commands
import io.github.dockyardmc.commands.IntArgument
import io.github.dockyardmc.commands.StringArgument
import io.github.dockyardmc.events.Events
import io.github.dockyardmc.events.PlayerJoinEvent
import io.github.dockyardmc.player.Player
import io.github.dockyardmc.player.systems.GameMode
import io.github.dockyardmc.registry.Attributes
import io.github.dockyardmc.registry.PotionEffects
import io.github.dockyardmc.registry.registries.PotionEffectRegistry

fun suggestPotionEffects(player: Player): List<String> {
return PotionEffectRegistry.potionEffects.keys.toList()
}

fun main() {
val server = DockyardServer {
withIp("0.0.0.0")
withPort(25565)
withUpdateChecker(false)
useDebugMode(true)
}

Events.on<PlayerJoinEvent> { event ->
val player = event.player
player.permissions.add("dockyard.admin")
player.permissions.add("dockyard.*")
player.gameMode.value = GameMode.CREATIVE
}

Commands.add("/test") {
addSubcommand("apply") {
addArgument("effect", StringArgument(), ::suggestPotionEffects)
addArgument("amplifier", IntArgument())
execute { ctx ->
val player = ctx.getPlayerOrThrow()
val effect = PotionEffectRegistry[getArgument("effect")]
player.addPotionEffect(effect, -1, getArgument("amplifier"))
}
}

addSubcommand("clear") {
execute { ctx ->
val player = ctx.getPlayerOrThrow()
player.clearPotionEffects()
}
}

execute { ctx ->
val player = ctx.getPlayerOrThrow()
player.attributes[Attributes.MOVEMENT_SPEED].addModifier("test", 0.2, AttributeOperation.ADD)
}
}

server.start()
}
103 changes: 57 additions & 46 deletions src/main/kotlin/io/github/dockyardmc/DockyardServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.github.dockyardmc.events.WorldFinishLoadingEvent
import io.github.dockyardmc.implementations.block.DefaultBlockHandlers
import io.github.dockyardmc.implementations.commands.DefaultCommands
import io.github.dockyardmc.npc.NpcCommand
import io.github.dockyardmc.profiler.profiler
import io.github.dockyardmc.protocol.NetworkCompression
import io.github.dockyardmc.protocol.packets.registry.ClientPacketRegistry
import io.github.dockyardmc.protocol.packets.registry.ServerPacketRegistry
Expand All @@ -18,8 +19,8 @@ import io.github.dockyardmc.registry.RegistryManager
import io.github.dockyardmc.registry.registries.*
import io.github.dockyardmc.registry.registries.tags.*
import io.github.dockyardmc.scheduler.GlobalScheduler
import io.github.dockyardmc.server.PlayerKeepAliveTimer
import io.github.dockyardmc.server.NettyServer
import io.github.dockyardmc.server.PlayerKeepAliveTimer
import io.github.dockyardmc.server.ServerTickManager
import io.github.dockyardmc.spark.SparkDockyardIntegration
import io.github.dockyardmc.utils.Resources
Expand All @@ -34,48 +35,56 @@ class DockyardServer(configBuilder: Config.() -> Unit) {
val playerKeepAliveTimer: PlayerKeepAliveTimer = PlayerKeepAliveTimer()

init {
instance = this
configBuilder.invoke(config)

ServerPacketRegistry.load()
ClientPacketRegistry.load()

SoundRegistry.initialize(RegistryManager.getStreamFromPath("registry/sound_registry.json.gz"))

RegistryManager.register(BlockRegistry)
RegistryManager.register(EntityTypeRegistry)
RegistryManager.register(DimensionTypeRegistry)
RegistryManager.register(WolfVariantRegistry)
RegistryManager.register(BannerPatternRegistry)
RegistryManager.register(DamageTypeRegistry)
RegistryManager.register(JukeboxSongRegistry)
RegistryManager.register(TrimMaterialRegistry)
RegistryManager.register(TrimPatternRegistry)
RegistryManager.register(ChatTypeRegistry)
RegistryManager.register(ParticleRegistry)
RegistryManager.register(PaintingVariantRegistry)
RegistryManager.register(PotionEffectRegistry)
RegistryManager.register(BiomeRegistry)
RegistryManager.register(ItemRegistry)
RegistryManager.register(FluidRegistry)

RegistryManager.register(ItemTagRegistry)
RegistryManager.register(BlockTagRegistry)
RegistryManager.register(EntityTypeTagRegistry)
RegistryManager.register(FluidTagRegistry)
RegistryManager.register(ItemTagRegistry)
RegistryManager.register(BiomeTagRegistry)

if(ConfigManager.config.implementationConfig.defaultCommands) DefaultCommands().register()
if(ConfigManager.config.implementationConfig.npcCommand) NpcCommand()
if(ConfigManager.config.implementationConfig.spark) SparkDockyardIntegration().initialize()
if(ConfigManager.config.implementationConfig.applyBlockPlacementRules) DefaultBlockHandlers().register()

NetworkCompression.compressionThreshold = ConfigManager.config.networkCompressionThreshold
WorldManager.loadDefaultWorld()

Events.dispatch(ServerFinishLoadEvent(this))
if(ConfigManager.config.updateChecker) UpdateChecker()
profiler("Server Load") {

instance = this
configBuilder.invoke(config)

profiler("Load Registries") {
ServerPacketRegistry.load()
ClientPacketRegistry.load()

SoundRegistry.initialize(RegistryManager.getStreamFromPath("registry/sound_registry.json.gz"))

RegistryManager.register(AttributeRegistry)
RegistryManager.register(BlockRegistry)
RegistryManager.register(EntityTypeRegistry)
RegistryManager.register(DimensionTypeRegistry)
RegistryManager.register(WolfVariantRegistry)
RegistryManager.register(BannerPatternRegistry)
RegistryManager.register(DamageTypeRegistry)
RegistryManager.register(JukeboxSongRegistry)
RegistryManager.register(TrimMaterialRegistry)
RegistryManager.register(TrimPatternRegistry)
RegistryManager.register(ChatTypeRegistry)
RegistryManager.register(ParticleRegistry)
RegistryManager.register(PaintingVariantRegistry)
RegistryManager.register(PotionEffectRegistry)
RegistryManager.register(BiomeRegistry)
RegistryManager.register(ItemRegistry)
RegistryManager.register(FluidRegistry)

RegistryManager.register(ItemTagRegistry)
RegistryManager.register(BlockTagRegistry)
RegistryManager.register(EntityTypeTagRegistry)
RegistryManager.register(FluidTagRegistry)
RegistryManager.register(ItemTagRegistry)
RegistryManager.register(BiomeTagRegistry)
}

profiler("Default Implementations") {
if (ConfigManager.config.implementationConfig.defaultCommands) DefaultCommands().register()
if (ConfigManager.config.implementationConfig.npcCommand) NpcCommand()
if (ConfigManager.config.implementationConfig.spark) SparkDockyardIntegration().initialize()
if (ConfigManager.config.implementationConfig.applyBlockPlacementRules) DefaultBlockHandlers().register()
}

NetworkCompression.compressionThreshold = ConfigManager.config.networkCompressionThreshold
WorldManager.loadDefaultWorld()

Events.dispatch(ServerFinishLoadEvent(this))
if (ConfigManager.config.updateChecker) UpdateChecker()
}
}

val ip get() = config.ip
Expand All @@ -86,9 +95,11 @@ class DockyardServer(configBuilder: Config.() -> Unit) {
log("Starting DockyardMC Version ${versionInfo.dockyardVersion} (${versionInfo.gitCommit}@${versionInfo.gitBranch} for MC ${minecraftVersion.versionName})", LogType.RUNTIME)
log("DockyardMC is still under heavy development. Things will break (I warned you)", LogType.WARNING)

serverTickManager.start()
playerKeepAliveTimer.start()
nettyServer.start()
profiler("Start TCP socket") {
serverTickManager.start()
playerKeepAliveTimer.start()
nettyServer.start()
}

Events.dispatch(WorldFinishLoadingEvent(WorldManager.mainWorld))
}
Expand Down
10 changes: 4 additions & 6 deletions src/main/kotlin/io/github/dockyardmc/attributes/Attribute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package io.github.dockyardmc.attributes

import io.github.dockyardmc.extentions.*
import io.github.dockyardmc.item.AttributeModifiersItemComponent
import io.github.dockyardmc.registry.registries.Attribute
import io.github.dockyardmc.registry.registries.AttributeRegistry
import io.netty.buffer.ByteBuf

data class Attribute(
val id: Int
)

enum class AttributeOperation {
ADD,
MULTIPLY_BASE,
Expand Down Expand Up @@ -45,14 +43,14 @@ data class Modifier(
val equipmentSlot: EquipmentSlotGroup
) {
fun write(buffer: ByteBuf) {
buffer.writeVarInt(attribute.id)
buffer.writeVarInt(attribute.getProtocolId())
attributeModifier.write(buffer)
buffer.writeVarIntEnum<EquipmentSlotGroup>(equipmentSlot)
}

companion object {
fun read(buffer: ByteBuf): Modifier {
val attribute = Attribute(buffer.readVarInt())
val attribute = AttributeRegistry.getByProtocolId(buffer.readVarInt())
val attributeModifier = AttributeModifier.read(buffer)
val slot = buffer.readVarIntEnum<EquipmentSlotGroup>()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.github.dockyardmc.attributes

import cz.lukynka.bindables.Bindable
import cz.lukynka.bindables.BindableMap
import cz.lukynka.bindables.BindablePool
import io.github.dockyardmc.player.Player
import io.github.dockyardmc.protocol.packets.play.clientbound.ClientboundUpdateAttributesPacket
import io.github.dockyardmc.registry.registries.Attribute
import io.github.dockyardmc.utils.Disposable

class AttributeInstance(val player: Player, val attribute: Attribute, private val bindablePool: BindablePool) : Disposable {
val base: Bindable<Double> = bindablePool.provideBindable(attribute.defaultValue)
private val modifiers: BindableMap<String, AttributeModifier> = bindablePool.provideBindableMap()

fun addModifier(id: String, amount: Double, operation: AttributeOperation) {
addModifier(AttributeModifier(id, amount, operation))
}

fun addModifier(modifier: AttributeModifier) {
modifiers[modifier.id] = modifier
}

fun removeModifier(id: String) {
modifiers.remove(id)
}

fun removeModifier(modifier: AttributeModifier) {
modifiers.remove(modifier.id)
}

init {
modifiers.mapUpdated {
sendUpdate()
}

base.valueChanged { event ->
sendUpdate()
}
}

private fun sendUpdate() {
val property = ClientboundUpdateAttributesPacket.Property(attribute, base.value, modifiers.values.values)
val packet = ClientboundUpdateAttributesPacket(player, listOf(property))

player.sendPacket(packet)
}

override fun dispose() {
bindablePool.dispose()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.dockyardmc.attributes

import cz.lukynka.bindables.BindablePool
import io.github.dockyardmc.player.Player
import io.github.dockyardmc.registry.Attributes
import io.github.dockyardmc.registry.registries.Attribute
import io.github.dockyardmc.utils.Disposable

class PlayerAttributes(val player: Player): Disposable {

private val bindablePool = BindablePool()
private val attributeMap: MutableMap<Attribute, AttributeInstance> = mutableMapOf()

operator fun get(attribute: Attribute): AttributeInstance {
if(!attributeMap.containsKey(attribute)) {
attributeMap[attribute] = AttributeInstance(player, attribute, bindablePool)
}
return attributeMap[attribute]!!
}

init {
setDefault(Attributes.ATTACK_DAMAGE, 1.0)
setDefault(Attributes.MOVEMENT_SPEED, 0.10000000149011612)
setDefault(Attributes.BLOCK_INTERACTION_RANGE, 4.5)
setDefault(Attributes.ENTITY_INTERACTION_RANGE, 3.0)
}

private fun setDefault(attribute: Attribute, default: Double) {
val bindable = get(attribute).base
bindable.value = default
bindable.defaultValue = default
}

override fun dispose() {
bindablePool.dispose()
attributeMap.clear()
}
}
Loading