-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement default components and component removal * start update item renderer * implement range dispatch * refactor Color to its own namespace, add fromJson * implement item tints * fix imports * update demo and fixes * fix circular dependencies * add item component string parser * don't error on missing item_model component & map color fix * fix circular dependencies * start special renderer * update from 24w46a changed default component handling again * fix imports * store id in itemstack * implement most special models * improve item registry * implement bundle/selected_item * implement bundle/fullness * remove local_time, fix chest special renderer * minor fixes * add tests * fix defaults of properties and tints * add more tests and a few fixes * undo unnecessary formatting changes * update item_definition url * add changes from 1.21.4-pre1
- Loading branch information
Showing
22 changed files
with
2,185 additions
and
1,045 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
input { | ||
padding: 4px; | ||
margin-left: 8px; | ||
width: 500px; | ||
} | ||
.invalid { | ||
color: #cb0000; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { NbtTag } from "../nbt/index.js" | ||
import { Identifier } from "./index.js" | ||
import { Registry } from "./Registry.js" | ||
|
||
|
||
export class Item { | ||
public static REGISTRY = Registry.createAndRegister<Item>('item') | ||
|
||
constructor( | ||
public components: Map<string, NbtTag> = new Map(), | ||
) { | ||
} | ||
|
||
public getComponent<T>(key: string | Identifier, reader: (tag: NbtTag) => T) { | ||
if (typeof key === 'string') { | ||
key = Identifier.parse(key) | ||
} | ||
const value = this.components.get(key.toString()) | ||
if (value) { | ||
return reader(value) | ||
} | ||
return undefined | ||
} | ||
|
||
public hasComponent(key: string | Identifier) { | ||
if (typeof key === 'string') { | ||
key = Identifier.parse(key) | ||
} | ||
return this.components.has(key.toString()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { NbtByte, NbtCompound, NbtDouble, NbtInt, NbtList, NbtString, NbtTag } from "./index.js" | ||
|
||
export function jsonToNbt(value: unknown): NbtTag { | ||
if (typeof value === 'string') { | ||
return new NbtString(value) | ||
} | ||
if (typeof value === 'number') { | ||
return Number.isInteger(value) ? new NbtInt(value) : new NbtDouble(value) | ||
} | ||
if (typeof value === 'boolean') { | ||
return new NbtByte(value) | ||
} | ||
if (Array.isArray(value)) { | ||
return new NbtList(value.map(jsonToNbt)) | ||
} | ||
if (typeof value === 'object' && value !== null) { | ||
return new NbtCompound( | ||
new Map(Object.entries(value ?? {}) | ||
.map(([k, v]) => [k, jsonToNbt(v)])) | ||
) | ||
} | ||
return new NbtByte(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.