diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-11-12 23:54:05 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-12 23:54:05 -0600 |
| commit | 6eee543a3367d38a6f0e9bffb457a2bd76a8f9cc (patch) | |
| tree | a5e493ccd7ec24293b8d866242c3836146517122 /codegen/lib/code/entity.py | |
| parent | fa57d03627aa20b1df44caed7cb025b6db1d9b53 (diff) | |
| download | azalea-drasl-6eee543a3367d38a6f0e9bffb457a2bd76a8f9cc.tar.xz | |
Pathfinder (#25)
Pathfinding is very much not done, but it works enough and I want to get this merged.
TODO: fast replanning, goals that aren't a single node, falling moves (it should be able to play the dropper), parkour moves
Diffstat (limited to 'codegen/lib/code/entity.py')
| -rw-r--r-- | codegen/lib/code/entity.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/codegen/lib/code/entity.py b/codegen/lib/code/entity.py index 13f99022..9b976ef6 100644 --- a/codegen/lib/code/entity.py +++ b/codegen/lib/code/entity.py @@ -44,7 +44,7 @@ def generate_entity_metadata(burger_entity_data: dict, mappings: Mappings): code.append('use azalea_block::BlockState;') code.append('use azalea_chat::Component;') code.append('use azalea_core::{BlockPos, Direction, Particle, Slot};') - code.append('use std::{collections::VecDeque, ops::Deref};') + code.append('use std::{collections::VecDeque, ops::{Deref, DerefMut}};') code.append('use uuid::Uuid;') code.append('') @@ -271,6 +271,10 @@ def generate_entity_metadata(burger_entity_data: dict, mappings: Mappings): code.append( f'fn deref(&self) -> &Self::Target {{ &self.{parent_field_name} }}') code.append('}') + code.append(f'impl DerefMut for {struct_name} {{') + code.append( + f'fn deref_mut(&mut self) -> &mut Self::Target {{ &mut self.{parent_field_name} }}') + code.append('}') code.append('') # make the EntityMetadata enum from entity_structs @@ -309,6 +313,36 @@ def generate_entity_metadata(burger_entity_data: dict, mappings: Mappings): code.append('}') code.append('') + # impl Deref for EntityMetadata { + # type Target = AbstractEntity; + # fn deref(&self) -> &Self::Target { + # match self { + # EntityMetadata::Allay(entity) => entity, + # _ => {} + # } + # } + # } + code.append('impl Deref for EntityMetadata {') + code.append('type Target = AbstractEntity;') + code.append('fn deref(&self) -> &Self::Target {') + code.append('match self {') + for struct_name in entity_structs: + code.append( + f'EntityMetadata::{struct_name}(entity) => entity,') + code.append('}') + code.append('}') + code.append('}') + code.append('impl DerefMut for EntityMetadata {') + code.append('fn deref_mut(&mut self) -> &mut Self::Target {') + code.append('match self {') + for struct_name in entity_structs: + code.append( + f'EntityMetadata::{struct_name}(entity) => entity,') + code.append('}') + code.append('}') + code.append('}') + code.append('') + with open(METADATA_RS_DIR, 'w') as f: f.write('\n'.join(code)) |
