From 6a321aabe058cf7c5fa27d4a530018b01c125cee Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 7 Jun 2022 00:06:56 +0300 Subject: [PATCH] simple entity registering, tested on pig, some classes were created, althrough they are still not implemented --- src/API/EntityAPI.php | 9 ++++- src/PocketMinecraftServer.php | 1 + src/config.php | 2 +- src/dependencies.php | 6 +++ src/entity/Ageable.php | 5 +++ src/entity/Animal.php | 8 ++++ src/entity/Creature.php | 8 ++++ src/entity/Damageable.php | 5 +++ src/entity/Entity.php | 3 +- src/entity/EntityRegistry.php | 56 +++++++++++++++++++++++++++ src/entity/Living.php | 3 ++ src/entity/animal/Pig.php | 12 ++++++ src/material/block/solid/Obsidian.php | 2 +- 13 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 src/entity/EntityRegistry.php diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index e4a83231..d9d2ef83 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -270,7 +270,14 @@ class EntityAPI{ public function add(Level $level, $class, $type = 0, $data = array()){ $eid = $this->eCnt++; - $this->entities[$eid] = new Entity($level, $eid, $class, $type, $data); + $efl = EntityRegistry::$entityList->getEntityFromType($type); + if($efl instanceof PropertyEntity){ + $class = $efl->getEntityName(); + console("yey"); + $this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data); + }else{ + $this->entities[$eid] = new Entity($level, $eid, $class, $type, $data); + } $this->server->handle("entity.add", $this->entities[$eid]); return $this->entities[$eid]; } diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 4b00b49e..129debdc 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -31,6 +31,7 @@ class PocketMinecraftServer{ private function load(){ global $dolog; + EntityRegistry::registerEntities(); $this->version = new VersionString(); /*if(defined("DEBUG") and DEBUG >= 0){ @cli_set_process_title("NostalgiaCore ".MAJOR_VERSION); diff --git a/src/config.php b/src/config.php index c2a417bd..bd234c48 100644 --- a/src/config.php +++ b/src/config.php @@ -67,7 +67,7 @@ set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH); ini_set("memory_limit", "256M"); //Default define("LOG", true); define("START_TIME", microtime(true)); -define("MAJOR_VERSION", "1.0.2 (Alpha_1.3.12)"); +define("MAJOR_VERSION", "1.0.2dev (Alpha_1.3.12)"); define("CODENAME", "懐かしさ (Nostalgia)"); //i'm not very creative - kotyaralih define("CURRENT_MINECRAFT_VERSION", "v0.8.1 alpha"); define("CURRENT_API_VERSION", '12.1'); diff --git a/src/dependencies.php b/src/dependencies.php index 59a4fd15..9b9383a0 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -95,6 +95,12 @@ $sha1sum = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; require_once(FILE_PATH."/src/math/Vector3.php"); require_once(FILE_PATH."/src/world/Position.php"); require_once(FILE_PATH."/src/pmf/PMF.php"); +require_once(FILE_PATH."/src/entity/Entity.php"); +require_once(FILE_PATH."/src/entity/Damageable.php"); +require_once(FILE_PATH."/src/entity/Living.php"); +require_once(FILE_PATH."/src/entity/Creature.php"); +require_once(FILE_PATH."/src/entity/Ageable.php"); +require_once(FILE_PATH."/src/entity/Animal.php"); require_all(FILE_PATH . "src/"); diff --git a/src/entity/Ageable.php b/src/entity/Ageable.php index e69de29b..46a48934 100644 --- a/src/entity/Ageable.php +++ b/src/entity/Ageable.php @@ -0,0 +1,5 @@ +level = $level; $this->fallY = false; diff --git a/src/entity/EntityRegistry.php b/src/entity/EntityRegistry.php new file mode 100644 index 00000000..99372db6 --- /dev/null +++ b/src/entity/EntityRegistry.php @@ -0,0 +1,56 @@ +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; + } +} \ No newline at end of file diff --git a/src/entity/Living.php b/src/entity/Living.php index e69de29b..a177696d 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -0,0 +1,3 @@ +isPickaxe() >= 5){ - return 9.4; + return 3.5;//from wiki }else{ return 250; }