diff --git a/build.gradle.kts b/build.gradle.kts index 26ad510..07379d6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget plugins { id("fabric-loom") version "1.7-SNAPSHOT" id("maven-publish") - id("org.jetbrains.kotlin.jvm") version "2.0.0" + id("org.jetbrains.kotlin.jvm") version "2.0.10" } version = property("mod_version").toString() @@ -50,20 +50,20 @@ tasks.withType { tasks.withType { - options.release = 17 + options.release = 21 } tasks.withType { compilerOptions { - jvmTarget = JvmTarget.JVM_17 + jvmTarget = JvmTarget.JVM_21 } } java { withSourcesJar() - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } tasks.withType { diff --git a/gradle.properties b/gradle.properties index ccbd03e..ee70459 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,10 +4,10 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.10 +minecraft_version=1.21 +yarn_mappings=1.21+build.2 loader_version=0.15.11 -fabric_kotlin_version=1.11.0+kotlin.2.0.0 +fabric_kotlin_version=1.12.0+kotlin.2.0.10 # Mod Properties mod_version=1.0.1 @@ -15,4 +15,4 @@ maven_group=starworld.core archives_base_name=starworldcorelib # Dependencies -fabric_version=0.92.2+1.20.1 \ No newline at end of file +fabric_version=0.102.0+1.21 \ No newline at end of file diff --git a/src/client/resources/starworldcorelib.client.mixins.json b/src/client/resources/starworldcorelib.client.mixins.json index b5f712e..0a55969 100644 --- a/src/client/resources/starworldcorelib.client.mixins.json +++ b/src/client/resources/starworldcorelib.client.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "starworld.core.mixin.client", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "client": [ "MinecraftClientMixin" ], diff --git a/src/main/kotlin/starworld/core/StarWorldCoreLib.kt b/src/main/kotlin/starworld/core/StarWorldCoreLib.kt index 6e7e3ac..628704d 100644 --- a/src/main/kotlin/starworld/core/StarWorldCoreLib.kt +++ b/src/main/kotlin/starworld/core/StarWorldCoreLib.kt @@ -1,11 +1,12 @@ package starworld.core import net.fabricmc.api.ModInitializer +import net.minecraft.util.Identifier import org.slf4j.LoggerFactory object StarWorldCoreLib : ModInitializer { - const val ID = "starworldcorelib" + const val ID = "swcl" val LOGGER = LoggerFactory.getLogger(ID) @@ -14,4 +15,7 @@ object StarWorldCoreLib : ModInitializer { LOGGER.info("Initialized!") } + fun rl(path: String) = Identifier.of(ID, path) + fun rls(path: String) = rl(path).toString() + } \ No newline at end of file diff --git a/src/main/kotlin/starworld/core/datagen/StarWorldCoreLibDataGenerator.kt b/src/main/kotlin/starworld/core/datagen/StarWorldCoreLibDataGenerator.kt index e3f8689..3adf30c 100644 --- a/src/main/kotlin/starworld/core/datagen/StarWorldCoreLibDataGenerator.kt +++ b/src/main/kotlin/starworld/core/datagen/StarWorldCoreLibDataGenerator.kt @@ -4,6 +4,5 @@ import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator object StarWorldCoreLibDataGenerator : DataGeneratorEntrypoint { - override fun onInitializeDataGenerator(fabricDataGenerator: FabricDataGenerator) { - } + override fun onInitializeDataGenerator(fabricDataGenerator: FabricDataGenerator) {} } \ No newline at end of file diff --git a/src/main/kotlin/starworld/core/server/command/ShareBlockCommand.kt b/src/main/kotlin/starworld/core/server/command/ShareBlockCommand.kt index 2bd815f..af42d8b 100644 --- a/src/main/kotlin/starworld/core/server/command/ShareBlockCommand.kt +++ b/src/main/kotlin/starworld/core/server/command/ShareBlockCommand.kt @@ -7,25 +7,25 @@ import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes import net.minecraft.command.CommandRegistryAccess import net.minecraft.command.argument.BlockPosArgumentType -import net.minecraft.item.BlockItem +import net.minecraft.component.DataComponentTypes.CUSTOM_NAME import net.minecraft.item.ItemStack import net.minecraft.item.Items -import net.minecraft.nbt.NbtCompound import net.minecraft.network.message.MessageType import net.minecraft.network.message.SignedMessage import net.minecraft.registry.Registries +import net.minecraft.registry.RegistryWrapper import net.minecraft.server.command.CommandManager import net.minecraft.server.command.ServerCommandSource import net.minecraft.text.HoverEvent -import net.minecraft.text.MutableText import net.minecraft.text.Text -import net.minecraft.text.TextContent import net.minecraft.util.Formatting import net.minecraft.util.hit.BlockHitResult import net.minecraft.util.math.BlockPos +import starworld.core.StarWorldCoreLib.rls import starworld.core.util.color import starworld.core.util.hover import starworld.core.util.text +import java.util.stream.Stream enum class ShareBlockCommand(val allowFluids: Boolean) : CommandRegistrationCallback { @@ -37,7 +37,7 @@ enum class ShareBlockCommand(val allowFluids: Boolean) : CommandRegistrationCall environment: CommandManager.RegistrationEnvironment ) { dispatcher.register( - CommandManager.literal(if (allowFluids) "share-fluid" else "share-block").then( + CommandManager.literal(rls(if (allowFluids) "share-fluid" else "share-block")).then( CommandManager.argument("position", BlockPosArgumentType.blockPos()) .executes { handle(BlockPosArgumentType.getLoadedBlockPos(it, "position"), it) @@ -51,7 +51,6 @@ enum class ShareBlockCommand(val allowFluids: Boolean) : CommandRegistrationCall ) } - @Suppress("UnstableApiUsage") fun handle(blockPos: BlockPos, context: CommandContext): Int { val playerManager = context.source.server.playerManager val world = context.source.playerOrThrow.serverWorld @@ -66,25 +65,24 @@ enum class ShareBlockCommand(val allowFluids: Boolean) : CommandRegistrationCall else block, 1 ) - if (allowFluids) itemStack.setCustomName(text(FluidVariantAttributes.getName(FluidVariant.of(blockState.fluidState.fluid))).styled { it.withItalic(false) }) - BlockItem.setBlockEntityNbt( + if (allowFluids) itemStack.set(CUSTOM_NAME, text(FluidVariantAttributes.getName(FluidVariant.of(blockState.fluidState.fluid))).styled { it.withItalic(false) }) + blockEntity?.setStackNbt( itemStack, - blockEntity?.type, - blockEntity?.createNbt() ?: NbtCompound() + RegistryWrapper.WrapperLookup.of(Stream.of(Registries.BLOCK.readOnlyWrapper)) ) val id = if (allowFluids) Registries.FLUID.getId(blockState.fluidState.fluid).toString() else Registries.BLOCK.getId(block).toString() - val text = MutableText.of(TextContent.EMPTY).apply { + val text = Text.empty().apply { append(ShareItemCommand.toItemChatText(itemStack)) append(" ") .append( - MutableText.of(TextContent.EMPTY) + Text.empty() .append("id ") .append(text(id).hover(text(id)).color(Formatting.GREEN)) .styled { it.withColor(Formatting.GRAY) } ) - append(MutableText.of(TextContent.EMPTY).append(" at ").styled { it.withColor(Formatting.GRAY) }) + append(Text.empty().append(" at ").styled { it.withColor(Formatting.GRAY) }) append( - MutableText.of(TextContent.EMPTY).apply { + Text.empty().apply { append(blockPos.toShortString()) styled { it.withHoverEvent( diff --git a/src/main/kotlin/starworld/core/server/command/ShareEntityCommand.kt b/src/main/kotlin/starworld/core/server/command/ShareEntityCommand.kt index 23866ab..61d90f1 100644 --- a/src/main/kotlin/starworld/core/server/command/ShareEntityCommand.kt +++ b/src/main/kotlin/starworld/core/server/command/ShareEntityCommand.kt @@ -12,13 +12,15 @@ import net.minecraft.server.command.CommandManager import net.minecraft.server.command.ServerCommandSource import net.minecraft.text.* import net.minecraft.util.Formatting +import net.minecraft.util.hit.EntityHitResult +import starworld.core.StarWorldCoreLib.rls import starworld.core.util.color import starworld.core.util.hover import starworld.core.util.text object ShareEntityCommand : CommandRegistrationCallback { - fun toEntityChatText(entity: Entity) = MutableText.of(TextContent.EMPTY).apply { + fun toEntityChatText(entity: Entity) = Text.empty().apply { styled { style: Style -> style.withHoverEvent( HoverEvent( @@ -36,32 +38,33 @@ object ShareEntityCommand : CommandRegistrationCallback { environment: CommandManager.RegistrationEnvironment ) { dispatcher.register( - CommandManager.literal("share-entity").then( + CommandManager.literal(rls("share-entity")).then( CommandManager.argument("selector", EntityArgumentType.entity()) .executes { handle(EntityArgumentType.getEntity(it, "selector"), it) } ).executes { - handle(it.source.entityOrThrow, it) + val raycast = it.source.playerOrThrow.raycast(15.0, 0f, false) + handle(if (raycast is EntityHitResult) raycast.entity else it.source.entityOrThrow, it) } ) } fun handle(entity: Entity, context: CommandContext): Int { val playerManager = context.source.server.playerManager - val text = MutableText.of(TextContent.EMPTY).apply { + val text = Text.empty().apply { append(toEntityChatText(entity)) append(" ") .append( - MutableText.of(TextContent.EMPTY) + Text.empty() .append("uuid ") .append(text(entity.uuidAsString).hover(text(entity.uuidAsString)).color(Formatting.GREEN)) .append("") .styled { it.withColor(Formatting.GRAY) } ) - append(MutableText.of(TextContent.EMPTY).append(" at ").styled { it.withColor(Formatting.GRAY) }) + append(Text.empty().append(" at ").styled { it.withColor(Formatting.GRAY) }) append( - MutableText.of(TextContent.EMPTY).apply { + Text.empty().apply { append(entity.blockPos.toShortString()) styled { it.withHoverEvent( diff --git a/src/main/kotlin/starworld/core/server/command/ShareItemCommand.kt b/src/main/kotlin/starworld/core/server/command/ShareItemCommand.kt index cf3223b..56317ac 100644 --- a/src/main/kotlin/starworld/core/server/command/ShareItemCommand.kt +++ b/src/main/kotlin/starworld/core/server/command/ShareItemCommand.kt @@ -13,13 +13,14 @@ import net.minecraft.server.command.ServerCommandSource import net.minecraft.text.* import net.minecraft.text.HoverEvent.ItemStackContent import net.minecraft.util.Formatting +import starworld.core.StarWorldCoreLib.rls import starworld.core.util.color import starworld.core.util.hover import starworld.core.util.text object ShareItemCommand : CommandRegistrationCallback { - fun toItemChatText(itemStack: ItemStack) = MutableText.of(TextContent.EMPTY).apply { + fun toItemChatText(itemStack: ItemStack) = Text.empty().apply { if (itemStack.count > 1) append("${itemStack.count} * ") styled { style: Style -> style.withHoverEvent( @@ -38,16 +39,16 @@ object ShareItemCommand : CommandRegistrationCallback { environment: CommandManager.RegistrationEnvironment ) { dispatcher.register( - CommandManager.literal("share-item").executes { context: CommandContext -> + CommandManager.literal(rls("share-item")).executes { context: CommandContext -> val player = context.source.playerOrThrow val playerManager = context.source.server.playerManager var itemStack = player.mainHandStack if (itemStack.isEmpty) itemStack = player.offHandStack val id = Registries.ITEM.getId(itemStack.item).toString() - val text = MutableText.of(TextContent.EMPTY).apply { + val text = Text.empty().apply { append(toItemChatText(itemStack)) append(" ").append( - MutableText.of(TextContent.EMPTY) + Text.empty() .append("id ") .append(text(id).hover(text(id)).color(Formatting.GREEN)) .styled { it.withColor(Formatting.GRAY) } diff --git a/src/main/kotlin/starworld/core/util/TextUtils.kt b/src/main/kotlin/starworld/core/util/TextUtils.kt index 170eb94..c9e23d7 100644 --- a/src/main/kotlin/starworld/core/util/TextUtils.kt +++ b/src/main/kotlin/starworld/core/util/TextUtils.kt @@ -4,14 +4,13 @@ import net.minecraft.text.HoverEvent import net.minecraft.text.MutableText import net.minecraft.text.Text import net.minecraft.text.TextColor -import net.minecraft.text.TextContent import net.minecraft.util.Formatting -fun text(text: String? = null) = MutableText.of(TextContent.EMPTY).also { +fun text(text: String? = null): MutableText = Text.empty().also { if (text != null) it.append(text) } -fun text(text: Text? = null) = MutableText.of(TextContent.EMPTY).also { +fun text(text: Text? = null): MutableText = Text.empty().also { if (text != null) it.append(text) } diff --git a/src/main/resources/assets/starworldcorelib/icon.png b/src/main/resources/assets/swcl/icon.png similarity index 100% rename from src/main/resources/assets/starworldcorelib/icon.png rename to src/main/resources/assets/swcl/icon.png diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 21c27cd..be3dc18 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "id": "starworldcorelib", + "id": "swcl", "version": "${version}", "name": "StarWorld's CoreLib", "description": "Some Utilities", @@ -12,7 +12,7 @@ "sources": "https://github.com/FabricMC/fabric-example-mod" }, "license": "MIT", - "icon": "assets/starworldcorelib/icon.png", + "icon": "assets/swcl/icon.png", "environment": "*", "entrypoints": { "main": [ @@ -43,8 +43,8 @@ ], "depends": { "fabricloader": ">=0.15.11", - "minecraft": "~1.20.1", - "java": ">=17", + "minecraft": "~1.21", + "java": ">=21", "fabric-api": "*", "fabric-language-kotlin": "*" }, diff --git a/src/main/resources/starworldcorelib.mixins.json b/src/main/resources/starworldcorelib.mixins.json index e02c95f..7a5736a 100644 --- a/src/main/resources/starworldcorelib.mixins.json +++ b/src/main/resources/starworldcorelib.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "starworld.core.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "mixins": [ "MinecraftServerMixin" ],