Skip to content

Commit 200d217

Browse files
committed
actually 3, better default block texture item
1 parent 3f42ec6 commit 200d217

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

rebar/src/main/kotlin/io/github/pylonmc/rebar/block/RebarBlock.kt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ open class RebarBlock private constructor(val block: Block) : Keyed {
189189
/**
190190
* Returns the item that should be used to display the block's texture.
191191
*
192-
* By default, returns the item with the same key as the block, marked with the
193-
* [rebarBlockTextureEntityKey]. The item will also have custom model data with
192+
* By default, returns the rebar item with the same key as the block, marked with the
193+
* [rebarBlockTextureEntityKey], or if there is no matching rebar item, an item with
194+
* the block material & key. The item will also have custom model data with
194195
* the vanilla block state properties of the block, merged with any custom
195196
* properties provided by the block. (see [getBlockTextureProperties])
196197
* This allows resource packs to provide different models/textures for different
@@ -201,14 +202,23 @@ open class RebarBlock private constructor(val block: Block) : Keyed {
201202
*
202203
* @return the item that should be used to display the block's texture
203204
*/
204-
open fun getBlockTextureItem() = defaultItem?.getItemStack()?.let { ItemStackBuilder(it) }?.apply {
205-
editPdc { it.set(rebarBlockTextureEntityKey, RebarSerializers.BOOLEAN, true) }
206-
val properties = NmsAccessor.instance.getStateProperties(block, getBlockTextureProperties())
207-
for ((property, value) in properties) {
208-
addCustomModelDataString("$property=$value")
205+
open fun getBlockTextureItem(): ItemStack? {
206+
val builder = if (defaultItem != null) {
207+
ItemStackBuilder.of(defaultItem.getItemStack())
208+
} else {
209+
ItemStackBuilder.of(schema.material)
210+
.addCustomModelDataString(key.toString())
209211
}
210-
set(DataComponentTypes.ITEM_MODEL, Key.key("air"))
211-
}?.build()
212+
213+
return builder.apply {
214+
editPdc { it.set(rebarBlockTextureEntityKey, RebarSerializers.BOOLEAN, true) }
215+
val properties = NmsAccessor.instance.getStateProperties(block, getBlockTextureProperties())
216+
for ((property, value) in properties) {
217+
addCustomModelDataString("$property=$value")
218+
}
219+
set(DataComponentTypes.ITEM_MODEL, Key.key("air"))
220+
}.build()
221+
}
212222

213223
/**
214224
* WAILA is the text that shows up when looking at a block to tell you what the block is.

0 commit comments

Comments
 (0)