1+ import type { ItemComponentsProvider } from 'deepslate'
12import { NbtByte , NbtDouble , NbtLong } from 'deepslate'
23import type { Random } from 'deepslate/core'
34import { Identifier , ItemStack , LegacyRandom } from 'deepslate/core'
@@ -20,7 +21,7 @@ const StackMixers = {
2021
2122type StackMixer = keyof typeof StackMixers
2223
23- interface LootOptions {
24+ interface LootOptions extends ItemComponentsProvider {
2425 version : VersionId ,
2526 seed : bigint ,
2627 luck : number ,
@@ -32,7 +33,6 @@ interface LootOptions {
3233 getPredicate ( id : string ) : any ,
3334 getEnchantments ( ) : Map < string , any > ,
3435 getEnchantmentTag ( id : string ) : string [ ] ,
35- getBaseComponents ( id : string ) : Map < string , NbtTag > ,
3636}
3737
3838interface LootContext extends LootOptions {
@@ -235,12 +235,12 @@ function createItem(entry: any, consumer: ItemConsumer, ctx: LootContext) {
235235 switch ( type ) {
236236 case 'item' :
237237 const id = Identifier . parse ( entry . name )
238- entryConsumer ( new ResolvedItem ( new ItemStack ( id , 1 ) , ctx . getBaseComponents ( id . toString ( ) ) ) )
238+ entryConsumer ( new ResolvedItem ( new ItemStack ( id , 1 ) , ctx . getItemComponents ( id ) ) )
239239 break
240240 case 'tag' :
241241 ctx . getItemTag ( entry . name ) . forEach ( tagEntry => {
242242 const id = Identifier . parse ( tagEntry )
243- entryConsumer ( new ResolvedItem ( new ItemStack ( id , 1 ) , ctx . getBaseComponents ( id . toString ( ) ) ) )
243+ entryConsumer ( new ResolvedItem ( new ItemStack ( id , 1 ) , ctx . getItemComponents ( id ) ) )
244244 } )
245245 break
246246 case 'loot_table' :
@@ -303,7 +303,7 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
303303 const level = ctx . random . nextInt ( maxLevel - 1 ) + 1
304304 if ( item . is ( 'book' ) ) {
305305 item . id = Identifier . create ( 'enchanted_book' )
306- item . base = ctx . getBaseComponents ( item . id . toString ( ) )
306+ item . base = ctx . getItemComponents ( item . id )
307307 }
308308 updateEnchantments ( item , levels => {
309309 return levels . set ( Identifier . parse ( pick ) . toString ( ) , level )
@@ -314,7 +314,7 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
314314 const selected = selectEnchantments ( item , computeInt ( levels , ctx ) , allowed , ctx )
315315 if ( item . is ( 'book' ) ) {
316316 item . id = Identifier . create ( 'enchanted_book' )
317- item . base = ctx . getBaseComponents ( item . id . toString ( ) )
317+ item . base = ctx . getItemComponents ( item . id )
318318 }
319319 updateEnchantments ( item , levelsMap => {
320320 for ( const { id, lvl } of selected ) {
@@ -437,7 +437,7 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
437437 }
438438 if ( item . is ( 'book' ) ) {
439439 item . id = Identifier . create ( 'enchanted_book' )
440- item . base = ctx . getBaseComponents ( item . id . toString ( ) )
440+ item . base = ctx . getItemComponents ( item . id )
441441 }
442442 updateEnchantments ( item , levels => {
443443 Object . entries ( enchantments ) . forEach ( ( [ id , level ] ) => {
@@ -463,7 +463,7 @@ const LootFunctions: Record<string, (params: any) => LootFunction> = {
463463 set_item : ( { item : newId } ) => ( item , ctx ) => {
464464 if ( typeof newId !== 'string' ) return
465465 item . id = Identifier . parse ( newId )
466- item . base = ctx . getBaseComponents ( item . id . toString ( ) )
466+ item . base = ctx . getItemComponents ( item . id )
467467 } ,
468468 set_loot_table : ( { name, seed } ) => ( item ) => {
469469 item . set ( 'container_loot' , new NbtCompound ( )
0 commit comments