Basic crops system

This commit is contained in:
2026-09-25 22:49:27 -03:00
parent ef25e66f08
commit 099811670f
22 changed files with 985 additions and 178 deletions
+5 -13
View File
@@ -4,6 +4,7 @@ import { AssetManager } from "$/client/assets.ts";
import { get_sprite_region } from "$/client/sprites.ts";
import type { ItemEntity } from "$/client/entity/item_entity.ts";
import { push_vertex, Texture } from "$/client/renderer/mod.ts";
import { block_item_texture, cube_face_texture } from "$/common/block_models.ts";
// how big items on the ground are drawn, minecraft's ground transform
const BLOCK_SCALE = 0.25;
@@ -40,9 +41,11 @@ function copies(amount: number) {
export function render_item_entity(entity: ItemEntity, partial_tick: number) {
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
const item_info = EverythingRegistry.get<ItemRegistry>("items", entity.item.type_id);
const block_info = item_info?.block_id
// blocks that aren't cubes, like plants, are drawn as their item's sprite
let block_info = item_info?.block_id
? EverythingRegistry.get<BlockRegistry>("blocks", item_info.block_id)
: undefined;
if (block_info && block_item_texture(block_info) !== undefined) block_info = undefined;
// spinning and bobbing, like minecraft's ItemEntityRenderer
const time = entity.age + partial_tick;
@@ -79,7 +82,7 @@ function push_block(
};
for (const face of CUBE_FACES) {
const region = get_sprite_region(block_face_texture(block, face.texture));
const region = get_sprite_region(cube_face_texture(block, face.texture));
push_textured_quad(atlas, region, face.corners.map(([cx, cy, cz]) => corner(cx, cy, cz)), face.shade);
}
}
@@ -121,17 +124,6 @@ function push_textured_quad(atlas: Texture, region: { x: number; y: number }, co
}
}
function block_face_texture(block: BlockRegistry, face: "top" | "bottom" | "front" | "side") {
const textures = block.textures;
if (typeof textures === "string") {
return textures;
}
if ("top" in textures) {
return face === "top" ? textures.top : face === "bottom" ? textures.bottom : textures.side;
}
return face === "front" ? textures.front : textures.side;
}
function item_texture(entity: ItemEntity, item_info: ItemRegistry | undefined) {
const texture_id = item_info?.texture_id;
if (typeof texture_id === "function") {