Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit cce0886

Browse files
committed
fix ItemStack and ItemStackList rule types
1 parent 1d32a56 commit cce0886

File tree

7 files changed

+61
-16
lines changed

7 files changed

+61
-16
lines changed

src/main/kotlin/io/github/dockyardmc/DockyardServer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class DockyardServer(configBuilder: Config.() -> Unit) {
135135
lateinit var versionInfo: Resources.DockyardVersionInfo
136136
lateinit var instance: DockyardServer
137137
val minecraftVersion = MinecraftVersions.v1_21_6
138-
var allowAnyVersion: Boolean = false
138+
var allowAnyVersion: Boolean = true
139139

140140
val scheduler = GlobalScheduler("main_scheduler")
141141

src/main/kotlin/io/github/dockyardmc/data/DataComponentPatch.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,22 @@ class DataComponentPatch(internal val components: Int2ObjectMap<DataComponent?>,
188188
}.getHashed()
189189
}
190190

191+
fun writeNoxesiumType(buffer: ByteBuf) {
192+
val components = this.components.filter { it.value != null }
193+
val emptyComponents = this.components.filter { it.value == null }
194+
195+
buffer.writeVarInt(components.size)
196+
buffer.writeVarInt(emptyComponents.size)
197+
198+
components.forEach { (key, value) ->
199+
buffer.writeString(DataComponentRegistry.getIdentifierById(key))
200+
value!!.write(buffer)
201+
}
202+
emptyComponents.forEach { (key, _) ->
203+
buffer.writeString(DataComponentRegistry.getIdentifierById(key))
204+
}
205+
}
206+
191207
override fun write(buffer: ByteBuf) {
192208
var added = 0
193209
components.values.forEach { component ->

src/main/kotlin/io/github/dockyardmc/data/DataComponentRegistry.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ object DataComponentRegistry {
1515
val dataComponentsByIdReversed = Object2IntOpenHashMap<KClass<out DataComponent>>()
1616
val dataComponentsByIdentifierReversed = Object2ObjectOpenHashMap<KClass<out DataComponent>, String>()
1717

18+
fun getIdentifierById(id: Int): String {
19+
return dataComponentsByIdentifierReversed.getValue(dataComponentsById.getValue(id))
20+
}
21+
1822
val CUSTOM_DATA = register("minecraft:custom_data", CustomDataComponent::class)
1923
val MAX_STACK_SIZE = register("minecraft:max_stack_size", MaxStackSizeComponent::class)
2024
val MAX_DAMAGE = register("minecraft:max_damage", MaxDamageComponent::class)

src/main/kotlin/io/github/dockyardmc/noxesium/Noxesium.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
package io.github.dockyardmc.noxesium
22

33
import com.noxcrew.noxesium.api.NoxesiumReferences
4-
import com.noxcrew.noxesium.api.protocol.ClientSettings
54
import cz.lukynka.prettylog.LogType
65
import cz.lukynka.prettylog.log
7-
import io.github.dockyardmc.events.EventPool
8-
import io.github.dockyardmc.events.Events
9-
import io.github.dockyardmc.events.PluginMessageReceivedEvent
10-
import io.github.dockyardmc.events.RegisterPluginChannelsEvent
6+
import io.github.dockyardmc.events.*
117
import io.github.dockyardmc.events.noxesium.NoxesiumClientInformationEvent
128
import io.github.dockyardmc.events.noxesium.NoxesiumClientSettingsEvent
139
import io.github.dockyardmc.events.noxesium.NoxesiumPacketReceiveEvent
14-
import io.github.dockyardmc.nbt.nbt
1510
import io.github.dockyardmc.noxesium.protocol.NoxesiumPacket
1611
import io.github.dockyardmc.noxesium.protocol.clientbound.*
1712
import io.github.dockyardmc.noxesium.protocol.serverbound.*
1813
import io.github.dockyardmc.noxesium.rules.NoxesiumEntityRuleContainer
1914
import io.github.dockyardmc.noxesium.rules.NoxesiumRuleContainer
2015
import io.github.dockyardmc.player.Player
16+
import io.github.dockyardmc.player.PlayerManager
2117
import io.github.dockyardmc.profiler.profiler
2218
import io.github.dockyardmc.protocol.packets.ProtocolState
2319
import io.github.dockyardmc.protocol.packets.play.clientbound.ClientboundPlayPluginMessagePacket
@@ -45,7 +41,6 @@ object Noxesium {
4541
val globalRuleContainer: NoxesiumRuleContainer = NoxesiumRuleContainer()
4642
val globalEntityRuleContainer: NoxesiumEntityRuleContainer = NoxesiumEntityRuleContainer()
4743

48-
private val settings: MutableMap<Player, ClientSettings> = mutableMapOf()
4944
private val waiting: MutableList<Player> = mutableListOf()
5045

5146
fun addPlayer(player: Player) {
@@ -111,7 +106,7 @@ object Noxesium {
111106

112107
eventPool.on<NoxesiumClientSettingsEvent> { event ->
113108
if (!_players.contains(event.player)) return@on
114-
settings[event.player] = event.clientSettings
109+
event.player.noxesiumIntegration.settings = event.clientSettings
115110
}
116111

117112
eventPool.on<RegisterPluginChannelsEvent> { event ->
@@ -123,6 +118,17 @@ object Noxesium {
123118
}
124119
}
125120

121+
eventPool.on<PlayerDisconnectEvent> { event ->
122+
val player = event.player
123+
this.globalEntityRuleContainer.removeEntity(player)
124+
this.globalEntityRuleContainer.removeViewer(player)
125+
this.globalRuleContainer.removeViewer(player)
126+
127+
PlayerManager.players.forEach { loopPlayer ->
128+
loopPlayer.noxesiumIntegration.entityRulesContainer.removeEntity(event.player)
129+
}
130+
}
131+
126132
}
127133
}
128134

src/main/kotlin/io/github/dockyardmc/noxesium/rules/NoxesiumRuleContainer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.dockyardmc.noxesium.rules
22

33
import com.noxcrew.noxesium.api.util.DebugOption
4+
import io.github.dockyardmc.item.ItemStack
45
import io.github.dockyardmc.noxesium.protocol.clientbound.ClientboundNoxesiumResetPacket
56
import io.github.dockyardmc.player.Player
67
import io.github.dockyardmc.utils.Disposable
@@ -54,9 +55,9 @@ class NoxesiumRuleContainer : Viewable(), Disposable {
5455
set(NoxesiumRules.Server.DISABLE_BOAT_COLLISION.createRule(value))
5556
}
5657

57-
// fun customCreativeItems(value: List<ItemStack>) {
58-
// rules.set(NoxesiumRules.Server.CUSTOM_CREATIVE_ITEMS.createRule(value))
59-
// }
58+
fun customCreativeItems(value: List<ItemStack>) {
59+
set(NoxesiumRules.Server.CUSTOM_CREATIVE_ITEMS.createRule(value))
60+
}
6061

6162
fun disableDefferedChunkUpdates(value: Boolean) {
6263
set(NoxesiumRules.Server.DISABLE_DEFFERED_CHUNK_UPDATES.createRule(value))
@@ -78,7 +79,6 @@ class NoxesiumRuleContainer : Viewable(), Disposable {
7879
set(NoxesiumRules.Server.RESTRICT_DEBUG_OPTIONS.createRule(value.map { it.keyCode }))
7980
}
8081

81-
@Suppress("UNCHECKED_CAST")
8282
private fun updateViewer(player: Player) {
8383
// Reset all server rules
8484
player.sendPacket(ClientboundNoxesiumResetPacket(0x01).getPluginMessagePacket())

src/main/kotlin/io/github/dockyardmc/noxesium/rules/NoxesiumRules.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package io.github.dockyardmc.noxesium.rules
33
import com.noxcrew.noxesium.api.protocol.rule.EntityRuleIndices
44
import com.noxcrew.noxesium.api.protocol.rule.ServerRuleIndices
55
import com.noxcrew.noxesium.api.qib.QibDefinition
6-
import io.github.dockyardmc.extentions.*
6+
import io.github.dockyardmc.extentions.asRGB
7+
import io.github.dockyardmc.extentions.writeString
8+
import io.github.dockyardmc.extentions.writeVarInt
79
import io.github.dockyardmc.item.ItemStack
810
import io.github.dockyardmc.protocol.types.writeList
911
import io.github.dockyardmc.protocol.types.writeMap
@@ -96,14 +98,29 @@ object NoxesiumRules {
9698
}
9799

98100
class ItemStackServerRule(index: Int, defaultV: ItemStack = ItemStack.AIR) : NoxesiumServerRule<ItemStack>(index, defaultV) {
101+
companion object {
102+
fun write(value: ItemStack, buffer: ByteBuf) {
103+
if (value.isEmpty()) {
104+
buffer.writeVarInt(0)
105+
} else {
106+
buffer.writeVarInt(1)
107+
buffer.writeString(value.material.identifier)
108+
value.components.writeNoxesiumType(buffer)
109+
}
110+
}
111+
}
112+
99113
override fun write(value: ItemStack, buffer: ByteBuf) {
100-
value.write(buffer)
114+
ItemStackServerRule.write(value, buffer)
101115
}
102116
}
103117

104118
class ItemStackListServerRule(index: Int, defaultV: List<ItemStack> = listOf()) : NoxesiumServerRule<List<ItemStack>>(index, defaultV) {
105119
override fun write(value: List<ItemStack>, buffer: ByteBuf) {
106-
buffer.writeList(value, ItemStack::write)
120+
buffer.writeVarInt(value.size)
121+
value.forEach { itemStack ->
122+
ItemStackServerRule.write(itemStack, buffer)
123+
}
107124
}
108125
}
109126

src/main/kotlin/io/github/dockyardmc/player/systems/NoxesiumIntegration.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.dockyardmc.player.systems
22

3+
import com.noxcrew.noxesium.api.protocol.ClientSettings
34
import cz.lukynka.bindables.Bindable
45
import io.github.dockyardmc.entity.Entity
56
import io.github.dockyardmc.noxesium.Noxesium
@@ -17,6 +18,7 @@ class NoxesiumIntegration(val player: Player) : PlayerSystem {
1718
val rulesContainer: NoxesiumRuleContainer = NoxesiumRuleContainer()
1819
val entityRulesContainer: NoxesiumEntityRuleContainer = NoxesiumEntityRuleContainer()
1920
val isUsingNoxesium: Bindable<Boolean> = player.bindablePool.provideBindable(false)
21+
var settings: ClientSettings? = null
2022

2123
private var scheduledActions: MutableList<() -> Unit> = mutableListOf()
2224

0 commit comments

Comments
 (0)