Jester time

This commit is contained in:
2026-11-21 23:07:42 -03:00
parent 0c711b8163
commit f308ab52f1
14 changed files with 3317 additions and 395 deletions
+6
View File
@@ -180,6 +180,12 @@ export interface LivingRef {
// cause is for events and the death message, like "magic"
damage(amount: number, cause?: string): void;
heal(amount: number): void;
// its stats, like Player's: "cubi:movement_speed", "cubi:attack_damage"... a mob's modifiers are saved with it
attribute(id: Id): number;
// replaces one with the same id on that attribute
add_modifier(attribute: Id, modifier: AttributeModifier): void;
// whether it had it
remove_modifier(attribute: Id, id: string): boolean;
}
export interface ComponentRegistry {
+4
View File
@@ -82,6 +82,10 @@ interface LivingRef {
effect(id: Id): { readonly amplifier: number; readonly duration: number } | undefined;
damage(amount: number, cause?: string): void; // cause is for events and the death message
heal(amount: number): void;
// its attributes and their modifiers, like a player's (see players.md). a mob's modifiers are saved with it
attribute(id: Id): number;
add_modifier(attribute: Id, modifier: AttributeModifier): void;
remove_modifier(attribute: Id, id: string): boolean;
}
```
+10 -1
View File
@@ -169,10 +169,19 @@ interface MobRef extends LivingRef {
look_at(x: number, y: number, z: number): void; // for a couple of ticks, so call it every tick
jump(): void; // this tick, or swims up in water
attack(target: Player | MobRef): void; // swings and hits with its attack_damage
// what clients see of its state, for its animator, see Animators
get_client_data<T>(field: string): T | undefined;
set_client_data(field: string, value: unknown): void;
}
```
Each mob has one `MobRef`, so `mob.target === player` works.
Each mob has one `MobRef`, so `mob.target === player` works. Like any living entity, it has attributes that modifiers
change, so a mob that speeds up the longer it chases can do it with a modifier on its speed:
```ts
mob.add_modifier("cubi:movement_speed", { id: "my_mod:rush", amount: 0.4, operation: "add_multiplied_total" });
mob.remove_modifier("cubi:movement_speed", "my_mod:rush");
```
## Getting Around
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -4,14 +4,14 @@
"id": "dangerous_business:jester",
"model": "dangerous_business:jester",
"texture": "dangerous_business:jester",
"behavior": "dangerous_business:coilhead",
"behavior": "dangerous_business:jester",
"width": 0.8,
"height": 1.9,
"max_health": 40,
"movement_speed": 0.23,
"jumps": false,
"max_fall": 0,
"attack_damage": 5,
"attack_damage": 99999,
"physical_shielding": 3
}
}
+126 -60
View File
@@ -20,12 +20,24 @@
"parent": "coilhead",
"pivot": [0, 0, 0],
"cubes": [
{"origin": [-4, 19, 1.3], "size": [8, 5, 6], "uv": [0, 25]},
{"origin": [-4.5, 24, 0.8], "size": [9, 3, 7], "uv": [0, 15]},
{"origin": [-5.5, 27, 0.3], "size": [11, 7, 8], "uv": [0, 0]},
{"origin": [-20.5, 24, 2.3], "size": [8, 3, 3], "pivot": [0, 0, 0], "rotation": [0, 0, 45], "uv": [35, 12]},
{"origin": [11.5, 24, 2.3], "size": [9, 3, 3], "pivot": [0, 0, 0], "rotation": [0, 0, -45], "uv": [30, 0]},
{"origin": [-4.5, 33.3, 1.3], "size": [9, 2, 6], "uv": [26, 19]}
{ "origin": [-4, 19, 1.3], "size": [8, 5, 6], "uv": [0, 25] },
{ "origin": [-4.5, 24, 0.8], "size": [9, 3, 7], "uv": [0, 15] },
{ "origin": [-5.5, 27, 0.3], "size": [11, 7, 8], "uv": [0, 0] },
{
"origin": [-20.5, 24, 2.3],
"size": [8, 3, 3],
"pivot": [0, 0, 0],
"rotation": [0, 0, 45],
"uv": [35, 12]
},
{
"origin": [11.5, 24, 2.3],
"size": [9, 3, 3],
"pivot": [0, 0, 0],
"rotation": [0, 0, -45],
"uv": [30, 0]
},
{ "origin": [-4.5, 33.3, 1.3], "size": [9, 2, 6], "uv": [26, 19] }
]
},
{
@@ -34,11 +46,38 @@
"pivot": [3, 20, 4.7],
"rotation": [7.5, 0, 0],
"cubes": [
{"origin": [1.5, 0, -2], "size": [3, 2, 3], "uv": [33, 55]},
{"origin": [1.5, 0, 0.5], "size": [3, 2, 3], "inflate": -0.1, "pivot": [-2.5, 0, 0], "rotation": [17.5, 0, 0], "uv": [21, 54]},
{"origin": [1.5, 0.9, 1.5], "size": [3, 7, 3], "pivot": [-2.5, -0.2, 0], "rotation": [5, 0, 0], "uv": [44, 39]},
{"origin": [1.5, 7.8, 0.7], "size": [3, 5, 3], "inflate": 0.2, "pivot": [-2.5, -0.2, 0], "rotation": [0, 0, 0], "uv": [12, 48]},
{"origin": [1, 12.5, -3.7], "size": [4, 8, 4], "inflate": 0.2, "pivot": [-2.5, -0.2, 0], "rotation": [-17.5, 0, 0], "uv": [16, 36]}
{ "origin": [1.5, 0, -2], "size": [3, 2, 3], "uv": [33, 55] },
{
"origin": [1.5, 0, 0.5],
"size": [3, 2, 3],
"inflate": -0.1,
"pivot": [-2.5, 0, 0],
"rotation": [17.5, 0, 0],
"uv": [21, 54]
},
{
"origin": [1.5, 0.9, 1.5],
"size": [3, 7, 3],
"pivot": [-2.5, -0.2, 0],
"rotation": [5, 0, 0],
"uv": [44, 39]
},
{
"origin": [1.5, 7.8, 0.7],
"size": [3, 5, 3],
"inflate": 0.2,
"pivot": [-2.5, -0.2, 0],
"rotation": [0, 0, 0],
"uv": [12, 48]
},
{
"origin": [1, 12.5, -3.7],
"size": [4, 8, 4],
"inflate": 0.2,
"pivot": [-2.5, -0.2, 0],
"rotation": [-17.5, 0, 0],
"uv": [16, 36]
}
]
},
{
@@ -47,8 +86,8 @@
"pivot": [3.8, 6, 1.7],
"rotation": [64.46949, 11.31255, -5.35254],
"cubes": [
{"origin": [2.8, 6, 0.7], "size": [1, 2, 1], "uv": [0, 3]},
{"origin": [2.3, 8, 0.2], "size": [2, 1, 2], "uv": [0, 0]}
{ "origin": [2.8, 6, 0.7], "size": [1, 2, 1], "uv": [0, 3] },
{ "origin": [2.3, 8, 0.2], "size": [2, 1, 2], "uv": [0, 0] }
]
},
{
@@ -57,8 +96,8 @@
"pivot": [4.5, 14.7, 1.9],
"rotation": [74.30716, -16.88547, 4.6653],
"cubes": [
{"origin": [3.5, 14.7, 0.9], "size": [1, 2, 1], "uv": [0, 3]},
{"origin": [3, 16.7, 0.4], "size": [2, 1, 2], "uv": [0, 0]}
{ "origin": [3.5, 14.7, 0.9], "size": [1, 2, 1], "uv": [0, 3] },
{ "origin": [3, 16.7, 0.4], "size": [2, 1, 2], "uv": [0, 0] }
]
},
{
@@ -67,11 +106,38 @@
"pivot": [-3, 20, 4.7],
"rotation": [7.5, 0, 0],
"cubes": [
{"origin": [-4.5, 0, -2], "size": [3, 2, 3], "uv": [53, 24]},
{"origin": [-4.5, 0, 0.5], "size": [3, 2, 3], "inflate": -0.1, "pivot": [2.5, 0, 0], "rotation": [17.5, 0, 0], "uv": [50, 7]},
{"origin": [-4.5, 0.9, 1.5], "size": [3, 7, 3], "pivot": [2.5, -0.2, 0], "rotation": [5, 0, 0], "uv": [32, 39]},
{"origin": [-4.5, 7.8, 0.7], "size": [3, 5, 3], "inflate": 0.2, "pivot": [2.5, -0.2, 0], "rotation": [0, 0, 0], "uv": [0, 48]},
{"origin": [-5, 12.5, -3.7], "size": [4, 8, 4], "inflate": 0.2, "pivot": [2.5, -0.2, 0], "rotation": [-17.5, 0, 0], "uv": [0, 36]}
{ "origin": [-4.5, 0, -2], "size": [3, 2, 3], "uv": [53, 24] },
{
"origin": [-4.5, 0, 0.5],
"size": [3, 2, 3],
"inflate": -0.1,
"pivot": [2.5, 0, 0],
"rotation": [17.5, 0, 0],
"uv": [50, 7]
},
{
"origin": [-4.5, 0.9, 1.5],
"size": [3, 7, 3],
"pivot": [2.5, -0.2, 0],
"rotation": [5, 0, 0],
"uv": [32, 39]
},
{
"origin": [-4.5, 7.8, 0.7],
"size": [3, 5, 3],
"inflate": 0.2,
"pivot": [2.5, -0.2, 0],
"rotation": [0, 0, 0],
"uv": [0, 48]
},
{
"origin": [-5, 12.5, -3.7],
"size": [4, 8, 4],
"inflate": 0.2,
"pivot": [2.5, -0.2, 0],
"rotation": [-17.5, 0, 0],
"uv": [0, 36]
}
]
},
{
@@ -80,8 +146,8 @@
"pivot": [-3.2, 3.2, 1.8],
"rotation": [75.65143, 69.40933, -13.46639],
"cubes": [
{"origin": [-4.2, 3.2, 0.8], "size": [1, 2, 1], "uv": [0, 3]},
{"origin": [-4.7, 5.2, 0.3], "size": [2, 1, 2], "uv": [0, 0]}
{ "origin": [-4.2, 3.2, 0.8], "size": [1, 2, 1], "uv": [0, 3] },
{ "origin": [-4.7, 5.2, 0.3], "size": [2, 1, 2], "uv": [0, 0] }
]
},
{
@@ -90,8 +156,8 @@
"pivot": [-1.8, 15, 1.5],
"rotation": [63.60782, 18.05776, -8.74472],
"cubes": [
{"origin": [-2.8, 15, 0.5], "size": [1, 2, 1], "uv": [0, 3]},
{"origin": [-3.3, 17, 0], "size": [2, 1, 2], "uv": [0, 0]}
{ "origin": [-2.8, 15, 0.5], "size": [1, 2, 1], "uv": [0, 3] },
{ "origin": [-3.3, 17, 0], "size": [2, 1, 2], "uv": [0, 0] }
]
},
{
@@ -100,8 +166,8 @@
"pivot": [-4.1, 19.5, 3.7],
"rotation": [29.03199, 61.09544, -57.62441],
"cubes": [
{"origin": [-5.1, 19.5, 2.7], "size": [1, 2, 1], "uv": [0, 3]},
{"origin": [-5.6, 21.5, 2.2], "size": [2, 1, 2], "uv": [0, 0]}
{ "origin": [-5.1, 19.5, 2.7], "size": [1, 2, 1], "uv": [0, 3] },
{ "origin": [-5.6, 21.5, 2.2], "size": [2, 1, 2], "uv": [0, 0] }
]
},
{
@@ -109,26 +175,26 @@
"parent": "body",
"pivot": [0, 35.3, 4.5],
"cubes": [
{"origin": [1.5, 35.3, 1.8], "size": [1, 1, 5], "uv": [52, 33]},
{"origin": [-2.4, 36.2, 1.6], "size": [1, 1, 5], "uv": [51, 44]},
{"origin": [-2.7, 35.8, 5.7], "size": [5, 1, 1], "uv": [56, 4]},
{"origin": [-2.7, 36.6, 1.7], "size": [5, 1, 1], "uv": [56, 2]},
{"origin": [-2.7, 38.6, 1.7], "size": [5, 1, 1], "uv": [0, 56]},
{"origin": [1.5, 37.3, 1.8], "size": [1, 1, 5], "uv": [50, 18]},
{"origin": [-2.7, 37.8, 5.7], "size": [5, 1, 1], "uv": [56, 0]},
{"origin": [-2.4, 38.2, 1.6], "size": [1, 1, 5], "uv": [50, 50]},
{"origin": [-2.7, 40.6, 1.7], "size": [5, 1, 1], "uv": [53, 39]},
{"origin": [1.5, 39.3, 1.8], "size": [1, 1, 5], "uv": [31, 49]},
{"origin": [-2.7, 39.8, 5.7], "size": [5, 1, 1], "uv": [54, 12]},
{"origin": [-2.4, 40.2, 1.6], "size": [1, 1, 5], "uv": [43, 49]},
{"origin": [-2.7, 42.6, 1.7], "size": [5, 1, 1], "uv": [30, 6]},
{"origin": [1.5, 41.3, 1.8], "size": [1, 1, 5], "uv": [24, 48]},
{"origin": [-2.7, 41.8, 5.7], "size": [5, 1, 1], "uv": [53, 29]},
{"origin": [-2.4, 42.2, 1.6], "size": [1, 1, 5], "uv": [49, 1]},
{"origin": [-2.7, 44.6, 1.7], "size": [5, 1, 1], "uv": [22, 27]},
{"origin": [1.5, 43.3, 1.8], "size": [1, 1, 5], "uv": [38, 6]},
{"origin": [-2.7, 43.8, 5.7], "size": [5, 1, 1], "uv": [22, 29]},
{"origin": [-2.4, 44.2, 1.6], "size": [1, 1, 5], "uv": [46, 27]}
{ "origin": [1.5, 35.3, 1.8], "size": [1, 1, 5], "uv": [52, 33] },
{ "origin": [-2.4, 36.2, 1.6], "size": [1, 1, 5], "uv": [51, 44] },
{ "origin": [-2.7, 35.8, 5.7], "size": [5, 1, 1], "uv": [56, 4] },
{ "origin": [-2.7, 36.6, 1.7], "size": [5, 1, 1], "uv": [56, 2] },
{ "origin": [-2.7, 38.6, 1.7], "size": [5, 1, 1], "uv": [0, 56] },
{ "origin": [1.5, 37.3, 1.8], "size": [1, 1, 5], "uv": [50, 18] },
{ "origin": [-2.7, 37.8, 5.7], "size": [5, 1, 1], "uv": [56, 0] },
{ "origin": [-2.4, 38.2, 1.6], "size": [1, 1, 5], "uv": [50, 50] },
{ "origin": [-2.7, 40.6, 1.7], "size": [5, 1, 1], "uv": [53, 39] },
{ "origin": [1.5, 39.3, 1.8], "size": [1, 1, 5], "uv": [31, 49] },
{ "origin": [-2.7, 39.8, 5.7], "size": [5, 1, 1], "uv": [54, 12] },
{ "origin": [-2.4, 40.2, 1.6], "size": [1, 1, 5], "uv": [43, 49] },
{ "origin": [-2.7, 42.6, 1.7], "size": [5, 1, 1], "uv": [30, 6] },
{ "origin": [1.5, 41.3, 1.8], "size": [1, 1, 5], "uv": [24, 48] },
{ "origin": [-2.7, 41.8, 5.7], "size": [5, 1, 1], "uv": [53, 29] },
{ "origin": [-2.4, 42.2, 1.6], "size": [1, 1, 5], "uv": [49, 1] },
{ "origin": [-2.7, 44.6, 1.7], "size": [5, 1, 1], "uv": [22, 27] },
{ "origin": [1.5, 43.3, 1.8], "size": [1, 1, 5], "uv": [38, 6] },
{ "origin": [-2.7, 43.8, 5.7], "size": [5, 1, 1], "uv": [22, 29] },
{ "origin": [-2.4, 44.2, 1.6], "size": [1, 1, 5], "uv": [46, 27] }
]
},
{
@@ -136,7 +202,7 @@
"parent": "spring",
"pivot": [0, 45.5, 2.2],
"cubes": [
{"origin": [-3.2, 45.4, 1.3], "size": [6, 6, 6], "uv": [28, 27]}
{ "origin": [-3.2, 45.4, 1.3], "size": [6, 6, 6], "uv": [28, 27] }
]
},
{
@@ -145,8 +211,8 @@
"pivot": [-0.6, 22.4, 2.2],
"rotation": [82.32005, 12.39135, -1.6575],
"cubes": [
{"origin": [-1.6, 22.4, 1.2], "size": [1, 2, 1], "uv": [0, 3]},
{"origin": [-2.1, 24.4, 0.7], "size": [2, 1, 2], "uv": [0, 0]}
{ "origin": [-1.6, 22.4, 1.2], "size": [1, 2, 1], "uv": [0, 3] },
{ "origin": [-2.1, 24.4, 0.7], "size": [2, 1, 2], "uv": [0, 0] }
]
},
{
@@ -155,8 +221,8 @@
"pivot": [3.9, 31.6, 1.6],
"rotation": [97.7614, -14.8687, -2.00307],
"cubes": [
{"origin": [2.9, 31.6, 0.6], "size": [1, 2, 1], "uv": [0, 3]},
{"origin": [2.4, 33.6, 0.1], "size": [2, 1, 2], "uv": [0, 0]}
{ "origin": [2.9, 31.6, 0.6], "size": [1, 2, 1], "uv": [0, 3] },
{ "origin": [2.4, 33.6, 0.1], "size": [2, 1, 2], "uv": [0, 0] }
]
},
{
@@ -165,8 +231,8 @@
"pivot": [0.9, 31.6, 7.4],
"rotation": [-97.7614, 14.8687, -2.00307],
"cubes": [
{"origin": [-0.1, 31.6, 7.4], "size": [1, 2, 1], "uv": [0, 3]},
{"origin": [-0.6, 33.6, 6.9], "size": [2, 1, 2], "uv": [0, 0]}
{ "origin": [-0.1, 31.6, 7.4], "size": [1, 2, 1], "uv": [0, 3] },
{ "origin": [-0.6, 33.6, 6.9], "size": [2, 1, 2], "uv": [0, 0] }
]
},
{
@@ -175,8 +241,8 @@
"pivot": [-1.5, 22.5, 6.2],
"rotation": [-97.7614, 14.8687, -2.00307],
"cubes": [
{"origin": [-2.5, 22.5, 6.2], "size": [1, 2, 1], "uv": [0, 3]},
{"origin": [-3, 24.5, 5.7], "size": [2, 1, 2], "uv": [0, 0]}
{ "origin": [-2.5, 22.5, 6.2], "size": [1, 2, 1], "uv": [0, 3] },
{ "origin": [-3, 24.5, 5.7], "size": [2, 1, 2], "uv": [0, 0] }
]
},
{
@@ -185,8 +251,8 @@
"pivot": [-3.4, 33.5, 1.2],
"rotation": [98.44236, 27.24513, 3.88714],
"cubes": [
{"origin": [-4.4, 33.5, 0.2], "size": [1, 2, 1], "uv": [0, 3]},
{"origin": [-4.9, 35.5, -0.3], "size": [2, 1, 2], "uv": [0, 0]}
{ "origin": [-4.4, 33.5, 0.2], "size": [1, 2, 1], "uv": [0, 3] },
{ "origin": [-4.9, 35.5, -0.3], "size": [2, 1, 2], "uv": [0, 0] }
]
},
{
@@ -195,11 +261,11 @@
"pivot": [-4, 33.5, 6.1],
"rotation": [10, 0, -30],
"cubes": [
{"origin": [-5, 33.5, 5.1], "size": [1, 2, 1], "uv": [0, 3]},
{"origin": [-5.5, 35.5, 4.6], "size": [2, 1, 2], "uv": [0, 0]}
{ "origin": [-5, 33.5, 5.1], "size": [1, 2, 1], "uv": [0, 3] },
{ "origin": [-5.5, 35.5, 4.6], "size": [2, 1, 2], "uv": [0, 0] }
]
}
]
}
]
}
}
+317 -317
View File
@@ -1,317 +1,317 @@
{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.jester",
"texture_width": 128,
"texture_height": 128,
"visible_bounds_width": 3,
"visible_bounds_height": 3.5,
"visible_bounds_offset": [0, 1.25, 0]
},
"bones": [
{
"name": "root",
"pivot": [0, 0, 0]
},
{
"name": "waist",
"parent": "root",
"pivot": [0, 12, 0]
},
{
"name": "box",
"parent": "waist",
"pivot": [0, 12, 0],
"cubes": [
{
"origin": [-8, 12, -8],
"size": [16, 16, 16],
"uv": {
"north": {"uv": [22, 60], "uv_size": [16, 16]},
"east": {"uv": [0, 64], "uv_size": [16, 16]},
"south": {"uv": [68, 0], "uv_size": [16, 16]},
"west": {"uv": [68, 16], "uv_size": [16, 16]},
"up": {"uv": [68, 32], "uv_size": [16, 16]},
"down": {"uv": [68, 64], "uv_size": [16, -16]}
}
}
]
},
{
"name": "box_lid",
"parent": "box",
"pivot": [0, 28, 8],
"cubes": [
{
"origin": [-8, 28, -8],
"size": [16, 1, 16],
"uv": {
"north": {"uv": [98, 65], "uv_size": [16, 1]},
"east": {"uv": [61, 103], "uv_size": [16, 1]},
"south": {"uv": [103, 102], "uv_size": [16, 1]},
"west": {"uv": [103, 103], "uv_size": [16, 1]},
"up": {"uv": [68, 64], "uv_size": [16, 16]},
"down": {"uv": [16, 92], "uv_size": [16, -16]}
}
}
]
},
{
"name": "tendrils",
"parent": "box",
"pivot": [-0.3709, 28.03888, 1.72961],
"cubes": [
{
"origin": [-4.75, 27, -2],
"size": [8, 28, 7],
"pivot": [-0.75, 27.5, 0.5],
"rotation": [11.5, 0, 0],
"uv": {
"north": {"uv": [84, 66], "uv_size": [8, 28]},
"east": {"uv": [24, 92], "uv_size": [7, 28]},
"south": {"uv": [16, 92], "uv_size": [8, 28]},
"west": {"uv": [84, 94], "uv_size": [7, 28]},
"up": {"uv": [32, 76], "uv_size": [8, 7]},
"down": {"uv": [98, 65], "uv_size": [8, -7]}
}
},
{
"origin": [-6.025, 25.63246, -6.50605],
"size": [12, 28, 0],
"pivot": [-0.75, 39.63246, -7.58105],
"rotation": [12.91186, -8.38903, -9.73581],
"uv": {
"north": {"uv": [44, 0], "uv_size": [12, 28]},
"east": {"uv": [0, 0], "uv_size": [0, 28]},
"south": {"uv": [44, 28], "uv_size": [12, 28]},
"west": {"uv": [0, 0], "uv_size": [0, 28]},
"up": {"uv": [0, 0], "uv_size": [12, 0]},
"down": {"uv": [0, 0], "uv_size": [12, 0]}
}
},
{
"origin": [-6.75, 25.33246, -8.85605],
"size": [12, 28, 0],
"pivot": [-0.75, 39.63246, -7.58105],
"rotation": [169.98699, 25.84107, -179.13668],
"uv": {
"north": {"uv": [56, 0], "uv_size": [12, 28]},
"east": {"uv": [0, 0], "uv_size": [0, 28]},
"south": {"uv": [56, 28], "uv_size": [12, 28]},
"west": {"uv": [0, 0], "uv_size": [0, 28]},
"up": {"uv": [0, 0], "uv_size": [12, 0]},
"down": {"uv": [0, 0], "uv_size": [12, 0]}
}
},
{
"origin": [-5.475, 25.63246, -6.50605],
"size": [12, 28, 0],
"pivot": [-0.75, 39.63246, -7.58105],
"rotation": [15.7096, 19.35594, 8.37709],
"uv": {
"north": {"uv": [44, 56], "uv_size": [12, 28]},
"east": {"uv": [0, 0], "uv_size": [0, 28]},
"south": {"uv": [56, 56], "uv_size": [12, 28]},
"west": {"uv": [0, 0], "uv_size": [0, 28]},
"up": {"uv": [0, 0], "uv_size": [12, 0]},
"down": {"uv": [0, 0], "uv_size": [12, 0]}
}
}
]
},
{
"name": "skull",
"parent": "tendrils",
"pivot": [-0.1784, 51.63803, -2.36963],
"cubes": [
{
"origin": [-11, 44.38084, -20.73926],
"size": [22, 20, 22],
"uv": {
"north": {"uv": [22, 0], "uv_size": [22, 20]},
"east": {"uv": [22, 20], "uv_size": [22, 20]},
"south": {"uv": [22, 40], "uv_size": [22, 20]},
"west": {"uv": [0, 44], "uv_size": [22, 20]},
"up": {"uv": [0, 0], "uv_size": [22, 22]},
"down": {"uv": [0, 44], "uv_size": [22, -22]}
}
},
{
"origin": [-9.375, 47, -19],
"size": [16, 16, 16],
"pivot": [-1.375, 50, -11],
"rotation": [0, 0, 11.75],
"uv": {
"north": {"uv": [0, 80], "uv_size": [16, 16]},
"east": {"uv": [68, 80], "uv_size": [16, 16]},
"south": {"uv": [84, 0], "uv_size": [16, 16]},
"west": {"uv": [84, 16], "uv_size": [16, 16]},
"up": {"uv": [32, 84], "uv_size": [16, 16]},
"down": {"uv": [84, 48], "uv_size": [16, -16]}
}
}
]
},
{
"name": "jaw",
"parent": "skull",
"pivot": [0, 44.18195, -1.85535],
"cubes": [
{
"origin": [-7, 39.68195, -19.85535],
"size": [14, 5, 18],
"uv": {
"north": {"uv": [0, 96], "uv_size": [14, 5]},
"east": {"uv": [62, 96], "uv_size": [18, 5]},
"south": {"uv": [98, 53], "uv_size": [14, 5]},
"west": {"uv": [98, 48], "uv_size": [18, 5]},
"up": {"uv": [48, 84], "uv_size": [14, 18]},
"down": {"uv": [84, 66], "uv_size": [14, -18]}
}
},
{
"origin": [-6.5, 44.68195, -19.35535],
"size": [13, 2, 17],
"uv": {
"north": {"uv": [0, 101], "uv_size": [13, 2]},
"east": {"uv": [91, 100], "uv_size": [17, 2]},
"south": {"uv": [41, 102], "uv_size": [13, 2]},
"west": {"uv": [62, 101], "uv_size": [17, 2]},
"up": {"uv": [92, 66], "uv_size": [13, 17]},
"down": {"uv": [92, 100], "uv_size": [13, -17]}
}
}
]
},
{
"name": "left_arm",
"parent": "box",
"pivot": [8, 15, 0],
"cubes": [
{
"origin": [8, 13, -2],
"size": [10, 4, 4],
"uv": {
"north": {"uv": [31, 100], "uv_size": [10, 4]},
"east": {"uv": [95, 102], "uv_size": [4, 4]},
"south": {"uv": [100, 36], "uv_size": [10, 4]},
"west": {"uv": [99, 102], "uv_size": [4, 4]},
"up": {"uv": [100, 40], "uv_size": [10, 4]},
"down": {"uv": [100, 48], "uv_size": [10, -4]}
}
}
]
},
{
"name": "left_forearm",
"parent": "left_arm",
"pivot": [18, 15, 0],
"cubes": [
{
"origin": [18, 13, -2],
"size": [10, 4, 4],
"uv": {
"north": {"uv": [31, 100], "uv_size": [10, 4]},
"east": {"uv": [95, 102], "uv_size": [4, 4]},
"south": {"uv": [100, 36], "uv_size": [10, 4]},
"west": {"uv": [99, 102], "uv_size": [4, 4]},
"up": {"uv": [100, 40], "uv_size": [10, 4]},
"down": {"uv": [100, 48], "uv_size": [10, -4]}
}
}
]
},
{
"name": "crank",
"parent": "box",
"pivot": [8.5, 20, 0],
"cubes": [
{
"origin": [8, 19, -1],
"size": [3, 2, 2],
"uv": {
"north": {"uv": [41, 100], "uv_size": [3, 2]},
"east": {"uv": [42, 60], "uv_size": [2, 2]},
"south": {"uv": [44, 100], "uv_size": [3, 2]},
"west": {"uv": [42, 62], "uv_size": [2, 2]},
"up": {"uv": [8, 103], "uv_size": [3, 2]},
"down": {"uv": [77, 105], "uv_size": [3, -2]}
}
}
]
},
{
"name": "handle",
"parent": "crank",
"pivot": [11, 20, -0.125],
"cubes": [
{
"origin": [11, 19.5, -5],
"size": [3, 1, 6],
"uv": {
"north": {"uv": [104, 9], "uv_size": [3, 1]},
"east": {"uv": [32, 83], "uv_size": [6, 1]},
"south": {"uv": [104, 10], "uv_size": [3, 1]},
"west": {"uv": [104, 0], "uv_size": [6, 1]},
"up": {"uv": [13, 101], "uv_size": [3, 6]},
"down": {"uv": [54, 108], "uv_size": [3, -6]}
}
},
{
"origin": [14, 19, -5.75],
"size": [3, 2, 2],
"uv": {
"north": {"uv": [104, 1], "uv_size": [3, 2]},
"east": {"uv": [20, 64], "uv_size": [2, 2]},
"south": {"uv": [104, 3], "uv_size": [3, 2]},
"west": {"uv": [42, 64], "uv_size": [2, 2]},
"up": {"uv": [104, 5], "uv_size": [3, 2]},
"down": {"uv": [104, 9], "uv_size": [3, -2]}
}
}
]
},
{
"name": "right_leg",
"parent": "root",
"pivot": [-3, 12, 0],
"cubes": [
{
"origin": [-5, 0, -2],
"size": [4, 12, 4],
"uv": {
"north": {"uv": [80, 96], "uv_size": [4, 12]},
"east": {"uv": [100, 0], "uv_size": [4, 12]},
"south": {"uv": [100, 12], "uv_size": [4, 12]},
"west": {"uv": [100, 24], "uv_size": [4, 12]},
"up": {"uv": [0, 103], "uv_size": [4, 4]},
"down": {"uv": [4, 107], "uv_size": [4, -4]}
}
}
]
},
{
"name": "left_leg",
"parent": "root",
"pivot": [2, 12, 0],
"cubes": [
{
"origin": [1, 0, -2],
"size": [4, 12, 4],
"uv": {
"north": {"uv": [38, 60], "uv_size": [4, 12]},
"east": {"uv": [16, 64], "uv_size": [4, 12]},
"south": {"uv": [40, 72], "uv_size": [4, 12]},
"west": {"uv": [62, 84], "uv_size": [4, 12]},
"up": {"uv": [57, 102], "uv_size": [4, 4]},
"down": {"uv": [91, 106], "uv_size": [4, -4]}
}
}
]
}
]
}
]
}
{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.jester",
"texture_width": 128,
"texture_height": 128,
"visible_bounds_width": 3,
"visible_bounds_height": 3.5,
"visible_bounds_offset": [0, 1.25, 0]
},
"bones": [
{
"name": "root",
"pivot": [0, 0, 0]
},
{
"name": "waist",
"parent": "root",
"pivot": [0, 12, 0]
},
{
"name": "box",
"parent": "waist",
"pivot": [0, 12, 0],
"cubes": [
{
"origin": [-8, 12, -8],
"size": [16, 16, 16],
"uv": {
"north": { "uv": [22, 60], "uv_size": [16, 16] },
"east": { "uv": [0, 64], "uv_size": [16, 16] },
"south": { "uv": [68, 0], "uv_size": [16, 16] },
"west": { "uv": [68, 16], "uv_size": [16, 16] },
"up": { "uv": [68, 32], "uv_size": [16, 16] },
"down": { "uv": [68, 64], "uv_size": [16, -16] }
}
}
]
},
{
"name": "box_lid",
"parent": "box",
"pivot": [0, 28, 8],
"cubes": [
{
"origin": [-8, 28, -8],
"size": [16, 1, 16],
"uv": {
"north": { "uv": [98, 65], "uv_size": [16, 1] },
"east": { "uv": [61, 103], "uv_size": [16, 1] },
"south": { "uv": [103, 102], "uv_size": [16, 1] },
"west": { "uv": [103, 103], "uv_size": [16, 1] },
"up": { "uv": [68, 64], "uv_size": [16, 16] },
"down": { "uv": [16, 92], "uv_size": [16, -16] }
}
}
]
},
{
"name": "tendrils",
"parent": "box",
"pivot": [-0.3709, 28.03888, 1.72961],
"cubes": [
{
"origin": [-4.75, 27, -2],
"size": [8, 28, 7],
"pivot": [-0.75, 27.5, 0.5],
"rotation": [11.5, 0, 0],
"uv": {
"north": { "uv": [84, 66], "uv_size": [8, 28] },
"east": { "uv": [24, 92], "uv_size": [7, 28] },
"south": { "uv": [16, 92], "uv_size": [8, 28] },
"west": { "uv": [84, 94], "uv_size": [7, 28] },
"up": { "uv": [32, 76], "uv_size": [8, 7] },
"down": { "uv": [98, 65], "uv_size": [8, -7] }
}
},
{
"origin": [-6.025, 25.63246, -6.50605],
"size": [12, 28, 0],
"pivot": [-0.75, 39.63246, -7.58105],
"rotation": [12.91186, -8.38903, -9.73581],
"uv": {
"north": { "uv": [44, 0], "uv_size": [12, 28] },
"east": { "uv": [0, 0], "uv_size": [0, 28] },
"south": { "uv": [44, 28], "uv_size": [12, 28] },
"west": { "uv": [0, 0], "uv_size": [0, 28] },
"up": { "uv": [0, 0], "uv_size": [12, 0] },
"down": { "uv": [0, 0], "uv_size": [12, 0] }
}
},
{
"origin": [-6.75, 25.33246, -8.85605],
"size": [12, 28, 0],
"pivot": [-0.75, 39.63246, -7.58105],
"rotation": [169.98699, 25.84107, -179.13668],
"uv": {
"north": { "uv": [56, 0], "uv_size": [12, 28] },
"east": { "uv": [0, 0], "uv_size": [0, 28] },
"south": { "uv": [56, 28], "uv_size": [12, 28] },
"west": { "uv": [0, 0], "uv_size": [0, 28] },
"up": { "uv": [0, 0], "uv_size": [12, 0] },
"down": { "uv": [0, 0], "uv_size": [12, 0] }
}
},
{
"origin": [-5.475, 25.63246, -6.50605],
"size": [12, 28, 0],
"pivot": [-0.75, 39.63246, -7.58105],
"rotation": [15.7096, 19.35594, 8.37709],
"uv": {
"north": { "uv": [44, 56], "uv_size": [12, 28] },
"east": { "uv": [0, 0], "uv_size": [0, 28] },
"south": { "uv": [56, 56], "uv_size": [12, 28] },
"west": { "uv": [0, 0], "uv_size": [0, 28] },
"up": { "uv": [0, 0], "uv_size": [12, 0] },
"down": { "uv": [0, 0], "uv_size": [12, 0] }
}
}
]
},
{
"name": "skull",
"parent": "tendrils",
"pivot": [-0.1784, 51.63803, -2.36963],
"cubes": [
{
"origin": [-11, 44.38084, -20.73926],
"size": [22, 20, 22],
"uv": {
"north": { "uv": [22, 0], "uv_size": [22, 20] },
"east": { "uv": [22, 20], "uv_size": [22, 20] },
"south": { "uv": [22, 40], "uv_size": [22, 20] },
"west": { "uv": [0, 44], "uv_size": [22, 20] },
"up": { "uv": [0, 0], "uv_size": [22, 22] },
"down": { "uv": [0, 44], "uv_size": [22, -22] }
}
},
{
"origin": [-9.375, 47, -19],
"size": [16, 16, 16],
"pivot": [-1.375, 50, -11],
"rotation": [0, 0, 11.75],
"uv": {
"north": { "uv": [0, 80], "uv_size": [16, 16] },
"east": { "uv": [68, 80], "uv_size": [16, 16] },
"south": { "uv": [84, 0], "uv_size": [16, 16] },
"west": { "uv": [84, 16], "uv_size": [16, 16] },
"up": { "uv": [32, 84], "uv_size": [16, 16] },
"down": { "uv": [84, 48], "uv_size": [16, -16] }
}
}
]
},
{
"name": "jaw",
"parent": "skull",
"pivot": [0, 44.18195, -1.85535],
"cubes": [
{
"origin": [-7, 39.68195, -19.85535],
"size": [14, 5, 18],
"uv": {
"north": { "uv": [0, 96], "uv_size": [14, 5] },
"east": { "uv": [62, 96], "uv_size": [18, 5] },
"south": { "uv": [98, 53], "uv_size": [14, 5] },
"west": { "uv": [98, 48], "uv_size": [18, 5] },
"up": { "uv": [48, 84], "uv_size": [14, 18] },
"down": { "uv": [84, 66], "uv_size": [14, -18] }
}
},
{
"origin": [-6.5, 44.68195, -19.35535],
"size": [13, 2, 17],
"uv": {
"north": { "uv": [0, 101], "uv_size": [13, 2] },
"east": { "uv": [91, 100], "uv_size": [17, 2] },
"south": { "uv": [41, 102], "uv_size": [13, 2] },
"west": { "uv": [62, 101], "uv_size": [17, 2] },
"up": { "uv": [92, 66], "uv_size": [13, 17] },
"down": { "uv": [92, 100], "uv_size": [13, -17] }
}
}
]
},
{
"name": "left_arm",
"parent": "box",
"pivot": [8, 15, 0],
"cubes": [
{
"origin": [8, 13, -2],
"size": [10, 4, 4],
"uv": {
"north": { "uv": [31, 100], "uv_size": [10, 4] },
"east": { "uv": [95, 102], "uv_size": [4, 4] },
"south": { "uv": [100, 36], "uv_size": [10, 4] },
"west": { "uv": [99, 102], "uv_size": [4, 4] },
"up": { "uv": [100, 40], "uv_size": [10, 4] },
"down": { "uv": [100, 48], "uv_size": [10, -4] }
}
}
]
},
{
"name": "left_forearm",
"parent": "left_arm",
"pivot": [18, 15, 0],
"cubes": [
{
"origin": [18, 13, -2],
"size": [10, 4, 4],
"uv": {
"north": { "uv": [31, 100], "uv_size": [10, 4] },
"east": { "uv": [95, 102], "uv_size": [4, 4] },
"south": { "uv": [100, 36], "uv_size": [10, 4] },
"west": { "uv": [99, 102], "uv_size": [4, 4] },
"up": { "uv": [100, 40], "uv_size": [10, 4] },
"down": { "uv": [100, 48], "uv_size": [10, -4] }
}
}
]
},
{
"name": "crank",
"parent": "box",
"pivot": [8.5, 20, 0],
"cubes": [
{
"origin": [8, 19, -1],
"size": [3, 2, 2],
"uv": {
"north": { "uv": [41, 100], "uv_size": [3, 2] },
"east": { "uv": [42, 60], "uv_size": [2, 2] },
"south": { "uv": [44, 100], "uv_size": [3, 2] },
"west": { "uv": [42, 62], "uv_size": [2, 2] },
"up": { "uv": [8, 103], "uv_size": [3, 2] },
"down": { "uv": [77, 105], "uv_size": [3, -2] }
}
}
]
},
{
"name": "handle",
"parent": "crank",
"pivot": [11, 20, -0.125],
"cubes": [
{
"origin": [11, 19.5, -5],
"size": [3, 1, 6],
"uv": {
"north": { "uv": [104, 9], "uv_size": [3, 1] },
"east": { "uv": [32, 83], "uv_size": [6, 1] },
"south": { "uv": [104, 10], "uv_size": [3, 1] },
"west": { "uv": [104, 0], "uv_size": [6, 1] },
"up": { "uv": [13, 101], "uv_size": [3, 6] },
"down": { "uv": [54, 108], "uv_size": [3, -6] }
}
},
{
"origin": [14, 19, -5.75],
"size": [3, 2, 2],
"uv": {
"north": { "uv": [104, 1], "uv_size": [3, 2] },
"east": { "uv": [20, 64], "uv_size": [2, 2] },
"south": { "uv": [104, 3], "uv_size": [3, 2] },
"west": { "uv": [42, 64], "uv_size": [2, 2] },
"up": { "uv": [104, 5], "uv_size": [3, 2] },
"down": { "uv": [104, 9], "uv_size": [3, -2] }
}
}
]
},
{
"name": "right_leg",
"parent": "root",
"pivot": [-3, 12, 0],
"cubes": [
{
"origin": [-5, 0, -2],
"size": [4, 12, 4],
"uv": {
"north": { "uv": [80, 96], "uv_size": [4, 12] },
"east": { "uv": [100, 0], "uv_size": [4, 12] },
"south": { "uv": [100, 12], "uv_size": [4, 12] },
"west": { "uv": [100, 24], "uv_size": [4, 12] },
"up": { "uv": [0, 103], "uv_size": [4, 4] },
"down": { "uv": [4, 107], "uv_size": [4, -4] }
}
}
]
},
{
"name": "left_leg",
"parent": "root",
"pivot": [2, 12, 0],
"cubes": [
{
"origin": [1, 0, -2],
"size": [4, 12, 4],
"uv": {
"north": { "uv": [38, 60], "uv_size": [4, 12] },
"east": { "uv": [16, 64], "uv_size": [4, 12] },
"south": { "uv": [40, 72], "uv_size": [4, 12] },
"west": { "uv": [62, 84], "uv_size": [4, 12] },
"up": { "uv": [57, 102], "uv_size": [4, 4] },
"down": { "uv": [91, 106], "uv_size": [4, -4] }
}
}
]
}
]
}
]
}
@@ -4,6 +4,8 @@ import type { Position, Schematic } from "cubi/server";
// placed, so a plan that comes out too small can be tried again without touching the world
export const DOORWAY = "dangerous_business:doorway";
// where the surface is placed, high above the interior. anyone higher than it is outside the facility
export const SURFACE_Y = 150;
export const VENT_SPOT = "dangerous_business:vent_spot";
// a marker block in a tile, a doorway or a vent spot, with its facing state: 0 north, 1 east, 2 south, 3 west. in a
@@ -40,6 +42,10 @@ export interface TileType extends TileRules {
vent_spots: Marker[];
}
export function in_facility(position: Position) {
return position.y <= SURFACE_Y;
}
export interface PlacedTile {
tile: string;
// where the schematic's lowest corner goes, before it's turned around it
+236
View File
@@ -0,0 +1,236 @@
// the jester: a box on legs that wanders until it sees a player. it follows them for a while, stops to wind its crank,
// and pops open, then runs down every player in the facility, faster and faster, until there's nobody left inside
import type { MobRef, Player, ScriptGoal, ServerContext } from "cubi/server";
import { type AnimatedEntity, AnimationState, type ClientContext, type Clip, type EntityPose } from "cubi/client";
import { opens_doors } from "./coilhead.ts";
import { in_facility } from "./interior.ts";
const JESTER = "dangerous_business:jester";
// its "state" client data, what its animator plays
const ROAMING = 1;
const CRANKING = 2;
const AGGRO = 3;
// how far away it notices a player it can see
const SEE_RANGE = 24;
// how close it comes to the player it's following
const FOLLOW_DISTANCE = 3;
// seconds after it first notices someone before it starts cranking, shorter with more players around
const COUNTDOWN_ALONE = [25, 42];
const COUNTDOWN_TOGETHER = [13, 21];
const CRANK_TICKS = 40 * 20;
// how long it stands after popping before it goes
const POP_TICKS = 2 * 20;
// it chases a fifth faster than it walks, and another fifth every SPEED_UP_TICKS, up to twice as fast
const SPEED_STEP = 0.2;
const SPEED_UP_TICKS = 120;
const MAX_SPEED_STEPS = 8;
const CHASE_SPEED = "dangerous_business:jester_chase";
// it only waits a moment at a closed door
const OPEN_DOOR_TICKS = 20;
export function register_jester(ctx: ServerContext) {
const builtin = ctx.entities.goals;
const chase = builtin.melee_attack();
const stroll = builtin.random_stroll();
const look_around = builtin.random_look_around();
ctx.entities.register_behavior(JESTER, (mob, goals) => {
let state = mob.get_client_data<number>("state") ?? ROAMING;
// ticks in its state
let ticks = 0;
// ticks left until it cranks, from when it first noticed someone
let countdown: number | undefined;
let followed: Player | undefined;
const set_state = (next: number) => {
state = next;
ticks = 0;
mob.set_client_data("state", next);
};
// what it's doing, which the goals after it follow
goals.add(0, {
can_use: () => true,
tick: () => {
ticks++;
if (state === ROAMING) {
if (followed && (followed.health <= 0 || !in_facility(followed.position))) followed = undefined;
followed ??= ctx.players.all().find((player) => can_see(ctx, mob, player));
if (followed && countdown === undefined) {
const [low, high] = ctx.players.all().length > 1 ? COUNTDOWN_TOGETHER : COUNTDOWN_ALONE;
countdown = Math.round((low + (high - low) * mob.random()) * 20);
}
if (countdown !== undefined && --countdown <= 0) {
countdown = undefined;
followed = undefined;
set_state(CRANKING);
}
} else if (state === CRANKING) {
if (ticks >= CRANK_TICKS) set_state(AGGRO);
} else {
const target = nearest_player(ctx, mob);
if (!target) {
mob.target = undefined;
mob.remove_modifier("cubi:movement_speed", CHASE_SPEED);
set_state(ROAMING);
return;
}
if (ticks < POP_TICKS) return;
mob.target = target;
const steps = Math.min(MAX_SPEED_STEPS, 1 + Math.floor((ticks - POP_TICKS) / SPEED_UP_TICKS));
mob.add_modifier("cubi:movement_speed", {
id: CHASE_SPEED,
amount: steps * SPEED_STEP,
operation: "add_multiplied_total",
});
}
},
});
// stands still while it cranks and while it pops
goals.add(1, {
flags: ["move", "look", "jump"],
can_use: () => state === CRANKING || (state === AGGRO && ticks < POP_TICKS),
start: () => mob.stop(),
});
goals.add(2, chase);
goals.add(3, follow(mob, () => state === ROAMING ? followed : undefined));
goals.add(4, stroll);
goals.add(5, look_around);
goals.add(6, opens_doors(ctx, mob, OPEN_DOOR_TICKS));
});
}
// keeps close to who(), looking at them, and stands by them once it's there instead of wandering off. it goes a new
// way only once they've moved to another block
function follow(mob: MobRef, who: () => Player | undefined): ScriptGoal {
let block = "";
return {
flags: ["move", "look"],
can_use: () => who() !== undefined,
start: () => block = "",
stop: () => mob.stop(),
tick: () => {
// the goal deciding what the jester does can let them go this tick
const player = who();
if (!player) return;
const { x, y, z } = player.position;
mob.look_at(x, y + 1.5, z);
const at = mob.position;
if (Math.hypot(x - at.x, y - at.y, z - at.z) <= FOLLOW_DISTANCE) {
if (block !== "") mob.stop();
block = "";
return;
}
const now = `${Math.floor(x)},${Math.floor(y)},${Math.floor(z)}`;
if (now === block) return;
block = now;
mob.move_to(x, y, z);
},
};
}
// whether it can see the player's eyes from its own, close enough to notice them, in the facility
function can_see(ctx: ServerContext, mob: MobRef, player: Player) {
if (player.health <= 0 || !in_facility(player.position)) return false;
const from = mob.eye_position;
const to = player.eye_position;
if (Math.hypot(to.x - from.x, to.y - from.y, to.z - from.z) > SEE_RANGE) return false;
return ctx.world.raycast(from, to) === undefined;
}
// the closest living player in the facility, however far
function nearest_player(ctx: ServerContext, mob: MobRef) {
const at = mob.position;
const distance = ({ position: { x, y, z } }: Player) => Math.hypot(x - at.x, y - at.y, z - at.z);
const inside = ctx.players.all().filter((player) => player.health > 0 && in_facility(player.position));
return inside.sort((a, b) => distance(a) - distance(b))[0] as Player | undefined;
}
// what bedrock's animation controller did: idle and walk while it roams, crank, then pop, then its chase. what its
// clips did with expressions is here as code
export function register_jester_animator(ctx: ClientContext) {
const clip = (name: string) => ctx.render.clip(`dangerous_business:jester/${name}`);
const idle = clip("idle");
const walk = clip("walk");
const crank = clip("crank");
const pop = clip("pop");
const aggro_idle = clip("aggro_idle");
const aggro_walk = clip("aggro_walk");
const attack = clip("attack");
ctx.render.register_entity_animator(JESTER, (jester) => {
const cranking = new AnimationState();
const popped = new AnimationState();
const attacking = new AnimationState();
return {
on_data(field, time) {
if (field !== "state") return;
const state = jester.get_client_data<number>("state");
cranking.animate_when(state === CRANKING, time);
popped.animate_when(state === AGGRO, time);
},
pose(pose, time) {
if (cranking.started) {
pose.play_state(crank, cranking, time);
} else if (popped.started && !popped.finished(pop, time)) {
pose.play_state(pop, popped, time);
} else if (popped.started) {
const swinging = jester.attack_progress(time) > 0;
if (swinging && (!attacking.started || attacking.finished(attack, time))) attacking.start(time);
if (attacking.started && !attacking.finished(attack, time)) {
pose.play_state(attack, attacking, time);
} else {
// its walk goes half as fast as when it roams
walking(pose, jester, time, aggro_walk, 40, (weight) => {
pose.play(aggro_idle, time / 20, weight);
sway(pose, time, weight, true);
});
}
} else {
walking(pose, jester, time, walk, 20, (weight) => {
pose.play(idle, time / 20, weight);
sway(pose, time, weight, false);
});
// both clips hide them, which blended halfway would only shrink them
pose.scale("tendrils", 0, 0, 0);
}
},
};
});
}
// clip as it walks, a second of it for ticks of walk_position, and standing as strongly as it isn't walking
function walking(
pose: EntityPose,
jester: AnimatedEntity,
time: number,
clip: Clip,
ticks: number,
standing: (weight: number) => void,
) {
const speed = Math.min(jester.walk_speed(time), 1);
pose.play(clip, jester.walk_position(time) / ticks, speed);
standing(1 - speed);
}
// the box bobbing and the arm swaying as it stands, and once it's popped the lid, skull, jaw and crank too
function sway(pose: EntityPose, time: number, weight: number, popped: boolean) {
// bedrock's math.cos and math.sin of life_time (seconds) times degrees a second
const seconds = time / 20;
const cos = (degrees_a_second: number) => Math.cos(seconds * degrees_a_second * Math.PI / 180) * weight;
const sin = (degrees_a_second: number) => Math.sin(seconds * degrees_a_second * Math.PI / 180) * weight;
pose.rotate("box", cos(180) * 2.5, 0, 0);
pose.rotate("left_arm", (-1.6248 * weight) + cos(90) * 5, -22.22485 * weight, 70.78761 * weight);
pose.rotate("left_forearm", cos(180) * 5, 62.5 * weight, 0);
if (!popped) {
pose.move("box", 0, -weight + cos(180), 0);
pose.move("left_arm", 0, 3 * weight - cos(180), 0);
return;
}
pose.rotate("tendrils", sin(180) * 2.5, 0, 0);
pose.rotate("box_lid", -127.5 * weight + sin(180) * 5, 0, 0);
pose.rotate("skull", cos(180) * -2.5, 0, 0);
pose.rotate("jaw", 10 * weight + sin(180) * 5, 0, 0);
pose.rotate("crank", sin(180) * 2.5, 0, 0);
}
+14 -2
View File
@@ -3,7 +3,17 @@ import type { ServerContext } from "cubi/server";
import { DOOR, FACILITY_DOOR } from "./shared.ts";
import { Alea } from "@paulaboks/rng";
import { register_coilhead, register_coilhead_animator } from "./coilhead.ts";
import { DOORWAY, MAIN_TILE, type Marker, type PlacedTile, plan_interior, tile_type, TILES } from "./interior.ts";
import { register_jester, register_jester_animator } from "./jester.ts";
import {
DOORWAY,
MAIN_TILE,
type Marker,
type PlacedTile,
plan_interior,
SURFACE_Y,
tile_type,
TILES,
} from "./interior.ts";
export { shared } from "./shared.ts";
@@ -15,11 +25,13 @@ export function server(ctx: ServerContext) {
register_death(ctx);
register_commands(ctx);
register_coilhead(ctx);
register_jester(ctx);
}
export function client(ctx: ClientContext) {
register_hud(ctx);
register_coilhead_animator(ctx);
register_jester_animator(ctx);
}
// a small 5x5 ring in the middle of the screen to aim with, its corners and middle left empty, in gui pixels
@@ -142,7 +154,7 @@ function clear_map(ctx: ServerContext) {
function place_surface(ctx: ServerContext) {
ctx.schematics.place(
"dangerous_business:assurance",
{ position: { x: -80, y: 150, z: -80 } },
{ position: { x: -80, y: SURFACE_Y, z: -80 } },
);
}
+3 -1
View File
@@ -287,7 +287,9 @@ export class MeleeAttackGoal extends Goal {
override tick() {
const mob = this.mob;
const target = mob.target!;
// a script's goal ticking before this one can have let it go, it stops next tick
const target = mob.target;
if (!target) return;
mob.look_control.look_at_entity(target);
this.#recalculate -= 1;
const block = `${Math.floor(target.x)},${Math.floor(target.y)},${Math.floor(target.z)}`;
+20 -12
View File
@@ -1681,18 +1681,7 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
}
player.vitals.add_exhaustion(amount);
},
attribute: (id) => player.attribute(known_attribute(id)),
add_modifier(attribute, modifier) {
const type = known_attribute(attribute);
const { id, amount, operation } = modifier;
if (typeof id !== "string" || typeof amount !== "number" || !Number.isFinite(amount)) {
throw new Error("a modifier needs a string id and a number amount");
}
if (!MODIFIER_OPERATIONS.includes(operation)) throw new Error(`unknown modifier operation ${operation}`);
player.attributes.get(type)?.add_modifier({ id, amount, operation });
},
remove_modifier: (attribute, id) =>
player.attributes.get(known_attribute(attribute))?.remove_modifier(id) ?? false,
...attributes_api(player),
add_effect(id, duration, options = {}) {
const type = known_effect(id);
if (!Number.isInteger(duration) || (duration < 1 && duration !== -1)) {
@@ -1748,8 +1737,27 @@ function look_direction(yaw: number, pitch: number): Position {
return { x: -Math.sin(yaw) * cos_pitch, y: Math.sin(pitch), z: -Math.cos(yaw) * cos_pitch };
}
// a player's or a mob's attribute, add_modifier and remove_modifier
function attributes_api(entity: LivingEntity): Pick<LivingRef, "attribute" | "add_modifier" | "remove_modifier"> {
return {
attribute: (id) => entity.attribute(known_attribute(id)),
add_modifier(attribute, modifier) {
const type = known_attribute(attribute);
const { id, amount, operation } = modifier;
if (typeof id !== "string" || typeof amount !== "number" || !Number.isFinite(amount)) {
throw new Error("a modifier needs a string id and a number amount");
}
if (!MODIFIER_OPERATIONS.includes(operation)) throw new Error(`unknown modifier operation ${operation}`);
entity.attributes.get(type)?.add_modifier({ id, amount, operation });
},
remove_modifier: (attribute, id) =>
entity.attributes.get(known_attribute(attribute))?.remove_modifier(id) ?? false,
};
}
export function living_ref(entity: LivingEntity): LivingRef {
return {
...attributes_api(entity),
id: entity.id,
get health() {
return entity.health;
+70
View File
@@ -19,6 +19,7 @@ const FLOOR = "dangerous_business:concrete_floor";
const DEATH = "dangerous_business:death";
const PIPE = "dangerous_business:double_steel_pipes";
const COILHEAD = "dangerous_business:coilhead";
const JESTER = "dangerous_business:jester";
const FACTORY_DOOR = "dangerous_business:factory_door";
// alice on a concrete floor at y 100, south of 0 100 0 and looking north, holding each of the blocks. it's a game of
@@ -256,6 +257,51 @@ Deno.test("a coilhead seen while it waits at a closed door stops waiting, and do
assertEquals(coilhead.navigation.blocked_by, undefined);
});
// a jester 6 blocks north of alice, in a state from its client data like one that was saved
function spawn_jester(t: Awaited<ReturnType<typeof setup>>["t"], state?: number) {
const jester = create_entity(t.game.entities, JESTER)! as Mob;
jester.set_position(0.5, 100, -2.5);
if (state !== undefined) jester.client_data = { state };
t.game.entities.add_entity(jester);
return jester;
}
Deno.test("a jester follows a player it sees without hurting them, then winds its crank standing still", async () => {
const { t } = await setup();
const alice = t.game.players()[0];
const jester = spawn_jester(t);
for (let i = 0; i < 100; i++) t.game.tick();
assert(jester.z > -1, `it stayed at z ${jester.z}, away from her`);
assertEquals(alice.health, alice.max_health);
for (let i = 0; i < 2000 && jester.client_data.state !== 2; i++) t.game.tick();
assertEquals(jester.client_data.state, 2);
const at = [jester.x, jester.z];
t.send(1, { type: "move", x: -2.5, y: 100, z: 3.5, yaw: 0, pitch: 0 });
for (let i = 0; i < 100; i++) t.game.tick();
assertEquals([jester.x, jester.z], at);
});
Deno.test("a popped jester runs down the nearest player faster and faster, and boxes up once they're out", async () => {
const { t } = await setup();
const alice = t.game.players()[0];
const jester = spawn_jester(t, 3);
const speed = () => t.game.mods.mob(jester).attribute("cubi:movement_speed");
const walking = speed();
for (let i = 0; i < 200 && alice.health === alice.max_health; i++) t.game.tick();
assert(alice.health < alice.max_health, "it never got to her");
assert(speed() > walking);
const chasing = speed();
for (let i = 0; i < 300; i++) t.game.tick();
assert(speed() > chasing, "it didn't get any faster");
// up on the surface, out of the facility
alice.set_position(0.5, 160, 3.5);
t.game.tick();
assertEquals(jester.client_data.state, 1);
assertEquals(speed(), walking);
});
// last, since it loads the mod the way a player gets it, in place of the server's
Deno.test("a coilhead's head springs back and forth when it freezes, and stays still when it stands", async () => {
const dir = Deno.makeTempDirSync({ prefix: "dangerous_business_client_" });
@@ -279,3 +325,27 @@ Deno.test("a coilhead's head springs back and forth when it freezes, and stays s
assertEquals(head(true, 1200), head(false, 1200));
Deno.removeSync(dir, { recursive: true });
});
Deno.test("a jester keeps its tendrils in the box until it pops, and turns its crank while it winds", async () => {
const dir = Deno.makeTempDirSync({ prefix: "dangerous_business_client_" });
copy_dir("mods/dangerous_business", `${dir}/dangerous_business`);
await load_as_player(dir);
const pose = (state: number | undefined, time: number) => {
const jester = {
id: "e1",
type: JESTER,
data: state === undefined ? {} : { client_data: { state } },
age: 0,
yaw: 0,
head_yaw: 0,
pitch: 0,
walk_animation: () => ({ position: 0, speed: 0 }),
attack_animation: () => 0,
};
return animation_for(jester)!.pose(time)!;
};
assertEquals(pose(undefined, 10).get("tendrils")!.scale, [0, 0, 0]);
assertNotEquals(pose(3, 100).get("tendrils")!.scale, [0, 0, 0]);
assertNotEquals(pose(2, 5).get("crank")!.rotation, pose(2, 15).get("crank")!.rotation);
Deno.removeSync(dir, { recursive: true });
});
+13
View File
@@ -4,6 +4,7 @@
// mobs following paths, see server/game/entity/navigation.ts
import { assert, assertEquals } from "@std/assert";
import { test_game, test_mob } from "./helpers.ts";
import { MeleeAttackGoal } from "@/server/game/entity/goals.ts";
// two rooms on a stone floor at y 99, split by a wall at x 3 with a doorway 2 high at z 4. a goal-less mob in the
// west room at 0.5 100 0.5, and alice in its corner, so it thinks
@@ -81,3 +82,15 @@ Deno.test("a script's mob walks its way, and stops when told", async () => {
assert(Math.hypot(ref.position.x - x, ref.position.z - z) < 0.5);
assertEquals(ref.blocked_by, undefined);
});
Deno.test("a mob going after its target stops when a script lets the target go partway through its thinking", async () => {
const { game, mob } = await rooms();
const melee = new MeleeAttackGoal(mob);
mob.target = game.players()[0];
assert(melee.can_use());
melee.start();
melee.tick();
mob.target = undefined;
melee.tick();
assert(!melee.can_continue_to_use());
});