Skip to content

Commit

Permalink
Update to Minecraft 1.21 and Kotlin 2.0 (#56)
Browse files Browse the repository at this point in the history
* Update to Minecraft 1.21-rc1 and Kotlin 2.0

* repo: Update to 1.21 release version

* core: Deprecate `serverPath` in favor of `serverDirectory`

---------

Co-authored-by: Jakob K <[email protected]>
  • Loading branch information
MushroomMif and jakobkmar authored Jun 16, 2024
1 parent a8ca3f6 commit 403b84d
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Gradle
.gradle/
build/
.kotlin/

# Editors (add yours if applicable)
.idea/
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {

allprojects {
group = "net.silkmc"
version = "1.10.6"
version = "1.10.7"
if (this.name.startsWith("silk")) {
description = "Silk is a Minecraft API for Kotlin"
}
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {
dependencies {
fun pluginDep(id: String, version: String) = "${id}:${id}.gradle.plugin:${version}"

val kotlinVersion = "1.9.23"
val kotlinVersion = "2.0.0"

compileOnly(kotlin("gradle-plugin", embeddedKotlinVersion))
runtimeOnly(kotlin("gradle-plugin", kotlinVersion))
Expand All @@ -24,8 +24,8 @@ dependencies {
implementation(pluginDep("fabric-loom", "1.6-SNAPSHOT"))
implementation(pluginDep("com.modrinth.minotaur", "2.8.7"))

implementation(pluginDep("io.papermc.paperweight.userdev", "1.5.11"))
implementation(pluginDep("xyz.jpenilla.run-paper", "2.2.3"))
implementation(pluginDep("io.papermc.paperweight.userdev", "1.7.1"))
implementation(pluginDep("xyz.jpenilla.run-paper", "2.3.0"))

val compileDokkaVersion = "1.9.20"
val dokkaVersion = "1.9.20"
Expand Down
10 changes: 5 additions & 5 deletions buildSrc/src/main/kotlin/BuildConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ object BuildConstants {

val authors = listOf("jakobkmar", "_F0X")

const val majorMinecraftVersion = "1.20"
const val majorMinecraftVersion = "1.21"

// check these values here: https://jakobk.net/mcdev
const val minecraftVersion = "1.20.6"
const val minecraftVersion = "1.21"
const val fabricLoaderVersion = "0.15.11"
const val fabricLanguageKotlinVersion = "1.10.19+kotlin.1.9.23"
const val fabricLanguageKotlinVersion = "1.11.0+kotlin.2.0.0"

const val kotestVersion = "5.8.1"
const val mockkVersion = "1.13.10"
const val kotestVersion = "5.9.1"
const val mockkVersion = "1.13.11"

val uploadModules = listOf(
"commands",
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.silkmc.silk.core.mixin.server;

import com.mojang.authlib.GameProfile;
import net.minecraft.network.chat.Component;
import net.minecraft.network.DisconnectionDetails;
import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
import net.silkmc.silk.core.event.PlayerEvents;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -19,9 +19,9 @@ public abstract class MixinServerConfigurationPacketListenerImpl {
method = "onDisconnect",
at = @At("HEAD")
)
private void onQuitDuringConfiguration(Component reason,
private void onQuitDuringConfiguration(DisconnectionDetails disconnectionDetails,
CallbackInfo ci) {
PlayerEvents.INSTANCE.getQuitDuringConfiguration()
.invoke(new PlayerEvents.PlayerQuitDuringLoginEvent(playerProfile(), reason));
.invoke(new PlayerEvents.PlayerQuitDuringLoginEvent(playerProfile(), disconnectionDetails.reason()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.silkmc.silk.core.mixin.server;

import net.minecraft.network.chat.Component;
import net.minecraft.network.DisconnectionDetails;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.silkmc.silk.core.event.PlayerEvents;
Expand All @@ -19,9 +19,9 @@ public abstract class MixinServerGamePacketListenerImpl {
method = "onDisconnect",
at = @At("HEAD")
)
private void onPreQuit(Component reason,
private void onPreQuit(DisconnectionDetails disconnectionDetails,
CallbackInfo ci) {
PlayerEvents.INSTANCE.getPreQuit()
.invoke(new PlayerEvents.PlayerQuitEvent(player, reason));
.invoke(new PlayerEvents.PlayerQuitEvent(player, disconnectionDetails.reason()));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.silkmc.silk.core.mixin.server;

import com.mojang.authlib.GameProfile;
import net.minecraft.network.chat.Component;
import net.minecraft.network.DisconnectionDetails;
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
import net.silkmc.silk.core.event.PlayerEvents;
import org.jetbrains.annotations.Nullable;
Expand All @@ -20,9 +20,9 @@ public abstract class MixinServerLoginPacketListenerImpl {
method = "onDisconnect",
at = @At("HEAD")
)
private void onQuitDuringLogin(Component reason,
private void onQuitDuringLogin(DisconnectionDetails disconnectionDetails,
CallbackInfo ci) {
PlayerEvents.INSTANCE.getQuitDuringLogin()
.invoke(new PlayerEvents.PlayerQuitDuringLoginEvent(authenticatedProfile, reason));
.invoke(new PlayerEvents.PlayerQuitDuringLoginEvent(authenticatedProfile, disconnectionDetails.reason()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import net.minecraft.server.level.ServerLevel
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.level.portal.DimensionTransition
import net.minecraft.world.phys.Vec3

/**
Expand All @@ -29,7 +30,11 @@ fun Entity.changePos(
}

if (world != null && world != this.level()) {
changeDimension(world)
changeDimension(DimensionTransition(
world, Vec3(xD, yD, zD), Vec3.ZERO, yaw ?: this.yRot,
pitch ?: this.xRot, false, DimensionTransition.DO_NOTHING
))
return
}

if (yaw != null) this.yRot = yaw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ typealias IdentifierSerializer = ResourceLocationSerializer

class ResourceLocationSerializer : SilkSerializer<ResourceLocation>() {
override fun deserialize(decoder: Decoder): ResourceLocation {
val split = decoder.decodeString().split(':')
return ResourceLocation(split[0], split[1])
return ResourceLocation.bySeparator(decoder.decodeString(), ':')
}

override fun serialize(encoder: Encoder, value: ResourceLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ val MinecraftServer.players: List<ServerPlayer>
* Returns the current run directory of the server as an
* absolute [Path].
*/
@Deprecated(
message = "Minecraft now offers a 'serverDirectory' property, use that instead.",
replaceWith = ReplaceWith("serverDirectory.absolute()", "kotlin.io.path.absolute"),
)
val MinecraftServer.serverPath: Path
get() = serverDirectory.toPath().absolute()
get() = serverDirectory.absolute()
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,9 @@ class SideboardScoreboard(
}

suspend fun addLine(initialContent: Component): Line {
val line: Line
lines.access {
return lines.access {
val index = it.lastIndex + 1
line = Line(index, initialContent)
it.add(line)
Line(index, initialContent).apply { it.add(this) }
}
return line
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sealed class AbstractPacketDefinition<T : Any, C>(
protected val receiverScope = CoroutineScope(Dispatchers.Default.limitedParallelism(1))

@InternalSilkApi
val type: CustomPacketPayload.Type<SilkPacketPayload> = CustomPacketPayload.createType(id.toString())
val type: CustomPacketPayload.Type<SilkPacketPayload> = CustomPacketPayload.Type(id)

@InternalSilkApi
val streamCodec: StreamCodec<FriendlyByteBuf, SilkPacketPayload> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ProtoChunk;
import net.minecraft.world.level.chunk.storage.ChunkSerializer;
import net.minecraft.world.level.chunk.storage.RegionStorageInfo;
import net.silkmc.silk.persistence.CompoundProvider;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -27,6 +28,7 @@ private static void onSerialize(ServerLevel world,
@Inject(method = "read", at = @At("RETURN"))
private static void onDeserialize(ServerLevel world,
PoiManager poiStorage,
RegionStorageInfo regionStorageInfo,
ChunkPos pos,
CompoundTag nbt,
CallbackInfoReturnable<ProtoChunk> cir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package net.silkmc.silk.test
import net.minecraft.resources.ResourceLocation

val String.testmodId
get() = ResourceLocation("silk-testmod", this)
get() = ResourceLocation.fromNamespaceAndPath("silk-testmod", this)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.silkmc.silk.test.commands

import net.minecraft.core.registries.Registries
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.item.Items
import net.minecraft.world.item.alchemy.Potions
Expand All @@ -8,7 +9,8 @@ import net.silkmc.silk.core.item.*

private fun createItems(player: ServerPlayer) = listOf(
itemStack(Items.NETHERITE_SWORD) {
enchant(Enchantments.SHARPNESS, 2)
val enchantmentRegistry = player.level().registryAccess().registryOrThrow(Registries.ENCHANTMENT)
enchant(enchantmentRegistry.getHolderOrThrow(Enchantments.SHARPNESS), 2)
},
itemStack(Items.POTION) {
setPotion(Potions.LEAPING)
Expand Down

0 comments on commit 403b84d

Please sign in to comment.