mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
Minecart is in separated class
This commit is contained in:
parent
5596f58a0a
commit
a75e286337
11 changed files with 515 additions and 32 deletions
|
|
@ -108,8 +108,6 @@ class Entity extends Position{
|
|||
if($this->type === OBJECT_SNOWBALL){
|
||||
$this->server->schedule(1210, array($this, "update")); //Despawn
|
||||
$this->update();
|
||||
}elseif($this->type == OBJECT_MINECART){
|
||||
$this->update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -120,6 +118,22 @@ class Entity extends Position{
|
|||
}
|
||||
}
|
||||
|
||||
public function lookOn($entity){
|
||||
$horizontal = sqrt(pow(($target->entity->x - $entity->x), 2) + pow(($target->entity->z - $entity->z) , 2));
|
||||
$vertical = $target->entity->y - ($entity->y + -0.5); /*0.5 = $entity->getEyeHeight()*/
|
||||
$pitch = -atan2($vertical, $horizontal) / M_PI * 180; //negative is up, positive is down
|
||||
|
||||
$xDist = $target->entity->x - $entity->x;
|
||||
$zDist = $target->entity->z - $entity->z;
|
||||
|
||||
$yaw = atan2($zDist, $xDist) / M_PI * 180 - 90;
|
||||
if($yaw < 0){
|
||||
$yaw += 360.0;
|
||||
}
|
||||
$this->yaw = $yaw;
|
||||
$this->pitch = $pitch;
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
if($this->class === ENTITY_PLAYER and $this->player instanceof Player and ($this->player->gamemode & 0x01) === 0){
|
||||
$inv = array();
|
||||
|
|
@ -138,13 +152,6 @@ class Entity extends Position{
|
|||
}
|
||||
}
|
||||
return $inv;
|
||||
}elseif($this->class === ENTITY_OBJECT){
|
||||
switch($this->type){
|
||||
case OBJECT_MINECART:
|
||||
return array(
|
||||
array(MINECART, 0, 1),
|
||||
);
|
||||
}
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
|
@ -646,26 +653,6 @@ class Entity extends Position{
|
|||
$pk->speedZ = $this->speedZ;
|
||||
$player->dataPacket($pk);
|
||||
break;
|
||||
case ENTITY_OBJECT:
|
||||
if($this->type === OBJECT_MINECART){
|
||||
$pk = new AddEntityPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->type = $this->type;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->speedX = $this->speedX;
|
||||
$pk->speedY = $this->speedY;
|
||||
$pk->speedZ = $this->speedZ;
|
||||
$player->dataPacket($pk);
|
||||
}
|
||||
break;
|
||||
case ENTITY_FALLING:
|
||||
$pk = new AddEntityPacket;
|
||||
$pk->eid = $this->eid;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ class EntityRegistry{
|
|||
public static $entityList;
|
||||
/*Register all entities*/
|
||||
public static function registerEntities(){
|
||||
console("[INFO] Registering entities...");
|
||||
self::$entityList = new EntityList;
|
||||
self::registerEntity(Pig::class);
|
||||
self::registerEntity(Chicken::class);
|
||||
|
|
@ -49,6 +50,7 @@ class EntityRegistry{
|
|||
self::registerEntity(Arrow::class);
|
||||
self::registerEntity(PrimedTNT::class);
|
||||
self::registerEntity(Painting::class);
|
||||
self::registerEntity(Minecart::class);
|
||||
}
|
||||
|
||||
/*Register an Entity*/
|
||||
|
|
@ -58,7 +60,7 @@ class EntityRegistry{
|
|||
//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);
|
||||
//console("[INFO] Registered a ".$className);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
5
src/entity/Rideable.php
Normal file
5
src/entity/Rideable.php
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
interface Rideable{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
abstract class Vehicle extends Entity implements Rideable{
|
||||
const CLASS_TYPE = ENTITY_OBJECT;
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
class Minecart extends Vehicle{
|
||||
const TYPE = OBJECT_MINECART;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x;
|
||||
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y;
|
||||
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z;
|
||||
$this->setHealth(1, "generic");
|
||||
//$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
||||
$this->size = 1;
|
||||
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return array(
|
||||
array(MINECART, 0, 1),
|
||||
);
|
||||
}
|
||||
|
||||
public function spawn($player){
|
||||
$pk = new AddEntityPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->type = $this->type;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->speedX = $this->speedX;
|
||||
$pk->speedY = $this->speedY;
|
||||
$pk->speedZ = $this->speedZ;
|
||||
$player->dataPacket($pk);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue