Skip to content

Commit

Permalink
fix: redirected click callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Nov 11, 2024
1 parent 7e5f624 commit 2b0c110
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ kotlin_version=2.0.21
fabric_kotlin_version=1.12.3

# mod properties
mod_version=1.5
mod_version=1.5.1
maven_group=net.mcbrawls
mod_id=slate
5 changes: 5 additions & 0 deletions src/main/kotlin/net/mcbrawls/slate/tile/RedirectedTile.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package net.mcbrawls.slate.tile

import net.mcbrawls.slate.Slate
import net.mcbrawls.slate.screen.slot.ClickType
import net.minecraft.item.ItemStack
import net.minecraft.server.network.ServerPlayerEntity

class RedirectedTile(
val parent: Tile,
val type: RedirectType,
) : Tile() {
override fun collectClickCallbacks(clickType: ClickType): TileClickCallback {
return parent.collectClickCallbacks(clickType)
}

override fun createDisplayedStack(slate: Slate, player: ServerPlayerEntity): ItemStack {
return when (type) {
RedirectType.NORMAL -> parent.createDisplayedStack(slate, player)
Expand Down
26 changes: 13 additions & 13 deletions src/main/kotlin/net/mcbrawls/slate/tile/Tile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ open class Tile {
*/
var immovable: Boolean = true

private val clickCallbacks: MutableList<Pair<ClickType, TileClickCallback>> = mutableListOf()
val clickCallbacks: MutableList<Pair<ClickType, TileClickCallback>> = mutableListOf()

/**
* Adds tooltips to this tile.
Expand Down Expand Up @@ -113,18 +113,6 @@ open class Tile {
}
}

/**
* Combines all callbacks for the given click type into one callable object.
*/
fun collectClickCallbacks(clickType: ClickType): TileClickCallback {
return TileClickCallback { slate, tile, context ->
clickCallbacks
.filter { it.first == clickType }
.map { it.second }
.forEach { callback -> callback.onClick(slate, tile, context) }
}
}

/**
* The base item stack to be displayed.
*/
Expand Down Expand Up @@ -188,6 +176,18 @@ open class Tile {
}
}

/**
* Combines all callbacks for the given click type into one callable object.
*/
internal open fun collectClickCallbacks(clickType: ClickType): TileClickCallback {
return TileClickCallback { slate, tile, context ->
clickCallbacks
.filter { it.first == clickType }
.map { it.second }
.forEach { callback -> callback.onClick(slate, tile, context) }
}
}

override fun toString(): String {
return "Tile"
}
Expand Down

0 comments on commit 2b0c110

Please sign in to comment.