Slim skins
This commit is contained in:
@@ -8,6 +8,8 @@ export abstract class Player extends Entity {
|
||||
name: string;
|
||||
// undefined draws the default skin
|
||||
skin: Texture | undefined;
|
||||
// 3 pixel wide arms, for skins made for them
|
||||
slim = false;
|
||||
#skin_version = 0;
|
||||
|
||||
// how far the limbs have swung and how hard they swing (0 to 1), like minecraft's WalkAnimationState
|
||||
@@ -21,7 +23,7 @@ export abstract class Player extends Entity {
|
||||
}
|
||||
|
||||
// a base64 png from the server, or undefined for the default. the old skin stays until the new one is decoded
|
||||
async set_skin(skin: string | undefined) {
|
||||
async set_skin(skin: string | undefined, slim = false) {
|
||||
const version = ++this.#skin_version;
|
||||
const texture = skin ? await decode_skin(skin) : undefined;
|
||||
if (version !== this.#skin_version) {
|
||||
@@ -31,6 +33,7 @@ export abstract class Player extends Entity {
|
||||
}
|
||||
this.skin?.tex.destroy();
|
||||
this.skin = texture;
|
||||
this.slim = slim;
|
||||
}
|
||||
|
||||
// after moving each tick. full speed is 5 blocks per second, a bit faster than walking
|
||||
|
||||
@@ -21,7 +21,7 @@ export class RemotePlayer extends Player {
|
||||
this.yaw = info.yaw;
|
||||
this.pitch = info.pitch;
|
||||
if (info.skin) {
|
||||
this.set_skin(info.skin);
|
||||
this.set_skin(info.skin, info.slim);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ export class ClientPacketListener {
|
||||
case "player_skin": {
|
||||
const player = level.entities.get(message.id);
|
||||
if (player instanceof Player) {
|
||||
player.set_skin(message.skin);
|
||||
player.set_skin(message.skin, message.slim);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,29 @@ const PARTS: ModelPart[] = [
|
||||
},
|
||||
];
|
||||
|
||||
// slim (alex) skins have 3 pixel wide arms, half a pixel lower, like minecraft's PlayerModel with slim set
|
||||
const SLIM_ARMS: ModelPart[] = [
|
||||
{
|
||||
name: "right_arm",
|
||||
size: [3, 12, 4],
|
||||
pivot: [5, 21.5, 0],
|
||||
from: [-1, -10, -2],
|
||||
texture: [40, 16],
|
||||
overlay: [40, 32],
|
||||
inflate: 0.25,
|
||||
},
|
||||
{
|
||||
name: "left_arm",
|
||||
size: [3, 12, 4],
|
||||
pivot: [-5, 21.5, 0],
|
||||
from: [-2, -10, -2],
|
||||
texture: [32, 48],
|
||||
overlay: [48, 48],
|
||||
inflate: 0.25,
|
||||
},
|
||||
];
|
||||
const SLIM_PARTS = PARTS.map((part) => SLIM_ARMS.find((arm) => arm.name === part.name) ?? part);
|
||||
|
||||
// a box's faces, like minecraft's ModelPart.Cube. `rect` is where the face is in the box's texture, which is laid
|
||||
// out as in a skin: the top and bottom above the sides (right, front, left, back). corners go counter clockwise from
|
||||
// outside as [x, y, z, u, v], 0 for the low end and 1 for the high one
|
||||
@@ -139,7 +162,7 @@ export function render_player(player: Player, skin: Texture, partial_tick: numbe
|
||||
left_leg: -swing * 1.4,
|
||||
};
|
||||
|
||||
for (const part of PARTS) {
|
||||
for (const part of player.slim ? SLIM_PARTS : PARTS) {
|
||||
const sin = Math.sin(angles[part.name]);
|
||||
const cos = Math.cos(angles[part.name]);
|
||||
const [pivot_x, pivot_y, pivot_z] = part.pivot;
|
||||
|
||||
Reference in New Issue
Block a user