-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4ab376
commit d1f881c
Showing
10 changed files
with
224 additions
and
8 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.dfsek.terra.minestom; | ||
|
||
import com.dfsek.terra.api.util.vector.Vector3; | ||
|
||
import net.minestom.server.coordinate.Point; | ||
import net.minestom.server.coordinate.Pos; | ||
|
||
|
||
public class MinestomAdapter { | ||
public static Vector3 adapt(Point point) { | ||
return Vector3.of(point.x(), point.y(), point.z()); | ||
} | ||
|
||
public static Pos adapt(Vector3 vector) { | ||
return new Pos(vector.getX(), vector.getY(), vector.getZ()); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/EntityFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.dfsek.terra.minestom.api; | ||
|
||
|
||
import net.minestom.server.entity.Entity; | ||
import net.minestom.server.entity.EntityType; | ||
|
||
|
||
/** | ||
* Allows adding AI to generated entities using custom entity types | ||
*/ | ||
public interface EntityFactory { | ||
Entity createEntity(EntityType type); | ||
} |
14 changes: 14 additions & 0 deletions
14
platforms/minestom/src/main/java/com/dfsek/terra/minestom/entity/DefaultEntityFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.dfsek.terra.minestom.entity; | ||
|
||
import com.dfsek.terra.minestom.api.EntityFactory; | ||
|
||
import net.minestom.server.entity.Entity; | ||
import net.minestom.server.entity.EntityType; | ||
|
||
|
||
public class DefaultEntityFactory implements EntityFactory { | ||
@Override | ||
public Entity createEntity(EntityType type) { | ||
return new Entity(type); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
platforms/minestom/src/main/java/com/dfsek/terra/minestom/entity/DeferredMinestomEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.dfsek.terra.minestom.entity; | ||
|
||
import com.dfsek.terra.api.entity.Entity; | ||
import com.dfsek.terra.api.entity.EntityType; | ||
import com.dfsek.terra.api.util.vector.Vector3; | ||
import com.dfsek.terra.api.world.ServerWorld; | ||
import com.dfsek.terra.minestom.world.TerraMinestomWorld; | ||
|
||
|
||
public class DeferredMinestomEntity implements Entity { | ||
private final EntityType type; | ||
private double x; | ||
private double y; | ||
private double z; | ||
private TerraMinestomWorld world; | ||
|
||
public DeferredMinestomEntity(double x, double y, double z, EntityType type, TerraMinestomWorld world) { | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
this.type = type; | ||
this.world = world; | ||
} | ||
|
||
@Override | ||
public Vector3 position() { | ||
return Vector3.of(x, y, z); | ||
} | ||
|
||
@Override | ||
public void position(Vector3 position) { | ||
x = position.getX(); | ||
y = position.getY(); | ||
z = position.getZ(); | ||
} | ||
|
||
@Override | ||
public void world(ServerWorld world) { | ||
this.world = (TerraMinestomWorld) world; | ||
} | ||
|
||
@Override | ||
public ServerWorld world() { | ||
return world; | ||
} | ||
|
||
@Override | ||
public Object getHandle() { | ||
return this; | ||
} | ||
|
||
public void spawn() { | ||
int chunkX = (int) x >> 4; | ||
int chunkZ = (int) z >> 4; | ||
|
||
if(!world.getHandle().isChunkLoaded(chunkX, chunkZ)) { | ||
return; | ||
} | ||
|
||
MinestomEntity.spawn(x, y, z, type, world); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
platforms/minestom/src/main/java/com/dfsek/terra/minestom/entity/MinestomEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.dfsek.terra.minestom.entity; | ||
|
||
import com.dfsek.terra.api.entity.EntityType; | ||
import com.dfsek.terra.api.util.vector.Vector3; | ||
import com.dfsek.terra.api.world.ServerWorld; | ||
|
||
import com.dfsek.terra.minestom.MinestomAdapter; | ||
import com.dfsek.terra.minestom.world.TerraMinestomWorld; | ||
|
||
import net.minestom.server.coordinate.Pos; | ||
import net.minestom.server.entity.Entity; | ||
import net.minestom.server.instance.Instance; | ||
|
||
|
||
public class MinestomEntity implements com.dfsek.terra.api.entity.Entity { | ||
private final Entity delegate; | ||
private final TerraMinestomWorld world; | ||
|
||
public MinestomEntity(Entity delegate, TerraMinestomWorld world) { | ||
this.delegate = delegate; | ||
this.world = world; | ||
} | ||
|
||
@Override | ||
public Vector3 position() { | ||
return MinestomAdapter.adapt(delegate.getPosition()); | ||
} | ||
|
||
@Override | ||
public void position(Vector3 position) { | ||
delegate.teleport(MinestomAdapter.adapt(position)); | ||
} | ||
|
||
@Override | ||
public void world(ServerWorld world) { | ||
delegate.setInstance(((TerraMinestomWorld) world).getHandle()); | ||
} | ||
|
||
@Override | ||
public ServerWorld world() { | ||
return world; | ||
} | ||
|
||
@Override | ||
public Object getHandle() { | ||
return delegate; | ||
} | ||
|
||
public static MinestomEntity spawn(double x, double y, double z, EntityType type, TerraMinestomWorld world) { | ||
Instance instance = world.getHandle(); | ||
Entity entity = world.getEntityFactory().createEntity(((MinestomEntityType) type).getHandle()); | ||
entity.setInstance(instance, new Pos(x, y, z)); | ||
return new MinestomEntity(entity, world); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
platforms/minestom/src/main/java/com/dfsek/terra/minestom/entity/MinestomEntityType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.dfsek.terra.minestom.entity; | ||
|
||
|
||
import net.minestom.server.entity.EntityType; | ||
|
||
|
||
public class MinestomEntityType implements com.dfsek.terra.api.entity.EntityType { | ||
private final EntityType delegate; | ||
|
||
public MinestomEntityType(String id) { | ||
delegate = EntityType.fromNamespaceId(id); | ||
} | ||
|
||
@Override | ||
public EntityType getHandle() { | ||
return delegate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters