Remove duplicate code
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
// facing out of the screen, the body turned a little toward the mouse and the head turned and tilted more, with what
|
||||
// they wear, like their curios. the gui has no depth buffer, so the faces are drawn back to front with the ones facing
|
||||
// away left out, like 3d items in slots
|
||||
import { flush_batch, get_current_texture, push_vertex, set_current_texture, type Texture } from "../renderer/mod.ts";
|
||||
import { push_vertex, type Texture, use_texture } from "../renderer/mod.ts";
|
||||
import type { ItemStack } from "$/common/inventory.ts";
|
||||
import { AssetManager } from "../assets.ts";
|
||||
import { rotation_around } from "./model_math.ts";
|
||||
@@ -102,10 +102,7 @@ export function draw_gui_player(
|
||||
// blocks to skin pixels to the screen, y down
|
||||
const scale = 16 * pixel;
|
||||
for (const { vertices, texture } of faces) {
|
||||
if (get_current_texture() !== texture.tex) {
|
||||
flush_batch();
|
||||
set_current_texture(texture.tex);
|
||||
}
|
||||
use_texture(texture.tex);
|
||||
for (const [vx, vy, , u, v, r, g, b] of vertices) {
|
||||
push_vertex(x + vx * scale, feet_y - vy * scale, 0, u, v, r, g, b, 1);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,14 @@ import { mat4, vec3 } from "gl-matrix";
|
||||
import type { ItemStack } from "$/common/inventory.ts";
|
||||
import { AssetManager } from "$/client/assets.ts";
|
||||
import type { LocalPlayer } from "$/client/entity/local_player.ts";
|
||||
import { begin_view_model, end_mode_3d, flush_batch, set_current_texture, Texture } from "$/client/renderer/mod.ts";
|
||||
import {
|
||||
begin_view_model,
|
||||
end_mode_3d,
|
||||
flush_batch,
|
||||
set_current_texture,
|
||||
Texture,
|
||||
use_texture,
|
||||
} from "$/client/renderer/mod.ts";
|
||||
import { item_block, push_item } from "./item_renderer.ts";
|
||||
import { push_cube, type Vec3 } from "./player_renderer.ts";
|
||||
import { right_arm } from "./player_model.ts";
|
||||
@@ -69,8 +76,7 @@ export class HandRenderer {
|
||||
push_cube(skin, arm, arm.overlay, arm.inflate, transform, tint);
|
||||
// what's worn on it goes over it, from the atlas
|
||||
if (player.worn.length > 0) {
|
||||
flush_batch();
|
||||
set_current_texture(AssetManager.instance.get<Texture>("bworld:textures").tex);
|
||||
use_texture(AssetManager.instance.get<Texture>("bworld:textures").tex);
|
||||
render_worn_arm(player, transform, tint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
push_vertex,
|
||||
set_current_texture,
|
||||
Texture,
|
||||
use_texture,
|
||||
view_projection,
|
||||
white_tex,
|
||||
} from "$/client/renderer/mod.ts";
|
||||
@@ -123,10 +124,7 @@ export class LevelRenderer {
|
||||
for (const entity of level.entities.values()) {
|
||||
if (entity !== camera_entity && entity instanceof RemotePlayer) {
|
||||
const skin = entity.skin ?? default_skin;
|
||||
if (get_current_texture() !== skin.tex) {
|
||||
flush_batch();
|
||||
set_current_texture(skin.tex);
|
||||
}
|
||||
use_texture(skin.tex);
|
||||
const tint = entity_tint(entity, partial_tick, entity.hurt_time > 0 ? HURT_TINT : undefined);
|
||||
const pose = player_pose(entity, partial_tick);
|
||||
render_player(skin, pose, tint);
|
||||
|
||||
@@ -21,11 +21,9 @@ import {
|
||||
draw_text,
|
||||
draw_texture_region,
|
||||
draw_texture_region_skewed,
|
||||
flush_batch,
|
||||
get_current_texture,
|
||||
push_vertex,
|
||||
set_current_texture,
|
||||
Texture,
|
||||
use_texture,
|
||||
} from "$/client/renderer/mod.ts";
|
||||
|
||||
// the corners keep their size (times scale), the edges stretch along and the middle fills the rest, like minecraft's
|
||||
@@ -163,10 +161,7 @@ const ICON_VIEW = [-1, 1, -1];
|
||||
// a block's item_model in a slot: its faces that face the viewer, back to front
|
||||
function draw_item_model(block_info: BlockRegistry, quads: BakedQuad[], x: number, y: number) {
|
||||
const atlas = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
if (get_current_texture() !== atlas.tex) {
|
||||
flush_batch();
|
||||
set_current_texture(atlas.tex);
|
||||
}
|
||||
use_texture(atlas.tex);
|
||||
const project = item_projection(x, y);
|
||||
const toward_viewer = (p: number[]) => p[0] * ICON_VIEW[0] + p[1] * ICON_VIEW[1] + p[2] * ICON_VIEW[2];
|
||||
const visible = quads
|
||||
|
||||
Reference in New Issue
Block a user