Basic crops system
This commit is contained in:
@@ -3,6 +3,7 @@ import { get_sprite_region } from "$/client/sprites.ts";
|
||||
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import { AssetManager } from "$/client/assets.ts";
|
||||
import { ItemStack } from "$/common/inventory.ts";
|
||||
import { block_item_texture, cube_face_texture } from "$/common/block_models.ts";
|
||||
import { draw_text, draw_texture_region, draw_texture_region_skewed, Texture } from "$/client/renderer/mod.ts";
|
||||
|
||||
export function draw_nine_slice(
|
||||
@@ -206,8 +207,12 @@ export function draw_item(item: ItemStack, x: number, y: number) {
|
||||
throw Error(`Didn't find item registry for '${item.type_id}'`);
|
||||
}
|
||||
|
||||
if (item_info?.block_id) {
|
||||
draw_item_block(item, item_info, x, y);
|
||||
const block_info = item_info.block_id
|
||||
? EverythingRegistry.get<BlockRegistry>("blocks", item_info.block_id)
|
||||
: undefined;
|
||||
// blocks that aren't cubes, like plants, show a flat sprite
|
||||
if (block_info && block_item_texture(block_info) === undefined) {
|
||||
draw_item_block(block_info, x, y);
|
||||
} else {
|
||||
draw_item_item(item, item_info, x, y);
|
||||
}
|
||||
@@ -251,30 +256,10 @@ function draw_item_item(item: ItemStack, item_info: ItemRegistry, x: number, y:
|
||||
);
|
||||
}
|
||||
|
||||
function draw_item_block(_item: ItemStack, item_info: ItemRegistry, x: number, y: number) {
|
||||
const block_info = EverythingRegistry.get<BlockRegistry>("blocks", item_info.block_id!);
|
||||
|
||||
if (!block_info) throw new Error(`no textures for ${item_info.block_id}`);
|
||||
|
||||
let front_texture = "engine:missing";
|
||||
let top_texture = "engine:missing";
|
||||
let left_texture = "engine:missing";
|
||||
|
||||
const textures = block_info.textures;
|
||||
|
||||
if (typeof textures === "string") {
|
||||
front_texture = textures;
|
||||
top_texture = textures;
|
||||
left_texture = textures;
|
||||
} else if ("top" in textures && "bottom" in textures && "side" in textures) {
|
||||
top_texture = textures.top;
|
||||
front_texture = textures.side;
|
||||
left_texture = textures.side;
|
||||
} else if ("front" in textures && "side" in textures) {
|
||||
top_texture = textures.side;
|
||||
front_texture = textures.front;
|
||||
left_texture = textures.side;
|
||||
}
|
||||
function draw_item_block(block_info: BlockRegistry, x: number, y: number) {
|
||||
const top_texture = cube_face_texture(block_info, "top");
|
||||
const front_texture = cube_face_texture(block_info, "front");
|
||||
const left_texture = cube_face_texture(block_info, "side");
|
||||
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user