Add sell value for every block and item in the game, crazy
This commit is contained in:
+15
-3
@@ -98,7 +98,8 @@ export interface SpawnJson {
|
||||
|
||||
export interface ItemJson {
|
||||
id: string;
|
||||
texture: string;
|
||||
// without one it isn't a new item, it fills in the item of the mod's block with this id, see add_to_block_item
|
||||
texture?: string;
|
||||
// data key -> texture, see ItemRegistry.data_textures
|
||||
data_textures?: Record<string, string>;
|
||||
// tier and speed default to 0 and 2
|
||||
@@ -352,7 +353,18 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson {
|
||||
}
|
||||
|
||||
export function item_from_json(json: ItemJson): ItemRegistry {
|
||||
const item: ItemRegistry = { texture_id: json.texture };
|
||||
if (json.texture === undefined) throw new Error(`${json.id} has no texture and isn't a block's item`);
|
||||
return { texture_id: json.texture, ...item_fields(json) };
|
||||
}
|
||||
|
||||
// an item json without a texture: what it sets replaces what the block's item has, the rest stays
|
||||
export function add_to_block_item(json: ItemJson, item: ItemRegistry) {
|
||||
Object.assign(item, item_fields(json));
|
||||
}
|
||||
|
||||
// everything but the texture
|
||||
function item_fields(json: ItemJson): Partial<ItemRegistry> {
|
||||
const item: Partial<ItemRegistry> = {};
|
||||
if (json.data_textures !== undefined) item.data_textures = json.data_textures;
|
||||
if (json.tool !== undefined) item.tool = { tier: 0, speed: 2, ...json.tool };
|
||||
if (json.places !== undefined) item.block_id = json.places;
|
||||
@@ -700,7 +712,7 @@ function is_whole(value: unknown): value is number {
|
||||
export function validate_item(json: unknown): Problems {
|
||||
if (!is_object(json)) return ["item must be an object"];
|
||||
const problems = validate_id(json.id, "id");
|
||||
problems.push(...validate_id(json.texture, "texture"));
|
||||
if (json.texture !== undefined) problems.push(...validate_id(json.texture, "texture"));
|
||||
if (json.data_textures !== undefined) {
|
||||
if (!is_object(json.data_textures)) problems.push("data_textures must be { data key: texture id }");
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user