Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.
Open
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
1 change: 1 addition & 0 deletions .idea/gradle.xml

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

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

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

13 changes: 0 additions & 13 deletions .idea/runConfigurations/MainKt.xml

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
`java-library`
}

val minecraftVersion = "1.21.8"
val minecraftVersion = "1.21.9"
val dockyardVersion = properties["dockyard.version"]!!
val gitBranch = "git rev-parse --abbrev-ref HEAD".runCommand()
val gitCommit = "git rev-parse --short=8 HEAD".runCommand()
Expand Down
28 changes: 28 additions & 0 deletions demo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
kotlin("jvm")
}

group = "io.github.dockyardmc.demo"
version = parent!!.version

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")
maven("https://maven.noxcrew.com/public")
}

dependencies {
testImplementation(kotlin("test"))
implementation(project(":"))
}

tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(21)
}
24 changes: 24 additions & 0 deletions demo/src/main/kotlin/io/github/dockyardmc/demo/Clanker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.dockyardmc.demo

import io.github.dockyardmc.entity.ai.EntityBehaviourCoordinator
import io.github.dockyardmc.entity.entities.CopperGolem
import io.github.dockyardmc.location.Location

class Clanker(location: Location) : CopperGolem(location) {

val brain = ClankerBehaviourCoordinator(this)

override fun tick() {
super.tick()
brain.tick()
}

}

class ClankerBehaviourCoordinator(entity: Clanker) : EntityBehaviourCoordinator(entity) {

init {
this.behaviours.add(EntityWalkAroundBehaviour(this))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.github.dockyardmc.demo

import io.github.dockyardmc.entity.Entity
import io.github.dockyardmc.entity.ai.EntityBehaviourCoordinator
import io.github.dockyardmc.entity.ai.EntityBehaviourNode
import io.github.dockyardmc.entity.ai.EntityBehaviourResult
import io.github.dockyardmc.pathfinding.PatheticPlatformDockyard.toPathPosition
import io.github.dockyardmc.pathfinding.PathfindingHelper
import io.github.dockyardmc.registry.Sounds
import io.github.dockyardmc.scheduler.runnables.ticks
import io.github.dockyardmc.sounds.Sound
import io.github.dockyardmc.utils.debug
import kotlin.random.Random

class EntityWalkAroundBehaviour(val coordinator: EntityBehaviourCoordinator) : EntityBehaviourNode() {

override val interruptible: Boolean = true
var failedTimes: Int = 0

override fun getScorer(entity: Entity): Float {
return 0.05f
}

override fun onStart(entity: Entity) {
var foundPath = false
this.cooldown = Random.nextInt(40, 80).ticks

coordinator.navigator.navigationCompleteDispatcher.subscribe {
getBehaviourFuture().complete(EntityBehaviourResult.SUCCESS)
}
coordinator.navigator.navigationNodeStepDispatcher.subscribe {
entity.playSoundToViewers(Sound(Sounds.ENTITY_COPPER_GOLEM_STEP))
}

entity.location.getBlocksInRadius(10).shuffled().forEach blockLoop@{ location ->
if (foundPath) {
return@blockLoop
}

if (!PathfindingHelper.isTraversable(location.block, location)) return@blockLoop
val start = entity.location.getBlockLocation().subtract(0, 1, 0).toPathPosition()
val end = location.toPathPosition()

coordinator.navigator.pathfinder.findPath(start, end, coordinator.navigator.filters).thenAccept { result ->
if (!result.successful()) {
return@thenAccept
}
if (foundPath) return@thenAccept

foundPath = true
coordinator.navigator.cancelNavigating()
coordinator.navigator.updatePathfindingPath(location)
}
}
}

override fun onBackstageTick(tick: Int) {
}

override fun onFrontstageTick(tick: Int) {
}

override fun onGeneralTick(tick: Int) {
}

override fun onStop(entity: Entity, interrupted: Boolean) {
coordinator.navigator.cancelNavigating()
coordinator.navigator.navigationNodeStepDispatcher.dispose()
coordinator.navigator.navigationCompleteDispatcher.dispose()
coordinator.navigator.pathfindResultDispatcher.dispose()
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kotlin.daemon.jvmargs=-Xmx3000m
dockyard.version=0.10.7
dockyard.version=0.10.8
kotlin.code.style=official
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
rootProject.name = "Dockyard"


include("demo")
6 changes: 3 additions & 3 deletions src/main/kotlin/io/github/dockyardmc/DockyardServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import io.github.dockyardmc.player.Player
import io.github.dockyardmc.player.PlayerManager
import io.github.dockyardmc.profiler.profiler
import io.github.dockyardmc.protocol.NetworkCompression
import io.github.dockyardmc.protocol.packets.configurations.Tag
import io.github.dockyardmc.protocol.packets.configurations.clientbound.Tag
import io.github.dockyardmc.protocol.packets.registry.ClientPacketRegistry
import io.github.dockyardmc.protocol.packets.registry.ServerPacketRegistry
import io.github.dockyardmc.provider.PlayerMessageProvider
Expand Down Expand Up @@ -45,6 +45,7 @@ class DockyardServer(configBuilder: Config.() -> Unit) {
profiler("Server Load") {

instance = this
versionInfo = Resources.getDockyardVersion()
configBuilder.invoke(config)

profiler("Register packets") {
Expand Down Expand Up @@ -123,7 +124,6 @@ class DockyardServer(configBuilder: Config.() -> Unit) {
val port get() = config.port

fun start() {
versionInfo = Resources.getDockyardVersion()
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)

Expand All @@ -139,7 +139,7 @@ class DockyardServer(configBuilder: Config.() -> Unit) {
companion object : PlayerMessageProvider, PlayerPacketProvider {
lateinit var versionInfo: Resources.DockyardVersionInfo
lateinit var instance: DockyardServer
val minecraftVersion = MinecraftVersions.v1_21_8
val minecraftVersion = MinecraftVersions.v1_21_9
var allowAnyVersion: Boolean = false

val scheduler = GlobalScheduler("main_scheduler")
Expand Down
12 changes: 3 additions & 9 deletions src/main/kotlin/io/github/dockyardmc/apis/Hologram.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import io.github.dockyardmc.entity.Entity
import io.github.dockyardmc.entity.EntityManager.despawnEntity
import io.github.dockyardmc.entity.EntityManager.spawnEntity
import io.github.dockyardmc.entity.TextDisplay
import io.github.dockyardmc.entity.metadata.EntityMetaValue
import io.github.dockyardmc.entity.metadata.EntityMetadata
import io.github.dockyardmc.entity.metadata.EntityMetadataType
import io.github.dockyardmc.entity.metadata.Metadata
import io.github.dockyardmc.location.Location
import io.github.dockyardmc.player.Player
import io.github.dockyardmc.player.toPersistent
import io.github.dockyardmc.registry.EntityTypes
import io.github.dockyardmc.registry.registries.EntityType
import io.github.dockyardmc.scroll.extensions.toComponent
Expand Down Expand Up @@ -141,7 +138,7 @@ class Hologram(spawnLocation: Location, builder: HologramBuilder) : Entity(spawn
entity.lineWidth.value = Int.MAX_VALUE
lineEntities.add(entity)
}
if (line !is PlayerContentLine && entity.metadataLayers.values.isNotEmpty()) entity.metadataLayers.clear()
if (line !is PlayerContentLine && entity.metadata.getMetadataLayers().values.isNotEmpty()) entity.metadata.clearMetadataLayers()

when (line) {
is StaticContentLine -> setGlobalLineContent(index, line.line)
Expand All @@ -156,10 +153,7 @@ class Hologram(spawnLocation: Location, builder: HologramBuilder) : Entity(spawn

private fun setPlayerLineContent(player: Player, lineIndex: Int, message: String) {
val display = lineEntities.getOrNull(lineIndex) ?: return

if (display.metadataLayers[player.toPersistent()] == null) display.metadataLayers[player.toPersistent()] = mutableMapOf()
val layer = display.metadataLayers[player.toPersistent()]!!
layer[EntityMetadataType.TEXT_DISPLAY_TEXT] = EntityMetadata(EntityMetadataType.TEXT_DISPLAY_TEXT, EntityMetaValue.TEXT_COMPONENT, message.toComponent())
display.metadata.setForPlayer(player, Metadata.TextDisplay.TEXT, message.toComponent())
display.sendMetadataPacket(player)
onLinesUpdated.dispatch(Unit)
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/io/github/dockyardmc/codec/ExtendedCodecs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.dockyardmc.codec

import io.github.dockyardmc.tide.codec.Codec
import io.github.dockyardmc.tide.stream.StreamCodec

fun <T> StreamCodec<T>.mutableList(): MutableListStreamCodec<T> {
return MutableListStreamCodec<T>(this)
}

fun <T> Codec<T>.mutableList(): MutableListCodec<T> {
return MutableListCodec<T>(this)
}
35 changes: 35 additions & 0 deletions src/main/kotlin/io/github/dockyardmc/codec/ExtraCodecs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.dockyardmc.codec

import io.github.dockyardmc.extentions.read
import io.github.dockyardmc.extentions.writeColor
import io.github.dockyardmc.scroll.CustomColor
import io.github.dockyardmc.tide.stream.StreamCodec
import io.netty.buffer.ByteBuf

object ExtraCodecs {
fun <T> fieldWriter(innerCodec: StreamCodec<T>): StreamCodec<T> {
return object : StreamCodec<T> {

override fun write(buffer: ByteBuf, value: T) {
innerCodec.write(buffer, value)
}

override fun read(buffer: ByteBuf): T {
return innerCodec.read(buffer)
}

}
}

val CUSTOM_COLOR_STREAM = object : StreamCodec<CustomColor> {

override fun write(buffer: ByteBuf, value: CustomColor) {
buffer.writeColor(value)
}

override fun read(buffer: ByteBuf): CustomColor {
return CustomColor.read(buffer)
}

}
}
24 changes: 24 additions & 0 deletions src/main/kotlin/io/github/dockyardmc/codec/MutableListCodec.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.dockyardmc.codec

import io.github.dockyardmc.tide.codec.Codec
import io.github.dockyardmc.tide.transcoder.Transcoder

class MutableListCodec<T>(val inner: Codec<T>) : Codec<MutableList<T>> {

override fun <D> encode(transcoder: Transcoder<D>, value: MutableList<T>): D {
val encodedList = transcoder.encodeList(value.size)
value.forEach { item ->
encodedList.add(inner.encode(transcoder, item))
}
return encodedList.build()
}

override fun <D> decode(transcoder: Transcoder<D>, value: D): MutableList<T> {
val listResult = transcoder.decodeList(value)
val decodedList = mutableListOf<T>()
listResult.forEach { item ->
decodedList.add(inner.decode(transcoder, item))
}
return decodedList
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.dockyardmc.codec

import io.github.dockyardmc.tide.stream.StreamCodec
import io.netty.buffer.ByteBuf

class MutableListStreamCodec<T>(val inner: StreamCodec<T>) : StreamCodec<MutableList<T>> {

override fun write(buffer: ByteBuf, value: MutableList<T>) {
StreamCodec.VAR_INT.write(buffer, value.size)
value.forEach { item ->
inner.write(buffer, item)
}
}

override fun read(buffer: ByteBuf): MutableList<T> {
val size = StreamCodec.VAR_INT.read(buffer)
val list = mutableListOf<T>()
for (i in 0 until size) {
list.add(inner.read(buffer))
}
return list
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.dockyardmc.data.components

import io.github.dockyardmc.data.DataComponent
import io.github.dockyardmc.entity.ParrotVariant
import io.github.dockyardmc.entity.Parrot
import io.github.dockyardmc.extentions.readEnum
import io.github.dockyardmc.extentions.writeEnum
import io.github.dockyardmc.protocol.NetworkReadable
import io.netty.buffer.ByteBuf

data class ParrotVariantComponent(val parrotColor: ParrotVariant) : DataComponent() {
data class ParrotVariantComponent(val parrotColor: Parrot.Variant) : DataComponent() {

override fun write(buffer: ByteBuf) {
buffer.writeEnum(parrotColor)
Expand Down
14 changes: 6 additions & 8 deletions src/main/kotlin/io/github/dockyardmc/entity/BlockDisplay.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package io.github.dockyardmc.entity

import cz.lukynka.bindables.Bindable
import io.github.dockyardmc.entity.metadata.EntityMetaValue
import io.github.dockyardmc.entity.metadata.EntityMetadata
import io.github.dockyardmc.entity.metadata.EntityMetadataType
import io.github.dockyardmc.entity.metadata.Metadata
import io.github.dockyardmc.location.Location
import io.github.dockyardmc.registry.Blocks
import io.github.dockyardmc.registry.EntityTypes
import io.github.dockyardmc.registry.registries.EntityType
import io.github.dockyardmc.world.block.Block

class BlockDisplay(location: Location): DisplayEntity(location) {
class BlockDisplay(location: Location) : DisplayEntity(location) {

override var type: EntityType = EntityTypes.BLOCK_DISPLAY
val block: Bindable<io.github.dockyardmc.world.block.Block> = Bindable(Blocks.STONE.toBlock())
val block: Bindable<Block> = bindablePool.provideBindable(Blocks.STONE.toBlock())

init {
block.valueChanged {
val type = EntityMetadataType.BLOCK_DISPLAY_BLOCK
metadata[type] = EntityMetadata(type, EntityMetaValue.BLOCK_STATE, it.newValue)
block.valueChanged { event ->
metadata[Metadata.BlockDisplay.DISPLAYED_BLOCK_STATE] = event.newValue
}
}
}
Loading
Loading