simple entity registering, tested on pig, some classes were created, althrough they are still not implemented

This commit is contained in:
GameHerobrine 2022-06-07 00:06:56 +03:00
parent e5abc85f94
commit 6a321aabe0
13 changed files with 116 additions and 4 deletions

View file

@ -0,0 +1,5 @@
<?php
interface Ageable{
}

View file

@ -0,0 +1,8 @@
<?php
/*
TODO:
move methods
*/
class Animal extends Creature implements Ageable{
}

View file

@ -0,0 +1,8 @@
<?php
/*
TODO:
move methods
*/
abstract class Creature extends Living{
const CLASS_TYPE = ENTITY_MOB;
}

View file

@ -0,0 +1,5 @@
<?php
interface Damageable{
}

View file

@ -20,6 +20,8 @@
*/
class Entity extends Position{
const TYPE = -1;
const CLASS_TYPE = -1;
public $age;
public $air;
public $spawntime;
@ -56,7 +58,6 @@ class Entity extends Position{
public $check = true;
public $size = 1;
public $inAction = false;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
$this->level = $level;
$this->fallY = false;

View file

@ -0,0 +1,56 @@
<?php
class PropertyEntity{
private $class,$type,$name;
function __construct($class, $type, $name){
$this->class = $class;
$this->type = $type;
$this->name = $name;
}
public function getEntityClass(){
return $this->class;
}
public function getEntityType(){
return $this->type;
}
public function getEntityName(){
return $this->name;
}
}
class EntityList{
public function getEntities(){
return $this->entities;
}
public function addEntity(PropertyEntity $property){
$this->entities[$property->getEntityType()] = $property;
}
public function getEntityFromType($type){
return isset($this->entities[$type]) ? $this->entities[$type] : 0;
}
private $entities = [];
}
class EntityRegistry{
public static $entityList;
/*Register all entities*/
public static function registerEntities(){
self::$entityList = new EntityList;
self::registerEntity(Pig::class);
}
/*Register an Entity*/
public static function registerEntity($className){
$class = new \ReflectionClass($className);
if(is_a($className, Entity::class, true) and !$class->isAbstract()){
//self::$entityList[$className::TYPE] = $className;
self::$entityList->addEntity(new PropertyEntity($className::CLASS_TYPE, $className::TYPE, $className));
//self::$shortNames[$className] = $class->getShortName(); what is this even supposed to do?
console("Registered a ".$className);
return true;
}
return false;
}
}

View file

@ -0,0 +1,3 @@
<?php
abstract class Living extends Entity implements Damageable{
}

View file

@ -0,0 +1,12 @@
<?php
/*
TODO:
move methods
*/
class Pig extends Animal{
const TYPE = 12;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
console("A constructor which indicates it works! ".":".$eid.":".$class.":".$type);
parent::__construct($level, $eid, $class, $type, $data);
}
}