Skip to content

Commit

Permalink
fix nested blocks added using *add* not working
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Aug 26, 2024
1 parent 0f777a9 commit b720584
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/emit/content/blockDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Acceptor } from '@pssbletrngle/pack-resolver'
import { Id, IdInput } from '../../common/id.js'
import CustomEmitter from '../custom.js'
import { BlockDefinition, BlockProperties } from '../../schema/content/blockDefinition.js'
import { ModelRules } from '../assets/models.js'
import { BlockstateRules } from '../assets/blockstates.js'
import { ModelRules } from '../assets/models.js'
import CustomEmitter from '../custom.js'
import { LootRules } from '../data/loot.js'
import { ClearableEmitter } from '../index.js'
import { Acceptor } from '@pssbletrngle/pack-resolver'

export type BlockDefinitionOptions = Readonly<{
blockstate?: boolean
Expand Down
12 changes: 6 additions & 6 deletions src/emit/content/innerBlockDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { AbstractBlockDefinitionRules, BlockDefinitionRules } from './blockDefinition.js'
import { IdInput } from '../../common/id.js'
import { BlockDefinition } from '../../schema/content/blockDefinition.js'
import { BlockstateRules } from '../assets/blockstates.js'
import { ModelRules } from '../assets/models.js'
import { LootRules } from '../data/loot.js'
import { BlockstateRules } from '../assets/blockstates.js'
import { BlockDefinition } from '../../schema/content/blockDefinition.js'
import { IdInput } from '../../common/id.js'
import { AbstractBlockDefinitionRules, BlockDefinitionRules } from './blockDefinition.js'

/* eslint-disable @typescript-eslint/no-explicit-any */

class InnerBlockDefinitionRules extends AbstractBlockDefinitionRules {
add<T extends BlockDefinition>(id: IdInput, definition: T): T {
return definition
add<T extends BlockDefinition>(id: IdInput | T, definition?: T): T {
return definition ?? (id as T)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/schema/content/blockDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type BlockProperties = Readonly<{
material: string
material?: string
strength?: number
}>

Expand Down
30 changes: 29 additions & 1 deletion test/content.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import setupLoader from './shared/loaderSetup.js'
import createTestAcceptor from './mock/TestAcceptor.js'
import setupLoader from './shared/loaderSetup.js'

const { loader } = setupLoader({ load: false })

Expand Down Expand Up @@ -68,4 +68,32 @@ describe('integration with content packs mod', () => {
},
})
})

it('uses custom definition types for nested block', async () => {
const acceptor = createTestAcceptor()

loader.content.blocks.basic('example:sapphire_block', { material: 'stone', type: 'example_block' })
loader.content.items.basic('example:sapphire', { type: 'example' })
loader.content.items.blockItem('example:sapphire_ore', {
type: 'example_block_item',
block: blocks =>
blocks.add({
type: 'example_block',
properties: {
material: 'ice',
},
}),
})

await loader.emit(acceptor)

expect(acceptor.jsonAt('content/example/block/sapphire_block.json')).toMatchObject({ type: 'example_block' })
expect(acceptor.jsonAt('content/example/item/sapphire.json')).toMatchObject({ type: 'example' })
expect(acceptor.jsonAt('content/example/item/sapphire_ore.json')).toMatchObject({
type: 'example_block_item',
block: {
type: 'example_block',
},
})
})
})

0 comments on commit b720584

Please sign in to comment.