mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
separated tnt class from all other ones
This commit is contained in:
parent
002f7f0946
commit
218dd4ffa4
10 changed files with 78 additions and 60 deletions
|
|
@ -4,6 +4,7 @@ TODO:
|
|||
move methods
|
||||
*/
|
||||
abstract class Animal extends Creature implements Ageable, Breedable{
|
||||
|
||||
public function isBaby(){
|
||||
if(!isset($this->data["IsBaby"])){
|
||||
$this->data["IsBaby"] = false;
|
||||
|
|
@ -25,4 +26,12 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
}
|
||||
parent::environmentUpdate();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
if($this->isBaby()){
|
||||
return array(
|
||||
array(AIR, 0, 0),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,4 +5,11 @@ move methods
|
|||
*/
|
||||
abstract class Creature extends Living{
|
||||
const CLASS_TYPE = ENTITY_MOB;
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:1, "generic");
|
||||
$this->update();
|
||||
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
|
||||
$this->size = 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -112,15 +112,6 @@ class Entity extends Position{
|
|||
$this->update();
|
||||
$this->size = 0.75;
|
||||
break;
|
||||
case ENTITY_MOB:
|
||||
switch($this->type){
|
||||
default:
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:1, "generic");
|
||||
$this->update();
|
||||
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
|
||||
$this->size = 1;
|
||||
}
|
||||
break;
|
||||
case ENTITY_FALLING:
|
||||
$this->setHealth(PHP_INT_MAX, "generic");
|
||||
$this->update();
|
||||
|
|
@ -135,13 +126,6 @@ class Entity extends Position{
|
|||
$this->size = 1;
|
||||
if($this->type === OBJECT_PAINTING){
|
||||
$this->isStatic = true;
|
||||
}elseif($this->type === OBJECT_PRIMEDTNT){
|
||||
if(!isset($this->data["fuse"])){
|
||||
$this->data["fuse"] = 0;
|
||||
}
|
||||
$this->setHealth(10000000, "generic");
|
||||
$this->server->schedule(5, array($this, "updateFuse"), array(), true);
|
||||
$this->update();
|
||||
}elseif($this->type === OBJECT_SNOWBALL){
|
||||
$this->server->schedule(1210, array($this, "update")); //Despawn
|
||||
$this->update();
|
||||
|
|
@ -157,20 +141,6 @@ class Entity extends Position{
|
|||
}
|
||||
}
|
||||
|
||||
public function updateFuse(){
|
||||
if($this->closed === true){
|
||||
return false;
|
||||
}
|
||||
if($this->type === OBJECT_PRIMEDTNT){
|
||||
$this->updateMetadata();
|
||||
if(((microtime(true) - $this->spawntime) * 20) >= $this->data["fuse"]){
|
||||
$this->close();
|
||||
$explosion = new Explosion($this, $this->data["power"]);
|
||||
$explosion->explode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
if($this->class === ENTITY_PLAYER and $this->player instanceof Player and ($this->player->gamemode & 0x01) === 0){
|
||||
$inv = array();
|
||||
|
|
@ -200,12 +170,6 @@ class Entity extends Position{
|
|||
array(MINECART, 0, 1),
|
||||
);
|
||||
}
|
||||
}elseif($this->class === ENTITY_MOB){
|
||||
if($this->data["IsBaby"]){
|
||||
return array(
|
||||
array(AIR, 0, 0),
|
||||
);
|
||||
}
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
|
@ -609,10 +573,7 @@ class Entity extends Position{
|
|||
16 => array("type" => 0, "value" => 0),
|
||||
17 => array("type" => 6, "value" => array(0, 0, 0)),
|
||||
);
|
||||
if($this->class === ENTITY_OBJECT || $this->class === ENTITY_MOB){ //ladder fix 2.0
|
||||
if($this->type === OBJECT_PRIMEDTNT){
|
||||
$d[16]["value"] = (int) max(0, $this->data["fuse"] - (microtime(true) - $this->spawntime) * 20);
|
||||
}
|
||||
if($this->class === ENTITY_MOB){ //ladder fix 2.0
|
||||
if($this->type === MOB_PIG){ /*Saddled Pig*/
|
||||
$d[16]["value"] = 0;
|
||||
}
|
||||
|
|
@ -720,22 +681,6 @@ class Entity extends Position{
|
|||
$pk->direction = $this->getDirection();
|
||||
$pk->title = $this->data["Motive"];
|
||||
$player->dataPacket($pk);
|
||||
}elseif($this->type === OBJECT_PRIMEDTNT){
|
||||
$pk = new AddEntityPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->type = $this->type;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->did = 0;
|
||||
$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);
|
||||
}elseif($this->type === OBJECT_MINECART){
|
||||
$pk = new AddEntityPacket;
|
||||
$pk->eid = $this->eid;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class EntityRegistry{
|
|||
self::registerEntity(Spider::class);
|
||||
self::registerEntity(Zombie::class);
|
||||
self::registerEntity(Arrow::class);
|
||||
self::registerEntity(PrimedTNT::class);
|
||||
}
|
||||
|
||||
/*Register an Entity*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
class Human extends Creature{
|
||||
const CLASS_TYPE = ENTITY_PLAYER;
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ class Chicken extends Animal{
|
|||
}
|
||||
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? array() :
|
||||
return $this->isBaby() ? parent::getDrops() :
|
||||
array(
|
||||
array(FEATHER, 0, mt_rand(0,2)),
|
||||
array(($this->fire > 0 ? COOKED_CHICKEN : RAW_CHICKEN), 0, 1),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class Cow extends Animal{
|
|||
}
|
||||
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? array() :
|
||||
return $this->isBaby() ? parent::getDrops() :
|
||||
array(
|
||||
array(LEATHER, 0, mt_rand(0,2)),
|
||||
array(($this->fire > 0 ? STEAK:BEEF), 0, 1),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class Pig extends Animal{
|
|||
return $id === POTATO || $id === CARROT || $id === BEETROOT;
|
||||
}
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? array() :
|
||||
return $this->isBaby() ? parent::getDrops() :
|
||||
array(
|
||||
array(($this->fire > 0 ? COOKED_PORKCHOP:RAW_PORKCHOP), 0, 1),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Sheep extends Animal{
|
|||
}
|
||||
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? array() :
|
||||
return $this->isBaby() ? parent::getDrops() :
|
||||
array(
|
||||
array(WOOL, $this->data["Color"] & 0x0F, 1),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
class PrimedTNT extends Entity{
|
||||
const TYPE = OBJECT_PRIMEDTNT;
|
||||
const CLASS_TYPE = ENTITY_OBJECT;
|
||||
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
if(!isset($this->data["fuse"])){
|
||||
$this->data["fuse"] = 0;
|
||||
}
|
||||
$this->setHealth(10000000, "generic");
|
||||
$this->server->schedule(5, array($this, "updateFuse"), array(), true);
|
||||
$this->update();
|
||||
}
|
||||
public function getMetadata(){
|
||||
$d = parent::getMetadata();
|
||||
$d[16]["value"] = (int) max(0, $this->data["fuse"] - (microtime(true) - $this->spawntime) * 20);
|
||||
return $d;
|
||||
}
|
||||
public function updateFuse(){
|
||||
if($this->closed === true){
|
||||
return false;
|
||||
}
|
||||
if($this->type === OBJECT_PRIMEDTNT){
|
||||
$this->updateMetadata();
|
||||
if(((microtime(true) - $this->spawntime) * 20) >= $this->data["fuse"]){
|
||||
$this->close();
|
||||
$explosion = new Explosion($this, $this->data["power"]);
|
||||
$explosion->explode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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->did = 0;
|
||||
$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