Skip to content

Commit

Permalink
build: 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
WowStarWorld committed Aug 23, 2024
1 parent 2f08b55 commit 1364c94
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 46 deletions.
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -50,20 +50,20 @@ tasks.withType<ProcessResources> {


tasks.withType<JavaCompile> {
options.release = 17
options.release = 21
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
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<Jar> {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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
maven_group=starworld.core
archives_base_name=starworldcorelib

# Dependencies
fabric_version=0.92.2+1.20.1
fabric_version=0.102.0+1.21
2 changes: 1 addition & 1 deletion src/client/resources/starworldcorelib.client.mixins.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"required": true,
"package": "starworld.core.mixin.client",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"client": [
"MinecraftClientMixin"
],
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/starworld/core/StarWorldCoreLib.kt
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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()

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
26 changes: 12 additions & 14 deletions src/main/kotlin/starworld/core/server/command/ShareBlockCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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)
Expand All @@ -51,7 +51,6 @@ enum class ShareBlockCommand(val allowFluids: Boolean) : CommandRegistrationCall
)
}

@Suppress("UnstableApiUsage")
fun handle(blockPos: BlockPos, context: CommandContext<ServerCommandSource>): Int {
val playerManager = context.source.server.playerManager
val world = context.source.playerOrThrow.serverWorld
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<ServerCommandSource>): 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -38,16 +39,16 @@ object ShareItemCommand : CommandRegistrationCallback {
environment: CommandManager.RegistrationEnvironment
) {
dispatcher.register(
CommandManager.literal("share-item").executes { context: CommandContext<ServerCommandSource> ->
CommandManager.literal(rls("share-item")).executes { context: CommandContext<ServerCommandSource> ->
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) }
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/starworld/core/util/TextUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
File renamed without changes
8 changes: 4 additions & 4 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"id": "starworldcorelib",
"id": "swcl",
"version": "${version}",
"name": "StarWorld's CoreLib",
"description": "Some Utilities",
Expand All @@ -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": [
Expand Down Expand Up @@ -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": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/starworldcorelib.mixins.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"required": true,
"package": "starworld.core.mixin",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"mixins": [
"MinecraftServerMixin"
],
Expand Down

0 comments on commit 1364c94

Please sign in to comment.