From 0946e8f3a24ae355c6bfb996eebcf9951c1864b8 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Fri, 24 Feb 2023 11:22:14 +0300 Subject: [PATCH] moved 2 more entities to separate classes, no more 1.0.2 --- src/API/EntityAPI.php | 2 +- src/{network => }/MinecraftInterface.php | 0 src/config.php | 2 +- src/entity/Entity.php | 22 +++------------------- src/entity/animal/Chicken.php | 2 ++ src/entity/object/FallingSand.php | 14 ++++++++++++++ src/entity/object/ItemEntity.php | 22 ++++++++++++++++++++++ src/entity/registry/EntityList.php | 1 + src/entity/registry/EntityRegistry.php | 4 ++++ 9 files changed, 48 insertions(+), 21 deletions(-) rename src/{network => }/MinecraftInterface.php (100%) diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 2361f857..843f7f4a 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -149,7 +149,7 @@ class EntityAPI{ $efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class); if($efl instanceof PropertyEntity){ $class = $efl->getEntityName(); - $this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data); + $this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityClass() === ENTITY_ITEM ? $type : $efl->getEntityType(), $data); }else{ $this->entities[$eid] = new Entity($level, $eid, $class, $type, $data); } diff --git a/src/network/MinecraftInterface.php b/src/MinecraftInterface.php similarity index 100% rename from src/network/MinecraftInterface.php rename to src/MinecraftInterface.php diff --git a/src/config.php b/src/config.php index 33b94ff4..d00996a9 100644 --- a/src/config.php +++ b/src/config.php @@ -48,7 +48,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.2dev"); +define("MAJOR_VERSION", "1.1.0dev"); 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/entity/Entity.php b/src/entity/Entity.php index 7923db4f..a9ec8b6f 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -76,6 +76,7 @@ class Entity extends Position public $position; public $onGround, $inWater; public $carryoverDamage; + public $gravity; function __construct(Level $level, $eid, $class, $type = 0, $data = array()) { $this->random = new Random(); @@ -106,6 +107,7 @@ class Entity extends Position $this->closed = false; $this->isStatic = false; $this->name = ""; + $this->gravity = 0.08; $this->state = $this->data["State"] = isset($this->data["State"]) ? $this->data["State"] : 0; $this->tickCounter = 0; $this->server->query("INSERT OR REPLACE INTO entities (EID, level, type, class, health, hasUpdate) VALUES (" . $this->eid . ", '" . $this->level->getName() . "', " . $this->type . ", " . $this->class . ", " . $this->health . ", 0);"); @@ -141,24 +143,6 @@ class Entity extends Position $this->hasGravity = true; $this->canBeAttacked = true; break; - case ENTITY_ITEM: - if(isset($data["item"]) and ($data["item"] instanceof Item)){ - $this->meta = $this->data["item"]->getMetadata(); - $this->stack = $this->data["item"]->count; - } else{ - $this->meta = (int) $this->data["meta"]; - $this->stack = (int) $this->data["stack"]; - } - $this->hasGravity = true; - $this->setHealth(5, "generic"); - $this->setSize(0.25, 0.25); - break; - case ENTITY_FALLING: - $this->setHealth(PHP_INT_MAX, "generic"); - $this->height = 0.98; - $this->width = 0.98; - $this->hasGravity = true; - break; case ENTITY_OBJECT: $this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x; $this->y = isset($this->data["TileY"]) ? $this->data["TileY"] : $this->y; @@ -658,7 +642,7 @@ class Entity extends Position if($this->hasGravity){ - $this->speedY -= $this->inWater ? 0.02 : (($this->class === ENTITY_FALLING) ? 0.04 : ($this->class === ENTITY_ITEM ? 0.06 : 0.08)); // TODO: replace with $gravity + $this->speedY -= $this->inWater ? 0.02 : ($this->gravity); // TODO: replace with $gravity $update = true; } elseif($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){ // $this->speedX = 0; diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index 0294bef7..599ceb53 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -16,6 +16,8 @@ class Chicken extends Animal{ return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS; } + public function fall(){} //chickens have no fall dmg? + public function update(){ parent::update(); if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){ diff --git a/src/entity/object/FallingSand.php b/src/entity/object/FallingSand.php index e69de29b..108a6ee1 100644 --- a/src/entity/object/FallingSand.php +++ b/src/entity/object/FallingSand.php @@ -0,0 +1,14 @@ +setHealth(PHP_INT_MAX, "generic"); + $this->height = 0.98; + $this->width = 0.98; + $this->hasGravity = true; + $this->gravity = 0.04; + } +} \ No newline at end of file diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index e69de29b..ee98bb25 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -0,0 +1,22 @@ +meta = $this->data["item"]->getMetadata(); + $this->stack = $this->data["item"]->count; + } else{ + $this->meta = (int) $this->data["meta"]; + $this->stack = (int) $this->data["stack"]; + } + $this->hasGravity = true; + $this->setHealth(5, "generic"); + $this->setSize(0.25, 0.25); + $this->gravity = 0.04; + } +} \ No newline at end of file diff --git a/src/entity/registry/EntityList.php b/src/entity/registry/EntityList.php index 615c5820..7d31cfdb 100644 --- a/src/entity/registry/EntityList.php +++ b/src/entity/registry/EntityList.php @@ -8,6 +8,7 @@ class EntityList{ $this->entities[$property->getEntityType()] = $property; } public function getEntityFromTypeAndClass($type, $class){ + if($class === ENTITY_ITEM) return $this->entities["itemSpecial"]; return isset($this->entities[$type]) && $this->entities[$type]->getEntityClass() === $class ? $this->entities[$type] : 0; } private $entities = []; diff --git a/src/entity/registry/EntityRegistry.php b/src/entity/registry/EntityRegistry.php index f8774378..9ad3781b 100644 --- a/src/entity/registry/EntityRegistry.php +++ b/src/entity/registry/EntityRegistry.php @@ -2,6 +2,7 @@ class EntityRegistry{ public static $entityList; + /*Register all entities*/ public static function registerEntities(){ console("[INFO] Registering entities..."); @@ -19,6 +20,8 @@ class EntityRegistry{ self::registerEntity(PrimedTNT::class); self::registerEntity(Painting::class); self::registerEntity(Minecart::class); + self::registerEntity(FallingSand::class); + self::registerEntity(ItemEntity::class); } /*Register an Entity*/ @@ -26,6 +29,7 @@ class EntityRegistry{ $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("[INFO] Registered a ".$className);