Skip to content

Commit

Permalink
improve item registry
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsjo committed Nov 14, 2024
1 parent bbd3983 commit 171e3e3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion demo/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Promise.all([
Object.keys(item_components[id]).forEach(c_id => {
components.set(c_id, jsonToNbt(item_components[id][c_id]))
})
Item.getRegistry().register(Identifier.create(id), new Item(components))
Item.REGISTRY.register(Identifier.create(id), new Item(components))
})

const atlasCanvas = document.createElement('canvas')
Expand Down
12 changes: 3 additions & 9 deletions src/core/Item.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { NbtTag } from "../nbt/index.js"
import { Identifier, Registry } from "./index.js"
import { Identifier } from "./index.js"
import { Registry } from "./Registry.js"


export class Item {
private static REGISTRY: Registry<Item>

public static getRegistry() {
if (this.REGISTRY === undefined){
this.REGISTRY = Registry.createAndRegister<Item>('item')
}
return this.REGISTRY
}
public static REGISTRY = Registry.createAndRegister<Item>('item')

constructor(
public components: Map<string, NbtTag> = new Map(),
Expand Down
2 changes: 1 addition & 1 deletion src/core/ItemStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ItemStack {
public count: number,
public readonly components: Map<string, NbtTag> = new Map(),
) {
this.item = Holder.reference(Item.getRegistry(), id, false)
this.item = Holder.reference(Item.REGISTRY, id, false)
}

public getComponent<T>(key: string | Identifier, reader: (tag: NbtTag) => T, includeDefaultComponents: boolean = true): T | undefined {
Expand Down

0 comments on commit 171e3e3

Please sign in to comment.