Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Implement entity framework #16

Merged
merged 90 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 89 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
32bb060
First look
Mubelotix Nov 9, 2023
dbb3c00
Add another layer
Mubelotix Nov 9, 2023
9754d3d
Reorder
Mubelotix Nov 9, 2023
8743ad3
Switch to handler
Mubelotix Nov 9, 2023
85bde6d
Move implementations
Mubelotix Nov 9, 2023
3158a80
Make goal clearer
Mubelotix Nov 9, 2023
0f1d5f0
Start new macro
Mubelotix Nov 9, 2023
4a8971c
Read defines
Mubelotix Nov 9, 2023
cbfd098
Reimplement old features
Mubelotix Nov 9, 2023
11d911f
Create methods struct
Mubelotix Nov 9, 2023
8300deb
Finish methods struct
Mubelotix Nov 9, 2023
42f639e
Fix warning
Mubelotix Nov 9, 2023
46ec159
Start implementing defaults
Mubelotix Nov 9, 2023
46adc8c
Fix warning
Mubelotix Nov 9, 2023
1253794
Fix issue
Mubelotix Nov 9, 2023
c1bf87b
Add implementations
Mubelotix Nov 9, 2023
3019afb
Generate ext trait
Mubelotix Nov 9, 2023
7931cb9
Implement ext traits
Mubelotix Nov 9, 2023
b36e2b4
Implement conversion traits
Mubelotix Nov 9, 2023
52e4497
Fix issue
Mubelotix Nov 9, 2023
51c8009
Fix mistake
Mubelotix Nov 9, 2023
84f5687
Fix infinite recursion
Mubelotix Nov 10, 2023
16a62b2
Fix missing methods
Mubelotix Nov 10, 2023
c009dcd
Fix some issues
Mubelotix Nov 10, 2023
e8bc550
First half
Mubelotix Nov 10, 2023
0354f83
Second half
Mubelotix Nov 10, 2023
ef84091
Fix ECS
Mubelotix Nov 10, 2023
7bbebc5
Start Implementing observer
Mubelotix Nov 10, 2023
9681c01
Start implementing TryAsEntityRef
Mubelotix Nov 10, 2023
b45a8cf
Finish fishes
Mubelotix Nov 10, 2023
293fb89
Fix errors
Mubelotix Nov 10, 2023
a110ce8
Make it compile
Mubelotix Nov 10, 2023
0c19ddc
Make stuff public
Mubelotix Nov 11, 2023
8146aff
Remove hundreds of warnings
Mubelotix Nov 11, 2023
4e09e2b
Add descendants
Mubelotix Nov 11, 2023
355a4d7
Rename parents to ancestors
Mubelotix Nov 11, 2023
13dee56
Impl TryAsEntityRef for all entities
Mubelotix Nov 11, 2023
b9581fd
Use newer code
Mubelotix Nov 11, 2023
1535c6a
Remove old code
Mubelotix Nov 11, 2023
7d93051
Add tests
Mubelotix Nov 11, 2023
be69933
Make tests pass
Mubelotix Nov 11, 2023
7d05ad6
Fix compiling
Mubelotix Nov 11, 2023
65d605d
Remove println
Mubelotix Nov 11, 2023
28f0468
Add mutate and observe
Mubelotix Nov 11, 2023
4e2ab8b
Fix warnings
Mubelotix Nov 11, 2023
1dcc179
Impl EntityWorldInterface on World
Mubelotix Nov 11, 2023
154dbbe
Finish observe and mutate
Mubelotix Nov 11, 2023
17227a7
Add spawn method
Mubelotix Nov 11, 2023
7248670
Add AnyEntity.as_network
Mubelotix Nov 11, 2023
0b0f86f
Rename as_network to to_network
Mubelotix Nov 11, 2023
b2df45a
Move ecs.rs
Mubelotix Nov 11, 2023
eacba03
Send spawning entities to client
Mubelotix Nov 11, 2023
a2daf45
Allow summoning zombies
Mubelotix Nov 11, 2023
4a6bd21
Add entity tasks
Mubelotix Nov 11, 2023
6984f3e
Turn entity crates to module
Mubelotix Nov 11, 2023
04f26e3
Fix compilation
Mubelotix Nov 11, 2023
14dea99
Simplify observers
Mubelotix Nov 11, 2023
c035549
Add ability to insert tasks
Mubelotix Nov 11, 2023
bf662b9
Add gravity
Mubelotix Nov 11, 2023
fef36c6
Fix example
Mubelotix Nov 11, 2023
9722729
Run TODO to Issue
Mubelotix Nov 11, 2023
018e099
Implement collision detection
Mubelotix Nov 12, 2023
c52b944
Fix algorithm
Mubelotix Nov 12, 2023
91acc40
Add test case
Mubelotix Nov 12, 2023
c67a94d
Add test cases
Mubelotix Nov 12, 2023
aeb7963
Add test cases
Mubelotix Nov 12, 2023
f34d1f9
Fix issue
Mubelotix Nov 13, 2023
9be1871
Optimization
Mubelotix Nov 13, 2023
d066aa5
Adapt ray_cast
Mubelotix Nov 13, 2023
2cf2438
Move code to collisions.rs
Mubelotix Nov 13, 2023
a057b3b
Add test module
Mubelotix Nov 13, 2023
c9ecf2c
Fix compilation
Mubelotix Nov 13, 2023
b20596c
Clean positions.rs
Mubelotix Nov 13, 2023
51ecd33
Make collisions pub
Mubelotix Nov 13, 2023
f10ffe2
Add try_move
Mubelotix Nov 13, 2023
3263ef9
Fix collision fragment
Mubelotix Nov 13, 2023
8c1aa2a
Improve algorithm to reduce imprecisions
Mubelotix Nov 13, 2023
02a97c7
Improve precision
Mubelotix Nov 13, 2023
22f9f0e
Fix last fragment
Mubelotix Nov 13, 2023
f9bfcb3
Merge branch 'main' into poo_experiment2
Mubelotix Nov 13, 2023
e6fe0b2
Finish implementing gravity
Mubelotix Nov 14, 2023
4018403
Generalize on AnyEntity
Mubelotix Nov 14, 2023
0c0bf92
Rename task gravity into newton
Mubelotix Nov 14, 2023
bd469f1
Optimize newton task using EntityChanges
Mubelotix Nov 14, 2023
c5532ab
Fix issue with entity change detection
Mubelotix Nov 14, 2023
40b36ae
Add todo on air resistance
Mubelotix Nov 14, 2023
5c6aee4
Make player report its existence to ECS
Mubelotix Nov 14, 2023
da6f6bb
Make zombie follow player
Mubelotix Nov 14, 2023
5258bfd
fix warning
DimitriTimoz Nov 17, 2023
400d2f9
Update minecraft-server/src/world/collisions.rs
Mubelotix Nov 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ members = [
"minecraft-protocol",
"minecraft-protocol-derive",
"minecraft-server",
"minecraft-entities",
"minecraft-positions",
"tags-macros"
"minecraft-entities-derive",
"minecraft-positions"
]

workspace.resolver = "2"
3 changes: 3 additions & 0 deletions minecraft-entities-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ proc-macro = true

[dependencies]
convert_case = "0.6"
proc-macro-error = "1.0.4"
quote = "1.0"
proc-macro2 = "1.0"
133 changes: 133 additions & 0 deletions minecraft-entities-derive/examples/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
use minecraft_entities_derive::*;

use std::{pin::Pin, future::Future, sync::{Mutex, Arc}};
type CallBack<O> = fn(O) -> Pin<Box<dyn Future<Output = ()> + Sync + Send>>;
type CallBack1<O, I> = fn(O, I) -> Pin<Box<dyn Future<Output = ()> + Sync + Send>>;
type CallBack2<O, I, J> = fn(O, I, J) -> Pin<Box<dyn Future<Output = ()> + Sync + Send>>;
type Eid = u32;

trait TryAsEntityRef<T> {
fn try_as_entity_ref(&self) -> Option<&T>;
fn try_as_entity_mut(&mut self) -> Option<&mut T>;
}

enum AnyEntity {
Entity(Entity),
Animal(Animal),
Cow(Cow),
}

pub struct Handler<T> {
uuid: Eid,
world: Arc<Mutex<()>>,
entity: std::marker::PhantomData<T>,
}

impl<T> Handler<T> {
fn assume(uuid: Eid, world: Arc<Mutex<()>>) -> Self {
Self {
uuid,
world,
entity: std::marker::PhantomData,
}
}

fn assume_other<V>(self) -> Handler<V> {
Handler {
uuid: self.uuid,
world: self.world,
entity: std::marker::PhantomData,
}
}
}

// Entity

#[MinecraftEntity(
inheritable,
ancestors { },
descendants { Animal... },
defines {
on_moved(self, from: f32, to: f32);
on_spawned(self);
}
)]
pub struct Entity {

}

impl Handler<Entity> {
async fn on_moved(self, from: f32, to: f32) {
println!("Entity moved from {} to {}", from, to);
}

async fn on_spawned(self) {
println!("Entity spawned");
}
}

// Animal

#[MinecraftEntity(
inheritable,
ancestors { Entity },
descendants { Cow },
defines {
Entity.on_spawned(self);
on_hit(self, damage: usize);
on_jump(self);
}
)]
pub struct Animal {
entity: Entity,
}

impl Handler<Animal> {
async fn on_hit(self, damage: usize) {
println!("Animal hit with {} damage", damage);
}

async fn on_jump(self) {
println!("Animal jumped");
}

async fn on_spawned(self) {
println!("Animal spawned");
}
}

// Cow

#[MinecraftEntity(
ancestors { Animal, Entity },
defines {
Entity.on_spawned(self);
Animal.on_hit(self, damage: usize);
on_milked(self);
}
)]
pub struct Cow {
animal: Animal,
}

impl Handler<Cow> {
async fn on_milked(self) {
println!("Cow milked");
}

async fn on_hit(self, damage: usize) {
println!("Cow hit with {} damage", damage);
}

async fn on_spawned(self) {
println!("Cow spawned");
}
}

fn main() {
}

#[test]
fn test() {

}
Loading