@@ -1400,6 +1400,9 @@ void hurtEntity (int entity_id, int attacker_id, uint8_t damage_type, uint8_t da
14001400 // Don't continue if the mob is already dead
14011401 if (mob_health == 0 ) return ;
14021402
1403+ // Set the mob's panic timer
1404+ mob -> data |= (3 << 6 );
1405+
14031406 // Process health change on the server
14041407 if (mob_health <= damage ) {
14051408
@@ -1544,6 +1547,9 @@ void handleServerTick (int64_t time_since_last_tick) {
15441547 mob_data [i ].type == 95 || // Pig
15451548 mob_data [i ].type == 106 // Sheep
15461549 );
1550+ // Mob "panic" timer, set to 3 after being hit
1551+ // Currently has no effect on hostile mobs
1552+ uint8_t panic = (mob_data [i ].data >> 6 ) & 3 ;
15471553
15481554 // Burn hostile mobs if above ground during sunlight
15491555 if (!passive && (world_time < 13000 || world_time > 23460 ) && mob_data [i ].y > 48 ) {
@@ -1553,8 +1559,21 @@ void handleServerTick (int64_t time_since_last_tick) {
15531559 uint32_t r = fast_rand ();
15541560
15551561 if (passive ) {
1556- // Update passive mobs once per 4 seconds on average
1557- if (r % (4 * (unsigned int )TICKS_PER_SECOND ) != 0 ) continue ;
1562+ if (panic ) {
1563+ // If panicking, move randomly at up to 4 times per second
1564+ if (TICKS_PER_SECOND >= 4 ) {
1565+ uint32_t ticks_per_panic = (uint32_t )(TICKS_PER_SECOND / 4 );
1566+ if (server_ticks % ticks_per_panic != 0 ) continue ;
1567+ }
1568+ // Reset panic state after timer runs out
1569+ // Each panic timer tick takes one second
1570+ if (server_ticks % (uint32_t )TICKS_PER_SECOND == 0 ) {
1571+ mob_data [i ].data -= (1 << 6 );
1572+ }
1573+ } else {
1574+ // When not panicking, move idly once per 4 seconds on average
1575+ if (r % (4 * (unsigned int )TICKS_PER_SECOND ) != 0 ) continue ;
1576+ }
15581577 } else {
15591578 // Update hostile mobs once per second
15601579 if (server_ticks % (uint32_t )TICKS_PER_SECOND != 0 ) continue ;
0 commit comments