Skip to content

Commit

Permalink
add curios/trinkets support
Browse files Browse the repository at this point in the history
  • Loading branch information
auxves committed Oct 19, 2023
1 parent a8a067a commit fc2e0a2
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 68 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/deploy.yml

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tasks.named<Copy>("processResources") {

from(sourceSets["main"].resources.srcDirs) {
include("fabric.mod.json")
expand(project.properties)
expand(properties)
}

from(sourceSets["main"].resources.srcDirs) {
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
kotlin.code.style=official
org.gradle.jvmargs=-Xmx1G

version=3.0.1
version=3.1.0+1.20.2

# Versions (https://fabricmc.net/develop)
minecraft=1.20.1
yarn=1.20.1+build.10
loader=0.14.22
minecraft=1.20.2
yarn=1.20.2+build.4
loader=0.14.23

fabric_api=0.88.1+1.20.1
fabric_kotlin=1.10.10+kotlin.1.9.10
fabric_api=0.90.0+1.20.2
fabric_kotlin=1.10.10+kotlin.1.9.10

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/kotlin/dev/auxves/vibes/client/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dev.auxves.vibes.sound.VibeInstance
import kotlinx.coroutines.*
import net.minecraft.client.MinecraftClient
import net.minecraft.sound.SoundEvent
import java.util.UUID
import java.util.*

private val client = MinecraftClient.getInstance()
private val instances = mutableMapOf<UUID, VibeInstance>()
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/dev/auxves/vibes/server/Bridges.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package dev.auxves.vibes.server

import dev.auxves.vibes.mixin.EnderChestInventoryAccessor
import dev.auxves.vibes.network.packet.*
import dev.auxves.vibes.util.VibeType
import dev.auxves.vibes.util.uuid
import dev.auxves.vibes.util.vibeTypeOf
import dev.auxves.vibes.util.vibesIn
import dev.auxves.vibes.util.*
import net.minecraft.block.entity.BlockEntity
import net.minecraft.entity.Entity
import net.minecraft.entity.ItemEntity
Expand Down Expand Up @@ -35,7 +32,9 @@ fun onBreakShulkerBox(entity: Entity) {
}

fun stopPlaying(stack: ItemStack, world: World) {
vibesIn(stack).map { it.uuid }.forEach { world.sendAll(Stop(it)) }
vibesIn(stack).map { it.uuid }.forEach {
world.sendAll(Stop(it))
}
}

fun changePosition(stack: ItemStack, block: BlockEntity) {
Expand Down
9 changes: 7 additions & 2 deletions src/main/kotlin/dev/auxves/vibes/server/Server.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package dev.auxves.vibes.server

import dev.auxves.vibes.network.packet.*
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents

fun initServer() {
register<Play> { data, player -> player.send(data) }
register<Stop> { data, player -> player.send(data) }
register<Play> { data, player -> player.world.sendAll(data) }
register<Stop> { data, player -> player.world.sendAll(data) }

ServerPlayConnectionEvents.DISCONNECT.register { handler, server ->
server.execute { onDisconnect(handler.player) }
}
}
11 changes: 10 additions & 1 deletion src/main/kotlin/dev/auxves/vibes/util/Items.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.auxves.vibes.item.Vibe
import net.minecraft.block.ShulkerBoxBlock
import net.minecraft.item.BlockItem
import net.minecraft.item.ItemStack
import java.util.UUID

enum class VibeType {
VIBE,
Expand All @@ -16,6 +17,14 @@ fun isPlaying(stack: ItemStack): Boolean = when (vibeTypeOf(stack)) {
else -> false
}

fun ensureUuid(stack: ItemStack): ItemStack {
if (stack.item is Vibe && !stack.orCreateNbt.containsUuid(Tags.UUID)) {
stack.uuid = UUID.randomUUID()
}

return stack
}

fun vibeTypeOf(stack: ItemStack): VibeType? = when {
stack.item is Vibe -> VibeType.VIBE
(stack.item as? BlockItem)?.block is ShulkerBoxBlock -> VibeType.SHULKER
Expand All @@ -26,4 +35,4 @@ fun vibesIn(stack: ItemStack): Sequence<ItemStack> = when (vibeTypeOf(stack)) {
VibeType.VIBE -> sequenceOf(stack)
VibeType.SHULKER -> shulkerInventoryOf(stack).asSequence().flatMap(::vibesIn)
else -> sequenceOf()
}.filter(::isPlaying)
}.map(::ensureUuid).filter(::isPlaying)
7 changes: 1 addition & 6 deletions src/main/kotlin/dev/auxves/vibes/util/Tags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ object Tags {
}

var ItemStack.uuid: UUID
get() {
if (orCreateNbt.containsUuid(Tags.UUID)) return orCreateNbt.getUuid(Tags.UUID)
val new = UUID.randomUUID()
uuid = new
return new
}
get() = orCreateNbt.getUuid(Tags.UUID)
set(new) = orCreateNbt.putUuid(Tags.UUID, new)

var ItemStack.disc: ItemStack?
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/data/curios/tags/items/back.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"vibes:vibe"
]
}
4 changes: 4 additions & 0 deletions src/main/resources/data/trinkets/entities/vibes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"entities": ["player"],
"slots": ["chest/back"]
}
6 changes: 6 additions & 0 deletions src/main/resources/data/trinkets/tags/items/chest/back.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"vibes:vibe"
]
}
4 changes: 4 additions & 0 deletions src/main/resources/data/vibes/curios/entities/vibes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"entities": ["player"],
"slots": ["back"]
}
3 changes: 1 addition & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
},
"mixins": ["vibes.mixins.json"],
"depends": {
"minecraft": "1.20.x",
"fabricloader": "*",
"minecraft": "1.20.1",
"fabric-api": "*",
"fabric-language-kotlin": "*"
}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/vibes.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"LootableContainerBlockEntityMixin",
"PlayerEntityMixin",
"PlayerInventoryMixin",
"ServerPlayNetworkHandlerMixin",
"ShulkerBoxBlockMixin",
"SimpleInventoryMixin",
"SoundManagerAccessor",
Expand Down

0 comments on commit fc2e0a2

Please sign in to comment.