Skip to content

Commit bb0464b

Browse files
committed
Packets -> Kotlin
1 parent 4955f9e commit bb0464b

5 files changed

Lines changed: 92 additions & 93 deletions

File tree

src/main/java/org/visuals/legacy/animatium/packet/SetServerFeaturesPayloadPacket.java

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/main/kotlin/org/visuals/legacy/animatium/AnimatiumFabricClient.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class AnimatiumFabricClient : ClientModInitializer {
6161

6262
ClientCommandRegistrationCallback.EVENT.register { dispatcher, _ -> dispatcher.register(AnimatiumCommand.create()) }
6363

64-
AnimatiumKeybinds.register()
64+
AnimatiumKeybinds.bootstrap()
6565
AnimatiumParticles.bootstrap()
6666
this.registerPayloads()
6767
}
@@ -78,23 +78,23 @@ class AnimatiumFabricClient : ClientModInitializer {
7878
}
7979

8080
PayloadTypeRegistry.clientboundConfiguration()
81-
.register(SetServerFeaturesPayloadPacket.PAYLOAD_ID, SetServerFeaturesPayloadPacket.CODEC)
82-
ClientConfigurationNetworking.registerGlobalReceiver(SetServerFeaturesPayloadPacket.PAYLOAD_ID) { payload, context ->
81+
.register(SetServerFeaturesPayloadPacket.ID, SetServerFeaturesPayloadPacket.CODEC)
82+
ClientConfigurationNetworking.registerGlobalReceiver(SetServerFeaturesPayloadPacket.ID) { payload, context ->
8383
context.client().schedule {
8484
Animatium.ENABLED_SERVER_FEATURES.clear()
8585
Animatium.ENABLED_SERVER_FEATURES.addAll(payload.features())
8686
}
8787
}
8888

8989
PayloadTypeRegistry.clientboundPlay()
90-
.register(SetServerFeaturesPayloadPacket.PAYLOAD_ID, SetServerFeaturesPayloadPacket.CODEC)
91-
ClientPlayNetworking.registerGlobalReceiver(SetServerFeaturesPayloadPacket.PAYLOAD_ID) { payload, context ->
90+
.register(SetServerFeaturesPayloadPacket.ID, SetServerFeaturesPayloadPacket.CODEC)
91+
ClientPlayNetworking.registerGlobalReceiver(SetServerFeaturesPayloadPacket.ID) { payload, context ->
9292
context.client().schedule {
9393
Animatium.ENABLED_SERVER_FEATURES.clear()
9494
Animatium.ENABLED_SERVER_FEATURES.addAll(payload.features())
9595
}
9696
}
9797

98-
PayloadTypeRegistry.serverboundPlay().register(InfoPayloadPacket.PAYLOAD_ID, InfoPayloadPacket.CODEC)
98+
PayloadTypeRegistry.serverboundPlay().register(InfoPayloadPacket.ID, InfoPayloadPacket.CODEC)
9999
}
100100
}

src/main/kotlin/org/visuals/legacy/animatium/handler/AnimatiumKeybinds.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ object AnimatiumKeybinds {
4343
GLFW.GLFW_KEY_BACKSLASH
4444
) { client -> AnimatiumConfig.getConfigScreen(client.gui.screen()) }
4545

46-
fun register() {
46+
fun bootstrap() {
4747
ClientTickEvents.END_CLIENT_TICK.register { tick(it) }
4848
for (binding in REGISTRY) {
4949
KeyMappingHelper.registerKeyMapping(binding.mapping)
5050
}
5151
}
5252

53-
fun tick(minecraft: Minecraft) {
53+
private fun tick(minecraft: Minecraft) {
5454
for (binding in REGISTRY) {
5555
if (binding.mapping.consumeClick()) {
5656
minecraft.schedule {
@@ -60,7 +60,11 @@ object AnimatiumKeybinds {
6060
}
6161
}
6262

63-
private fun create(name: String, keybind: Int, onClick: Consumer<Minecraft>): KeyMapping {
63+
private fun create(
64+
name: String,
65+
keybind: Int,
66+
onClick: Consumer<Minecraft>
67+
): KeyMapping {
6468
val mapping = KeyMapping(name, keybind, ANIMATIUM_CATEGORY)
6569
REGISTRY.add(Binding(mapping, onClick))
6670
return mapping

src/main/java/org/visuals/legacy/animatium/packet/InfoPayloadPacket.java renamed to src/main/kotlin/org/visuals/legacy/animatium/packet/InfoPayloadPacket.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@
2323
* "MINECRAFT" LINKING EXCEPTION TO THE GPL
2424
*/
2525

26-
package org.visuals.legacy.animatium.packet;
26+
package org.visuals.legacy.animatium.packet
2727

28-
import net.minecraft.network.FriendlyByteBuf;
29-
import net.minecraft.network.codec.StreamCodec;
30-
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
31-
import org.jetbrains.annotations.NotNull;
32-
import org.jetbrains.annotations.Nullable;
33-
import org.visuals.legacy.animatium.Animatium;
28+
import net.minecraft.network.FriendlyByteBuf
29+
import net.minecraft.network.codec.StreamCodec
30+
import net.minecraft.network.protocol.common.custom.CustomPacketPayload
31+
import org.visuals.legacy.animatium.Animatium.location
32+
import java.util.*
3433

35-
import java.util.Optional;
34+
data class InfoPayloadPacket(val version: Double, val developmentVersion: String?) : CustomPacketPayload {
35+
companion object {
36+
val ID = CustomPacketPayload.Type<InfoPayloadPacket>(location("info"))
3637

37-
public record InfoPayloadPacket(double version, @Nullable String developmentVersion) implements CustomPacketPayload {
38-
public static final StreamCodec<FriendlyByteBuf, InfoPayloadPacket> CODEC = CustomPacketPayload.codec(InfoPayloadPacket::write, null);
39-
public static final CustomPacketPayload.Type<InfoPayloadPacket> PAYLOAD_ID = new CustomPacketPayload.Type<>(Animatium.location("info"));
38+
val CODEC: StreamCodec<FriendlyByteBuf, InfoPayloadPacket> =
39+
CustomPacketPayload.codec(InfoPayloadPacket::write, InfoPayloadPacket::read)
4040

41-
private void write(final FriendlyByteBuf buffer) {
42-
buffer.writeDouble(this.version);
43-
buffer.writeOptional(Optional.ofNullable(this.developmentVersion), FriendlyByteBuf::writeUtf);
41+
private fun read(buffer: FriendlyByteBuf): Nothing = throw UnsupportedOperationException()
4442
}
4543

46-
@Override
47-
public @NotNull Type<? extends CustomPacketPayload> type() {
48-
return PAYLOAD_ID;
44+
private fun write(buffer: FriendlyByteBuf) {
45+
buffer.writeDouble(this.version)
46+
buffer.writeOptional(Optional.ofNullable(this.developmentVersion), FriendlyByteBuf::writeUtf)
4947
}
50-
}
48+
49+
override fun type(): CustomPacketPayload.Type<out CustomPacketPayload> = ID
50+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Animatium
3+
* The all-you-could-want legacy animations mod for modern minecraft versions.
4+
* Brings back animations from the 1.7/1.8 era and more.
5+
* <p>
6+
* Copyright (C) 2024-2025 lowercasebtw
7+
* Copyright (C) 2024-2025 mixces
8+
* Copyright (C) 2024-2025 Contributors to the project retain their copyright
9+
* <p>
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
* <p>
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
* <p>
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
* <p>
23+
* "MINECRAFT" LINKING EXCEPTION TO THE GPL
24+
*/
25+
26+
package org.visuals.legacy.animatium.packet
27+
28+
import net.minecraft.network.FriendlyByteBuf
29+
import net.minecraft.network.codec.StreamCodec
30+
import net.minecraft.network.protocol.common.custom.CustomPacketPayload
31+
import org.visuals.legacy.animatium.Animatium.location
32+
import org.visuals.legacy.animatium.util.enums.ServerFeature
33+
import java.util.*
34+
35+
data class SetServerFeaturesPayloadPacket(val features: EnumSet<ServerFeature>) : CustomPacketPayload {
36+
companion object {
37+
val ID = CustomPacketPayload.Type<SetServerFeaturesPayloadPacket>(location("set_server_features"))
38+
39+
val CODEC: StreamCodec<FriendlyByteBuf, SetServerFeaturesPayloadPacket> =
40+
CustomPacketPayload.codec(SetServerFeaturesPayloadPacket::write, SetServerFeaturesPayloadPacket::read)
41+
42+
private fun read(buffer: FriendlyByteBuf): SetServerFeaturesPayloadPacket {
43+
val bytes = ByteArray(buffer.readableBytes())
44+
buffer.readBytes(bytes)
45+
46+
val bitSet = BitSet.valueOf(bytes)
47+
val features = EnumSet.noneOf(ServerFeature::class.java)
48+
for (index in 0..<ServerFeature.VALUES.size) {
49+
if (bitSet.get(index)) {
50+
features.add(ServerFeature.byId(index) ?: continue)
51+
}
52+
}
53+
54+
return SetServerFeaturesPayloadPacket(features)
55+
}
56+
}
57+
58+
private fun write(buffer: FriendlyByteBuf): Nothing = throw UnsupportedOperationException()
59+
60+
override fun type(): CustomPacketPayload.Type<out CustomPacketPayload> = ID
61+
}

0 commit comments

Comments
 (0)