Skip to content

Commit

Permalink
♻️ Add missing allay and warden memories + refactor memory modules + …
Browse files Browse the repository at this point in the history
…add docs

Combined all memory module types into one file, since memory modules
are often shared between multiple entity types, not using inheritance,
which is how the other files are structured.
  • Loading branch information
misode committed Oct 9, 2024
1 parent 91f483d commit 176a349
Show file tree
Hide file tree
Showing 13 changed files with 298 additions and 178 deletions.
306 changes: 292 additions & 14 deletions java/server/util/memory.mcdoc
Original file line number Diff line number Diff line change
@@ -1,32 +1,310 @@
use ::java::server::util::global_pos::GlobalPos

struct TimedMemory {
/// Ticks before this memory is removed.
struct Memories {
[#[id="memory_module_type"] string]: minecraft:memory_module[[%key]],
}

struct ExpirableValue {
/// If present, ticks before this memory is automatically removed.
#[since="1.16"]
ttl: long,
ttl?: long,
}

// Memory modules that are not dispatched do not have a codec and are not serialized in-game
dispatch minecraft:memory_module[%unknown] to ()

dispatch minecraft:memory_module[home] to struct Home {
...ExpirableValue,
// Position of the villager's home.
value: GlobalPos,
}

dispatch minecraft:memory_module[job_site] to struct JobSite {
...ExpirableValue,
// Position of the villager's job site.
value: GlobalPos,
}

dispatch minecraft:memory_module[potential_job_site] to struct PotentialJobSite {
...ExpirableValue,
// Position of a potential job site of the villager.
value: GlobalPos,
}

dispatch minecraft:memory_module[meeting_point] to struct MeetingPoint {
...ExpirableValue,
// Position of the villager's meeting point.
value: GlobalPos,
}

struct FlagMemory {
dispatch minecraft:memory_module[golem_detected_recently] to struct GolemDetectedRecently {
...ExpirableValue,
// Whether the villager has detected an iron golem recently.
value: boolean,
}

struct TimedFlagMemory {
...TimedMemory,
dispatch minecraft:memory_module[danger_detected_recently] to struct DangerDetectedRecently {
...ExpirableValue,
// Whether the armadillo has detected danger recently.
value: boolean,
}

struct TimedEntityMemory {
...TimedMemory,
/// Target entity's UUID.
value: int[] @ 4,
dispatch minecraft:memory_module[last_slept] to struct LastSlept {
...ExpirableValue,
// The gametime tick that the villager last slept in a bed.
value: long,
}

struct TickMemory {
/// Tick value
dispatch minecraft:memory_module[last_woken] to struct LastWoken {
...ExpirableValue,
// The gametime tick that the villager last woke up from a bed.
value: long,
}

struct PositionMemory {
/// Position
dispatch minecraft:memory_module[last_worked_at_poi] to struct LastWorkedAtPoi {
...ExpirableValue,
// The gametime tick that the villager last worked at their job site.
value: long,
}

dispatch minecraft:memory_module[play_dead_ticks] to struct PlayDeadTicks {
...ExpirableValue,
/// Ticks until the axolotl stops playing dead.
value: int,
}

dispatch minecraft:memory_module[temptation_cooldown_ticks] to struct TemptationCooldownTicks {
...ExpirableValue,
// Ticks before the mob can be tempted again.
value: int,
}

dispatch minecraft:memory_module[gaze_cooldown_ticks] to struct GazeCooldownTicks {
...ExpirableValue,
// Ticks before the armadillo or camel can randomly look around again.
value: int,
}

dispatch minecraft:memory_module[is_tempted] to struct IsTempted {
...ExpirableValue,
/// Whether the mob is currently tempted by a player.
value: boolean,
}

dispatch minecraft:memory_module[long_jump_cooling_down] to struct LongJumpCoolingDown {
...ExpirableValue,
/// Ticks before the goat can long jump again.
value: int,
}

dispatch minecraft:memory_module[has_hunting_cooldown] to struct HasHuntingCooldown {
...ExpirableValue,
// Whether the axolotl is in a hunting cooldown.
value: boolean,
}

dispatch minecraft:memory_module[ram_cooldown_ticks] to struct RamCooldownTicks {
...ExpirableValue,
// Ticks before the goat can ram again.
value: int,
}

dispatch minecraft:memory_module[is_in_water] to struct IsInWater {
...ExpirableValue,
/// Whether the frog is currently in water.
value: struct {}
}

dispatch minecraft:memory_module[is_pregnant] to struct IsPregnant {
...ExpirableValue,
/// Whether the frog is pregnant.
value: struct {},
}

dispatch minecraft:memory_module[is_panicking] to struct IsPanicking {
...ExpirableValue,
// Whether the mob is currently panicking.
value: boolean,
}

dispatch minecraft:memory_module[angry_at] to struct AngryAt {
...ExpirableValue,
/// The target of the piglin or piglin brute.
value: #[uuid] int[] @ 4,
}

dispatch minecraft:memory_module[universal_anger] to struct UniversalAnger {
...ExpirableValue,
// Whether the piglin is being universally angered. Only used when the `universalAnger` gamerule is enabled.
value: boolean,
}

dispatch minecraft:memory_module[admiring_item] to struct AdmiringItem {
...ExpirableValue,
/// Whether the piglin is currently admiring an item.
value: boolean,
}

dispatch minecraft:memory_module[admiring_disabled] to struct AdmiringDisable {
...ExpirableValue,
/// Whether the piglin cannot admire an item.
/// Set when converting, when attacked, or when admiring an item.
value: boolean,
}

dispatch minecraft:memory_module[hunted_recently] to struct HuntedRecently {
...ExpirableValue,
/// Whether the piglin just hunted recently.
/// Set after hunting or spawning in a bastion remnant.
value: boolean,
}

dispatch minecraft:memory_module[recent_projectile] to struct RecentProjectile {
...ExpirableValue,
// Whether the warden has recently noticed a projectile vibration.
value: struct {},
}

dispatch minecraft:memory_module[is_sniffing] to struct IsSniffing {
...ExpirableValue,
// Whether the warden or sniffer is currently sniffing.
value: struct {},
}

dispatch minecraft:memory_module[is_emerging] to struct IsEmerging {
...ExpirableValue,
// Whether the warden is currently emerging from the ground.
value: struct {},
}

dispatch minecraft:memory_module[roar_sound_delay] to struct RoarSoundDelay {
...ExpirableValue,
// If present, the warden doesn't roar.
value: struct {},
}

dispatch minecraft:memory_module[dig_cooldown] to struct DigCooldown {
...ExpirableValue,
// If present, the warden will not dig down.
value: struct {},
}

dispatch minecraft:memory_module[roar_sound_cooldown] to struct RoarSoundCooldown {
...ExpirableValue,
// If present, the warden doesn't roar.
value: struct {},
}

dispatch minecraft:memory_module[sniff_cooldown] to struct SniffCooldown {
...ExpirableValue,
// If present, the warden or sniffer will not sniff.
value: struct {},
}

dispatch minecraft:memory_module[touch_cooldown] to struct TouchCooldown {
...ExpirableValue,
// If present, the warden will not react to being pushed by another mob. Set to 20 when touched.
value: struct {},
}

dispatch minecraft:memory_module[vibration_cooldown] to struct VibrationCooldown {
...ExpirableValue,
// If present, the warden will not react to vibrations. Set to 40 when receiving a vibration.
value: struct {},
}

dispatch minecraft:memory_module[sonic_boom_cooldown] to struct SonicBoomCooldown {
...ExpirableValue,
// If present, the warden will not use the sonic boom attack.
value: struct {},
}

dispatch minecraft:memory_module[sonic_boom_sound_cooldown] to struct SonicBoomSoundCooldown {
...ExpirableValue,
// If present, the warden's sonic boom animation will not spawn particles and play sounds.
value: struct {},
}

dispatch minecraft:memory_module[sonic_boom_sound_delay] to struct SonicBoomSoundDelay {
...ExpirableValue,
// If present, will delay the warden's sonic boom animation.
value: struct {},
}

dispatch minecraft:memory_module[liked_player] to struct LikedPlayer {
...ExpirableValue,
/// The UUID of the player entity that the allay likes.
value: #[uuid] int[] @ 4,
}

dispatch minecraft:memory_module[liked_noteblock] to struct LikedNoteblock {
...ExpirableValue,
/// The position and dimension of the note block that the allay likes.
value: GlobalPos,
}

dispatch minecraft:memory_module[liked_noteblock_cooldown_ticks] to struct LikedNoteblockCooldownTicks {
...ExpirableValue,
/// Ticks before the allay stops putting items at the liked note block.
value: int,
}

dispatch minecraft:memory_module[item_pickup_cooldown_ticks] to struct ItemPickupCooldownTicks {
...ExpirableValue,
/// Ticks before the allay goes to pick up an item again.
value: int,
}

dispatch minecraft:memory_module[sniffer_explored_positions] to struct SnifferExploredPositions {
...ExpirableValue,
/// Last 20 block positions that the sniffer has dug up. The sniffer will not dig in these positions.
value: [int[] @ 3] @ ..20,
}

dispatch minecraft:memory_module[breeze_jump_cooldown] to struct BreezeJumpCooldown {
...ExpirableValue,
// If present, the breeze will not long jump or slide. Set after performing a long jump.
value: struct {},
}

dispatch minecraft:memory_module[breeze_shoot] to struct BreezeShoot {
...ExpirableValue,
// If present, the breeze is able to shoot a wind charge, and will not long jump or slide.
value: struct {},
}

dispatch minecraft:memory_module[breeze_shoot_charging] to struct BreezeShootCharging {
...ExpirableValue,
// If present, the breeze will not shoot a wind charge. Set when starting to shoot.
value: struct {},
}

dispatch minecraft:memory_module[breeze_shoot_recover] to struct BreezeShootRecover {
...ExpirableValue,
// If present, the breeze will not shoot a wind charge.
value: struct {},
}

dispatch minecraft:memory_module[breeze_shoot_cooldown] to struct BreezeShootCooldown {
...ExpirableValue,
// If present, the breeze will not shoot a wind charge. Set after shooting
value: struct {},
}

dispatch minecraft:memory_module[breeze_jump_inhaling] to struct BreezeJumpInhaling {
...ExpirableValue,
// If present, the breeze will not long jump or shoot a wind charge when stuck.
value: struct {},
}

dispatch minecraft:memory_module[breeze_jump_target] to struct BreezeJumpTarget {
...ExpirableValue,
/// The block position that the breeze is jumping towards.
value: int[] @ 3,
}

dispatch minecraft:memory_module[breeze_leaving_water] to struct BreezeLeavingWater {
...ExpirableValue,
// If present, the breeze is in water.
value: struct {},
}
6 changes: 0 additions & 6 deletions java/server/util/mod.mcdoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ type ColorString = color::ColorString
type EffectId = effect::EffectId
type GlobalPos = global_pos::GlobalPos
type SlottedItem<T> = inventory::SlottedItem<T>
type TickMemory = memory::TickMemory
type TimedMemory = memory::TimedMemory
type FlagMemory = memory::FlagMemory
type TimedFlagMemory = memory::TimedFlagMemory
type TimedEntityMemory = memory::TimedEntityMemory
type PositionMemory = memory::PositionMemory
type Particle = particle::Particle

type Filterable<T> = (
Expand Down
9 changes: 0 additions & 9 deletions java/server/world/entity/mob/breedable/armadillo.mcdoc
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
use ::java::server::util::TimedMemory

dispatch minecraft:memory_module[danger_detected_recently] to TimedMemory

#[since="1.20.5"]
dispatch minecraft:entity[armadillo] to struct Armadillo {
...super::Breedable,
state?: ArmadilloState,
scute_time?: int @ 0..,
}

dispatch minecraft:entity_memory[armadillo] to (
"gaze_cooldown_ticks" |
"danger_detected_recently" |
)

enum(string) ArmadilloState {
Idle = "idle",
Rolling = "rolling",
Expand Down
14 changes: 0 additions & 14 deletions java/server/world/entity/mob/breedable/axolotl.mcdoc
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
use ::java::server::util::FlagMemory
use ::java::server::util::TickMemory

/// Hunting cooldown active.
dispatch minecraft:memory_module[has_hunting_cooldown] to FlagMemory
/// Ticks until it stops playing dead.
dispatch minecraft:memory_module[play_dead_ticks] to TickMemory

#[since="1.17"]
dispatch minecraft:entity[axolotl] to struct Axolotl {
...super::Breedable,
Expand All @@ -15,12 +7,6 @@ dispatch minecraft:entity[axolotl] to struct Axolotl {
FromBucket?: boolean
}

dispatch minecraft:entity_memory[axolotl] to (
super::BreedableMemories |
"has_hunting_cooldown" |
"play_dead_ticks" |
)

enum(int) Variant {
Lucy = 0,
Wild = 1,
Expand Down
Loading

0 comments on commit 176a349

Please sign in to comment.