mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
moved 2 more entities to separate classes, no more 1.0.2
This commit is contained in:
parent
96bb79cdcb
commit
0946e8f3a2
9 changed files with 48 additions and 21 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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()){
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
class FallingSand extends Entity{
|
||||
const TYPE = FALLING_SAND;
|
||||
const CLASS_TYPE = ENTITY_FALLING;
|
||||
public function __construct($level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(PHP_INT_MAX, "generic");
|
||||
$this->height = 0.98;
|
||||
$this->width = 0.98;
|
||||
$this->hasGravity = true;
|
||||
$this->gravity = 0.04;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
class ItemEntity extends Entity{
|
||||
const TYPE = "itemSpecial";
|
||||
const CLASS_TYPE = ENTITY_ITEM;
|
||||
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array())
|
||||
{
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
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);
|
||||
$this->gravity = 0.04;
|
||||
}
|
||||
}
|
||||
|
|
@ -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 = [];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue