Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Commoble/c80ec7bcdc7761f1d864c950f0cc20b7 to your computer and use it in GitHub Desktop.
Save Commoble/c80ec7bcdc7761f1d864c950f0cc20b7 to your computer and use it in GitHub Desktop.
Idle Time and Mob Despawning in Minecraft Forge
idletime has these interactions:
is reset to 0 when:
when attacked
in the despawn check, when:
when the despawn fails due to persistance flag set or preventDespawn returning true
when the forge event is denied
when the nearest player is closer than the random despawn distance
when piglin or raider uses a ranged attack
when raider starts targeting a home
when vindicator starts targeting a door
when johnny vindicator starts targeting anything
raiders' idle time is fixed at 0 while targeting a player
withers' idle time is fixed at 0 while game mode isn't peaceful
is incremented:
by +1/tick for all MobEntities (not players or armor stands)
additionally by +2/tick for most monsters while light > 0.5
additionally by +2/tick every tick for raiders
is checked to determine:
random despawn check (must be > 600)
pillagers can only join raid if idle time <= 2400
random walk goal can only run if idle time < 100
squids can only move if idle time <= 100
other things related to despawning:
instant despawn distance (to nearest player)
if entity is further away from any player than this, entity will despawn
this is 128 for most things and 64 for ambient water fish
this can ONLY be prevented via:
setting the persistence flag to make noDespawnRequired return true
overriding preventDespawn
this is only done by raiders (during raids), endermen (while holding a block), and fish (that came from bucket)
denying forge's despawn event
idle time + canDespawn check -- if ALL of these are true:
idleTime > 600 (30 seconds)
rand.nextInt(800) == 0 (about once in every 40 seconds, or about 22% every minute)
distance to nearest player > 32
canDespawn returns true (given distance to nearest player)
so canDespawn controls random despawning (distance > 32), but not instant despawning (distance > 128)
preventDespawn & persistance controls both
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment