diff --git a/build.gradle.kts b/build.gradle.kts index f3da60f..e08124a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,32 +1,25 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import com.modrinth.minotaur.TaskModrinthUpload java.sourceCompatibility = JavaVersion.VERSION_1_8 java.targetCompatibility = JavaVersion.VERSION_1_8 -fun getArtifactPath(): String { - return tasks.named("jar").get().archiveFile.get().toString() -} - -fun p(name: String): String { - return project.property(name).toString() -} +fun p(name: String) = project.property(name).toString() plugins { id("fabric-loom") - id("com.modrinth.minotaur") version "1.1.0" - kotlin("jvm") version "1.4.21" -} - -repositories { - maven("https://maven.fabricmc.net/") + kotlin("jvm") } dependencies { - minecraft("com.mojang:minecraft:${p("minecraft.target")}") + minecraft("com.mojang:minecraft:${p("minecraft")}") mappings("net.fabricmc:yarn:${p("yarn")}:v2") + modImplementation("net.fabricmc:fabric-loader:${p("loader")}") - modImplementation("net.fabricmc.fabric-api:fabric-api:${p("fabric_api")}") + + listOf("fabric-resource-loader-v0", "fabric-networking-api-v1").forEach { + modImplementation(fabricApi.module(it, p("fabric_api"))) + } + modImplementation("net.fabricmc:fabric-language-kotlin:${p("fabric_kotlin")}") } @@ -35,7 +28,7 @@ tasks.named("processResources") { from(sourceSets["main"].resources.srcDirs) { include("fabric.mod.json") - expand("version" to project.version) + expand(project.properties) } from(sourceSets["main"].resources.srcDirs) { @@ -47,23 +40,6 @@ tasks.withType { kotlinOptions.jvmTarget = "1.8" } -task("modrinth") { - token = System.getenv("MODRINTH_TOKEN") - projectId = p("id") - - versionNumber = p("version") - versionName = "${project.property("name")} v$versionNumber" - - uploadFile = getArtifactPath() - - addGameVersion(p("minecraft.target")) - - p("minecraft.compatible").split(", ").forEach { addGameVersion(it) } - - addLoader("fabric") -} - -task("publish") { - dependsOn("build") - dependsOn("modrinth") +tasks.withType { + from("LICENSE") } diff --git a/gradle.properties b/gradle.properties index 8786fab..aab1e10 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,18 +3,13 @@ org.gradle.jvmargs=-Xmx1G # Project id=vibes -name=Vibes -version=1.0.0 - -# Curse - -curse.id=?????? +title=Vibes +version=1.0.1 # Versions (https://modmuss50.me/fabric.html) -minecraft.target=1.16.4 -minecraft.compatible=1.16.3, 1.16.2 -yarn=1.16.4+build.7 -loader=0.10.8 +minecraft=1.16.5 +yarn=1.16.5+build.5 +loader=0.11.2 -fabric_api=0.29.2+1.16 -fabric_kotlin=1.4.21+build.1 +fabric_api=0.31.0+1.16 +fabric_kotlin=1.4.30+build.2 diff --git a/settings.gradle.kts b/settings.gradle.kts index 5305335..52df9cb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -6,6 +6,6 @@ pluginManagement { plugins { id("fabric-loom") version "0.5-SNAPSHOT" - kotlin("jvm") version embeddedKotlinVersion + kotlin("jvm") version "1.4.21" } } diff --git a/src/main/java/io/glossnyx/vibes/mixin/AbstractFurnaceBlockEntityMixin.java b/src/main/java/io/glossnyx/vibes/mixin/AbstractFurnaceBlockEntityMixin.java index a15d52f..577ea46 100644 --- a/src/main/java/io/glossnyx/vibes/mixin/AbstractFurnaceBlockEntityMixin.java +++ b/src/main/java/io/glossnyx/vibes/mixin/AbstractFurnaceBlockEntityMixin.java @@ -6,24 +6,28 @@ import net.minecraft.block.entity.BlockEntityType; import net.minecraft.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(AbstractFurnaceBlockEntity.class) +abstract class AbstractFurnaceBlockEntityMixin extends BlockEntity { + @Shadow public abstract ItemStack getStack(int slot); + public AbstractFurnaceBlockEntityMixin(BlockEntityType type) { super(type); } @Inject(method = "setStack", at = @At("HEAD")) private void onSetStack(int slot, ItemStack stack, CallbackInfo ci) { - ServerNetworking.INSTANCE.changePositionProvider(stack, this); + ServerNetworking.INSTANCE.changePositionProvider(stack, this, getStack(slot)); } @Inject(method = "removeStack(II)Lnet/minecraft/item/ItemStack;", at = @At("RETURN")) private void onRemoveStack(int slot, int amount, CallbackInfoReturnable cir) { - ServerNetworking.INSTANCE.changePositionProvider(cir.getReturnValue(), this.world); + ServerNetworking.INSTANCE.changePositionProvider(cir.getReturnValue(), world); } } diff --git a/src/main/java/io/glossnyx/vibes/mixin/EntityMixin.java b/src/main/java/io/glossnyx/vibes/mixin/EntityMixin.java index 39d7d67..fba6cbc 100644 --- a/src/main/java/io/glossnyx/vibes/mixin/EntityMixin.java +++ b/src/main/java/io/glossnyx/vibes/mixin/EntityMixin.java @@ -16,7 +16,7 @@ class EntityMixin { @Inject(method = "remove", at = @At("HEAD")) private void onRemove(CallbackInfo ci) { - if (this.world.isClient) return; + if (world.isClient) return; //noinspection ConstantConditions if (!ItemEntity.class.isInstance(this)) return; diff --git a/src/main/java/io/glossnyx/vibes/mixin/HopperBlockEntityMixin.java b/src/main/java/io/glossnyx/vibes/mixin/HopperBlockEntityMixin.java index 34bdce1..42c7b7f 100644 --- a/src/main/java/io/glossnyx/vibes/mixin/HopperBlockEntityMixin.java +++ b/src/main/java/io/glossnyx/vibes/mixin/HopperBlockEntityMixin.java @@ -7,7 +7,9 @@ import net.minecraft.block.entity.HopperBlockEntity; import net.minecraft.entity.ItemEntity; import net.minecraft.item.ItemStack; +import net.minecraft.util.collection.DefaultedList; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; @@ -16,18 +18,20 @@ @Mixin(HopperBlockEntity.class) class HopperBlockEntityMixin extends BlockEntity { + @Shadow private DefaultedList inventory; + public HopperBlockEntityMixin(BlockEntityType type) { super(type); } @Inject(method = "setStack", at = @At("HEAD")) private void onSetStack(int slot, ItemStack stack, CallbackInfo ci) { - ServerNetworking.INSTANCE.changePositionProvider(stack, this); + ServerNetworking.INSTANCE.changePositionProvider(stack, this, inventory.get(slot)); } @Inject(method = "removeStack(II)Lnet/minecraft/item/ItemStack;", at = @At("RETURN")) private void onRemoveStack(int slot, int amount, CallbackInfoReturnable cir) { - ServerNetworking.INSTANCE.changePositionProvider(cir.getReturnValue(), this.world); + ServerNetworking.INSTANCE.changePositionProvider(cir.getReturnValue(), world); } @Redirect( @@ -35,7 +39,7 @@ private void onRemoveStack(int slot, int amount, CallbackInfoReturnable type) { super(type); } @Inject(method = "setStack", at = @At("HEAD")) private void onSetStack(int slot, ItemStack stack, CallbackInfo ci) { - ServerNetworking.INSTANCE.changePositionProvider(stack, this); + ServerNetworking.INSTANCE.changePositionProvider(stack, this, getStack(slot)); } @Inject(method = "removeStack(II)Lnet/minecraft/item/ItemStack;", at = @At("RETURN")) private void onRemoveStack(int slot, int amount, CallbackInfoReturnable cir) { - ServerNetworking.INSTANCE.changePositionProvider(cir.getReturnValue(), this.world); + ServerNetworking.INSTANCE.changePositionProvider(cir.getReturnValue(), world); } } \ No newline at end of file diff --git a/src/main/java/io/glossnyx/vibes/mixin/ShulkerBoxBlockMixin.java b/src/main/java/io/glossnyx/vibes/mixin/ShulkerBoxBlockMixin.java index 8fa4a1c..17b7db4 100644 --- a/src/main/java/io/glossnyx/vibes/mixin/ShulkerBoxBlockMixin.java +++ b/src/main/java/io/glossnyx/vibes/mixin/ShulkerBoxBlockMixin.java @@ -16,6 +16,6 @@ class ShulkerBoxBlockMixin { @Inject(method = "onPlaced", at = @At("HEAD")) private void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack, CallbackInfo ci) { - ServerNetworking.INSTANCE.changePositionProvider(itemStack, world.getBlockEntity(pos)); + ServerNetworking.INSTANCE.changePositionProvider(itemStack, world.getBlockEntity(pos), null); } } diff --git a/src/main/java/io/glossnyx/vibes/mixin/StorageMinecartEntityMixin.java b/src/main/java/io/glossnyx/vibes/mixin/StorageMinecartEntityMixin.java index 173c1ca..8854ccb 100644 --- a/src/main/java/io/glossnyx/vibes/mixin/StorageMinecartEntityMixin.java +++ b/src/main/java/io/glossnyx/vibes/mixin/StorageMinecartEntityMixin.java @@ -25,7 +25,7 @@ private void onSetStack(int slot, ItemStack stack, CallbackInfo ci) { @Inject(method = "removeStack(II)Lnet/minecraft/item/ItemStack;", at = @At("RETURN")) private void onRemoveStack(int slot, int amount, CallbackInfoReturnable cir) { - ServerNetworking.INSTANCE.changePositionProvider(cir.getReturnValue(), this.world); + ServerNetworking.INSTANCE.changePositionProvider(cir.getReturnValue(), world); } @Override diff --git a/src/main/kotlin/io/glossnyx/vibes/item/Vibe.kt b/src/main/kotlin/io/glossnyx/vibes/item/Vibe.kt index ba6b50c..88d2577 100644 --- a/src/main/kotlin/io/glossnyx/vibes/item/Vibe.kt +++ b/src/main/kotlin/io/glossnyx/vibes/item/Vibe.kt @@ -18,9 +18,7 @@ object Vibe : Item(settings) { override fun appendTooltip(stack: ItemStack?, world: World?, tooltip: MutableList?, context: TooltipContext?) { if (tooltip == null || stack == null) return - val tag = stack.getSubTag(Tags.DISC) ?: return - ItemStack.fromTag(tag).item.appendTooltip(stack, world, tooltip, context) } } \ No newline at end of file diff --git a/src/main/kotlin/io/glossnyx/vibes/network/ClientNetworking.kt b/src/main/kotlin/io/glossnyx/vibes/network/ClientNetworking.kt index 8705d1d..21c445f 100644 --- a/src/main/kotlin/io/glossnyx/vibes/network/ClientNetworking.kt +++ b/src/main/kotlin/io/glossnyx/vibes/network/ClientNetworking.kt @@ -7,8 +7,6 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch import net.minecraft.client.MinecraftClient -import net.minecraft.client.world.ClientWorld -import net.minecraft.entity.Entity import net.minecraft.entity.player.PlayerEntity import net.minecraft.item.ItemStack import net.minecraft.item.Items @@ -20,16 +18,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable import java.util.UUID object ClientNetworking { + private val client = MinecraftClient.getInstance() private val vibeInstances = mutableListOf() - private fun getInstance(uuid: UUID): VibeInstance? { - return vibeInstances.find { it.uuid == uuid } - } + private fun getInstance(uuid: UUID) = vibeInstances.find { it.uuid == uuid } + + private fun getEntity(uuid: UUID) = client.world?.let { world -> + world.players.plus(world.entities).find { it.uuid == uuid } + } ?: throw Exception("entity with uuid $uuid not found") - private fun getEntity(world: ClientWorld, uuid: UUID): Entity { - return world.players.find { it.uuid == uuid } - ?: world.entities.find { it.uuid == uuid } - ?: throw Exception("entity with uuid $uuid not found") + private fun stop(uuid: UUID) = getInstance(uuid)?.let { + client.soundManager.stop(it) + vibeInstances.remove(it) } fun onRightClick(slot: Slot, clickType: Int, actionType: SlotActionType, player: PlayerEntity, cir: CallbackInfoReturnable) { @@ -68,37 +68,23 @@ object ClientNetworking { fun init() { register { data -> - val client = MinecraftClient.getInstance() - - getInstance(data.uuid)?.let { - client.soundManager.stop(it) - vibeInstances.remove(it) - } - - val world = client.world ?: throw Exception("no world") - val entity = getEntity(world, data.entityUUID) + stop(data.uuid) + val entity = getEntity(data.entityUUID) val instance = VibeInstance(data.uuid, EntityPositionProvider(entity), SoundEvent(data.identifier)) vibeInstances.add(instance) client.soundManager.play(instance) } - register { data -> - getInstance(data.uuid)?.let { - MinecraftClient.getInstance().soundManager.stop(it) - vibeInstances.remove(it) - } - } + register { data -> stop(data.uuid) } register { data -> getInstance(data.uuid)?.let { GlobalScope.launch { - val world = MinecraftClient.getInstance().world ?: throw Exception("no world") - - val entity = runCatching { getEntity(world, data.entityUUID) }.getOrElse { + val entity = runCatching { getEntity(data.entityUUID) }.getOrElse { delay(100) - getEntity(world, data.entityUUID) + getEntity(data.entityUUID) } it.position = EntityPositionProvider(entity) diff --git a/src/main/kotlin/io/glossnyx/vibes/network/ServerNetworking.kt b/src/main/kotlin/io/glossnyx/vibes/network/ServerNetworking.kt index 92da650..daa736a 100644 --- a/src/main/kotlin/io/glossnyx/vibes/network/ServerNetworking.kt +++ b/src/main/kotlin/io/glossnyx/vibes/network/ServerNetworking.kt @@ -26,7 +26,7 @@ object ServerNetworking { /** Stops playing sounds */ fun stopPlaying(stack: ItemStack, world: World) { forEachVibe(stack) { - world.sendAll(Stop(uuidOf(it)!!)) + world.sendAll(Stop(uuidOf(it) ?: return@forEachVibe)) } } @@ -52,7 +52,6 @@ object ServerNetworking { fun onPickup(player: PlayerEntity, entity: Entity?) { if (entity == null) return if (entity !is ItemEntity) return - if (player.world.isClient) return changePositionProvider(entity.stack, player) } @@ -81,12 +80,15 @@ object ServerNetworking { } /** When player puts vibe into block */ - fun changePositionProvider(stack: ItemStack, block: BlockEntity?) { - if (block == null) return - if (block.world!!.isClient) return + fun changePositionProvider(stack: ItemStack, block: BlockEntity?, oldStack: ItemStack?) { + val world = block?.world ?: return + if (world.isClient) return + + if (oldStack != null) changePositionProvider(oldStack, world) forEachVibe(stack) { - block.world!!.sendAll(ChangePositionBlock(uuidOf(it)!!, block.pos)) + val uuid = uuidOf(it) ?: return@forEachVibe + world.sendAll(ChangePositionBlock(uuid, block.pos)) } } @@ -96,7 +98,8 @@ object ServerNetworking { if (entity.world.isClient) return forEachVibe(stack) { - entity.world.sendAll(ChangePositionEntity(uuidOf(it)!!, entity.uuid)) + val uuid = uuidOf(it) ?: return@forEachVibe + entity.world.sendAll(ChangePositionEntity(uuid, entity.uuid)) } } diff --git a/src/main/kotlin/io/glossnyx/vibes/network/packet/ChangePositionBlock.kt b/src/main/kotlin/io/glossnyx/vibes/network/packet/ChangePositionBlock.kt index d7c40d3..b791996 100644 --- a/src/main/kotlin/io/glossnyx/vibes/network/packet/ChangePositionBlock.kt +++ b/src/main/kotlin/io/glossnyx/vibes/network/packet/ChangePositionBlock.kt @@ -1,7 +1,6 @@ package io.glossnyx.vibes.network.packet import io.glossnyx.vibes.Vibes -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs import net.minecraft.network.PacketByteBuf import net.minecraft.util.math.BlockPos import java.util.UUID @@ -16,7 +15,8 @@ data class ChangePositionBlock(val uuid: UUID, val blockPos: BlockPos) : Packet ) } - override fun toBuf(): PacketByteBuf = PacketByteBufs.create() - .writeUuid(uuid) - .writeBlockPos(blockPos) + override val buffer = createPacket { + writeUuid(uuid) + writeBlockPos(blockPos) + } } \ No newline at end of file diff --git a/src/main/kotlin/io/glossnyx/vibes/network/packet/ChangePositionEntity.kt b/src/main/kotlin/io/glossnyx/vibes/network/packet/ChangePositionEntity.kt index 9dd2a51..4a3c9c7 100644 --- a/src/main/kotlin/io/glossnyx/vibes/network/packet/ChangePositionEntity.kt +++ b/src/main/kotlin/io/glossnyx/vibes/network/packet/ChangePositionEntity.kt @@ -1,7 +1,6 @@ package io.glossnyx.vibes.network.packet import io.glossnyx.vibes.Vibes -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs import net.minecraft.network.PacketByteBuf import java.util.UUID @@ -15,7 +14,8 @@ data class ChangePositionEntity(val uuid: UUID, val entityUUID: UUID) : Packet { ) } - override fun toBuf(): PacketByteBuf = PacketByteBufs.create() - .writeUuid(uuid) - .writeUuid(entityUUID) + override val buffer = createPacket { + writeUuid(uuid) + writeUuid(entityUUID) + } } \ No newline at end of file diff --git a/src/main/kotlin/io/glossnyx/vibes/network/packet/Packets.kt b/src/main/kotlin/io/glossnyx/vibes/network/packet/Packets.kt index 2db52b8..83695e6 100644 --- a/src/main/kotlin/io/glossnyx/vibes/network/packet/Packets.kt +++ b/src/main/kotlin/io/glossnyx/vibes/network/packet/Packets.kt @@ -1,6 +1,7 @@ package io.glossnyx.vibes.network.packet import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking import net.minecraft.network.PacketByteBuf import net.minecraft.server.network.ServerPlayerEntity @@ -8,7 +9,7 @@ import net.minecraft.util.Identifier import kotlin.reflect.full.companionObjectInstance interface Packet { - fun toBuf(): PacketByteBuf + val buffer: PacketByteBuf } interface PacketCompanion { @@ -36,10 +37,12 @@ inline fun register(crossinline handler: (packet: T, player fun send(player: ServerPlayerEntity, packet: Packet) { val companion = packet::class.companionObjectInstance as PacketCompanion - ServerPlayNetworking.send(player, companion.id, packet.toBuf()) + ServerPlayNetworking.send(player, companion.id, packet.buffer) } fun send(packet: Packet) { val companion = packet::class.companionObjectInstance as PacketCompanion - ClientPlayNetworking.send(companion.id, packet.toBuf()) -} \ No newline at end of file + ClientPlayNetworking.send(companion.id, packet.buffer) +} + +fun createPacket(block: PacketByteBuf.() -> Unit) = PacketByteBufs.create().apply(block)!! diff --git a/src/main/kotlin/io/glossnyx/vibes/network/packet/Play.kt b/src/main/kotlin/io/glossnyx/vibes/network/packet/Play.kt index d798f43..365a93a 100644 --- a/src/main/kotlin/io/glossnyx/vibes/network/packet/Play.kt +++ b/src/main/kotlin/io/glossnyx/vibes/network/packet/Play.kt @@ -1,7 +1,6 @@ package io.glossnyx.vibes.network.packet import io.glossnyx.vibes.Vibes -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs import net.minecraft.network.PacketByteBuf import net.minecraft.util.Identifier import java.util.UUID @@ -17,8 +16,9 @@ data class Play(val uuid: UUID, val entityUUID: UUID, val identifier: Identifier ) } - override fun toBuf(): PacketByteBuf = PacketByteBufs.create() - .writeUuid(uuid) - .writeUuid(entityUUID) - .writeIdentifier(identifier) + override val buffer = createPacket { + writeUuid(uuid) + writeUuid(entityUUID) + writeIdentifier(identifier) + } } \ No newline at end of file diff --git a/src/main/kotlin/io/glossnyx/vibes/network/packet/RightClickPlay.kt b/src/main/kotlin/io/glossnyx/vibes/network/packet/RightClickPlay.kt index 84840d1..437b33c 100644 --- a/src/main/kotlin/io/glossnyx/vibes/network/packet/RightClickPlay.kt +++ b/src/main/kotlin/io/glossnyx/vibes/network/packet/RightClickPlay.kt @@ -1,7 +1,6 @@ package io.glossnyx.vibes.network.packet import io.glossnyx.vibes.Vibes -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs import net.minecraft.network.PacketByteBuf import net.minecraft.util.Identifier import java.util.UUID @@ -17,8 +16,9 @@ data class RightClickPlay(val slotID: Int, val uuid: UUID, val identifier: Ident ) } - override fun toBuf(): PacketByteBuf = PacketByteBufs.create() - .writeVarInt(slotID) - .writeUuid(uuid) - .writeIdentifier(identifier) + override val buffer = createPacket { + writeVarInt(slotID) + writeUuid(uuid) + writeIdentifier(identifier) + } } \ No newline at end of file diff --git a/src/main/kotlin/io/glossnyx/vibes/network/packet/RightClickStop.kt b/src/main/kotlin/io/glossnyx/vibes/network/packet/RightClickStop.kt index 85e924e..168af22 100644 --- a/src/main/kotlin/io/glossnyx/vibes/network/packet/RightClickStop.kt +++ b/src/main/kotlin/io/glossnyx/vibes/network/packet/RightClickStop.kt @@ -1,7 +1,6 @@ package io.glossnyx.vibes.network.packet import io.glossnyx.vibes.Vibes -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs import net.minecraft.network.PacketByteBuf data class RightClickStop(val slotID: Int) : Packet { @@ -10,5 +9,5 @@ data class RightClickStop(val slotID: Int) : Packet { override fun fromBuf(buf: PacketByteBuf) = RightClickStop(buf.readVarInt()) } - override fun toBuf(): PacketByteBuf = PacketByteBufs.create().writeVarInt(slotID) + override val buffer = createPacket { writeVarInt(slotID) } } \ No newline at end of file diff --git a/src/main/kotlin/io/glossnyx/vibes/network/packet/Stop.kt b/src/main/kotlin/io/glossnyx/vibes/network/packet/Stop.kt index 4e98972..41590f6 100644 --- a/src/main/kotlin/io/glossnyx/vibes/network/packet/Stop.kt +++ b/src/main/kotlin/io/glossnyx/vibes/network/packet/Stop.kt @@ -1,7 +1,6 @@ package io.glossnyx.vibes.network.packet import io.glossnyx.vibes.Vibes -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs import net.minecraft.network.PacketByteBuf import java.util.UUID @@ -11,5 +10,5 @@ data class Stop(val uuid: UUID) : Packet { override fun fromBuf(buf: PacketByteBuf) = Stop(buf.readUuid()) } - override fun toBuf(): PacketByteBuf = PacketByteBufs.create().writeUuid(uuid) + override val buffer = createPacket { writeUuid(uuid) } } \ No newline at end of file diff --git a/src/main/kotlin/io/glossnyx/vibes/util/Items.kt b/src/main/kotlin/io/glossnyx/vibes/util/Items.kt index 35dee26..130935a 100644 --- a/src/main/kotlin/io/glossnyx/vibes/util/Items.kt +++ b/src/main/kotlin/io/glossnyx/vibes/util/Items.kt @@ -12,17 +12,17 @@ enum class VibeType { SHULKER } -fun getShulkerInventory(stack: ItemStack): DefaultedList? { +fun shulkerInventoryOf(stack: ItemStack): List? { val tag = stack.getSubTag("BlockEntityTag") ?: return null val inventory = DefaultedList.ofSize(27, ItemStack.EMPTY) Inventories.fromTag(tag, inventory) - return inventory + return inventory.toList() } fun isPlaying(stack: ItemStack): Boolean { return when (vibeTypeOf(stack)) { VibeType.VIBE -> uuidOf(stack) != null && discOf(stack) != null - VibeType.SHULKER -> getShulkerInventory(stack)?.find { isPlaying(it) } != null + VibeType.SHULKER -> shulkerInventoryOf(stack)?.find(::isPlaying) != null else -> false } } @@ -37,7 +37,9 @@ fun vibeTypeOf(stack: ItemStack): VibeType? { fun forEachVibe(stack: ItemStack, fn: (stack: ItemStack) -> Unit) { if (!isPlaying(stack)) return - if (vibeTypeOf(stack) == VibeType.VIBE) return fn(stack) - getShulkerInventory(stack)?.filter { isPlaying(it) }?.forEach { forEachVibe(it, fn) } + when (vibeTypeOf(stack)) { + VibeType.VIBE -> fn(stack) + VibeType.SHULKER -> shulkerInventoryOf(stack)?.filter(::isPlaying)?.forEach { forEachVibe(it, fn) } + } } \ No newline at end of file diff --git a/src/main/kotlin/io/glossnyx/vibes/util/Tags.kt b/src/main/kotlin/io/glossnyx/vibes/util/Tags.kt index 23bd5f8..e24fcd6 100644 --- a/src/main/kotlin/io/glossnyx/vibes/util/Tags.kt +++ b/src/main/kotlin/io/glossnyx/vibes/util/Tags.kt @@ -9,15 +9,14 @@ object Tags { const val UUID = "VibeUUID" } -fun uuidOf(stack: ItemStack): UUID? { - return if (stack.orCreateTag.containsUuid(Tags.UUID)) stack.orCreateTag.getUuid(Tags.UUID) else null +fun uuidOf(stack: ItemStack) = stack.tag?.let { + if (it.containsUuid(Tags.UUID)) it.getUuid(Tags.UUID) else null } fun setUUIDOf(stack: ItemStack, uuid: UUID) = stack.orCreateTag.putUuid(Tags.UUID, uuid) -fun discOf(stack: ItemStack): ItemStack? { - val tag = stack.getSubTag(Tags.DISC) ?: return null - return ItemStack.fromTag(tag) +fun discOf(stack: ItemStack) = stack.getSubTag(Tags.DISC)?.let { + ItemStack.fromTag(it) } fun setDiscOf(stack: ItemStack, disc: ItemStack) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a7857bc..02cd2c3 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,26 +1,27 @@ { "schemaVersion": 1, - "id": "vibes", + "id": "${id}", "version": "${version}", - "name": "Vibes", + "name": "${title}", "description": "Listen to music discs on the go with the Vibe", "authors": ["glossnyx"], "contact": { - "homepage": "https://github.com/glossnyx/vibes", - "sources": "https://github.com/glossnyx/vibes" + "homepage": "https://github.com/glossnyx/${id}", + "sources": "https://github.com/glossnyx/${id}" }, "license": "MIT", - "icon": "assets/vibes/icon.png", + "icon": "assets/${id}/icon.png", "environment": "*", "entrypoints": { "main": ["io.glossnyx.vibes.EntrypointKt::init"], "client": ["io.glossnyx.vibes.EntrypointKt::initClient"] }, - "mixins": ["vibes.mixins.json"], + "mixins": ["${id}.mixins.json"], "depends": { + "minecraft": "1.16.x", "fabricloader": ">=0.8.7", - "fabric": "*", - "fabric-language-kotlin": "*", - "minecraft": "1.16.x" + "fabric-resource-loader-v0": "*", + "fabric-networking-api-v1": "*", + "fabric-language-kotlin": "*" } }