-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBlocksRegistry.kt
More file actions
81 lines (67 loc) · 3.27 KB
/
BlocksRegistry.kt
File metadata and controls
81 lines (67 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package blocks
import ru.endlesscode.mimic.ExperimentalMimicApi
import ru.endlesscode.mimic.MimicService
/**
* Registry to get and place blocks.
* @since 0.9.0
*/
@ExperimentalMimicApi
public interface BlocksRegistry<ItemStackT : Any, BlockT : Any> : MimicService {
/** Returns all known block IDs. */
public val knownIds: Collection<String>
/** Returns `true` if given [block] represented with given [blockId]. */
public fun isSameBlock(block: BlockT, blockId: String): Boolean = getBlockId(block) == blockId
/** Returns `true` if given [blockItem] is an item stack containing the block represented with given [blockId]. */
public fun isSameBlockItem(blockItem: ItemStackT, blockId: String): Boolean = getBlockItemId(blockItem) == blockId
/** Returns `true` if block with given [blockId] exists. */
public fun isBlockExists(blockId: String): Boolean
/** Returns ID representing given [block], or `null` if the ID not found in this registry. */
public fun getBlockId(block: BlockT): String?
/**
* Returns ID representing the block contained in given [blockItem],
* or `null` if the ID not found in this registry.
*/
public fun getBlockItemId(blockItem: ItemStackT): String?
/** Returns item containing block by given [blockId], or `null` if the ID not found in this registry. */
public fun getBlockItem(blockId: String): ItemStackT? = getBlockItem(blockId, payload = null, amount = 1)
/**
* Returns item containing block with specified [payload] by given [blockId],
* or `null` if the ID not found in this registry.
*
* If [payload] is not `null`, block will be configured using it.
*/
public fun getBlockItem(blockId: String, payload: Any?): ItemStackT? = getBlockItem(blockId, payload, amount = 1)
/**
* Returns item containing block with specified [amount] by given [blockId],
* or `null` if ID not found in this registry.
*
* If the given [amount] is greater than maximum possible, will use maximum possible amount.
* Amount shouldn't be less than `1`.
*/
public fun getBlockItem(blockId: String, amount: Int): ItemStackT? = getBlockItem(blockId, payload = null, amount)
/**
* Returns item containing block with specified [amount] and [payload] by given [blockId],
* or `null` if ID not found in this registry.
*
* If the given [amount] is greater than maximum possible, will use maximum possible amount.
* Amount shouldn't be less than `1`.
*
* Given [payload] may be used to configure block.
*/
public fun getBlockItem(blockId: String, payload: Any?, amount: Int): ItemStackT?
/**
* Places block by given [blockId] at [destination].
*
* Returns `true` if the block was placed, and `false` if ID not found in this registry.
*/
public fun placeBlock(blockId: String, destination: BlockT): Boolean =
placeBlock(blockId, payload = null, destination)
/**
* Places block with specified [payload] by given [blockId] at [destination].
*
* Given [payload] may be used to configure block.
*
* Returns `true` if the block was placed, and `false` if ID not found in this registry.
*/
public fun placeBlock(blockId: String, payload: Any?, destination: BlockT): Boolean
}