mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
Big update about mobs
Removes some array() and some another minor changes.
Cow now drop 0-3 meat.
Pigs can be saddled, and if pig saddled it will drop them.
Creeper can be blown up with flint and steel ("power" => 3).
You can ride on pig (some buggy).
Now Saddle maxStackSize = 1.
Using shears and flint&steel on sheep and creeper they will break.
Saddled will save with closing the server.
This commit is contained in:
parent
2a52e6c69c
commit
f5222be9d2
17 changed files with 221 additions and 180 deletions
101
src/Player.php
101
src/Player.php
|
|
@ -1798,8 +1798,10 @@ class Player{
|
|||
$data["entity"] = $this->entity;
|
||||
if($packet->action === InteractPacket::ACTION_HOLD){
|
||||
switch($target->class){
|
||||
case ENTITY_MOB:
|
||||
case ENTITY_OBJECT:
|
||||
switch($target->type){
|
||||
case MOB_PIG:
|
||||
case OBJECT_MINECART:
|
||||
if($target->linkedEntity != null){
|
||||
break;
|
||||
|
|
@ -1812,35 +1814,53 @@ class Player{
|
|||
$pk->type = 1;
|
||||
$this->dataPacket($pk);
|
||||
$needsBreak = true;
|
||||
|
||||
}
|
||||
case ENTITY_MOB:
|
||||
$slot = $this->getSlot($this->slot);
|
||||
switch($target->type){
|
||||
case MOB_COW:
|
||||
if($slot->getID() === BUCKET && $slot->getMetadata() === 0){ //Empty Bucket
|
||||
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); //remove a bucket
|
||||
$this->addItem(BUCKET, 1, $slot->count, true); //add a milk bucket
|
||||
if($slot->getID() === BUCKET && $slot->getMetadata() === 0){
|
||||
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
$this->addItem(BUCKET, 1, $slot->count, true);
|
||||
$needsBreak = true;
|
||||
}
|
||||
break;
|
||||
case MOB_SHEEP:
|
||||
if($slot->getID() === SHEARS && $target->data["Sheared"] === 0 && !$target->isBaby()){ //not sheared
|
||||
ServerAPI::request()->api->entity->drop(new Position($target->x + 0.5, $target->y, $target->z + 0.5, $target->level), BlockAPI::getItem(WOOL, $target->data["Color"], mt_rand(1, 3)));
|
||||
$target->data["Sheared"] = 1; //i hope it means sheared right?
|
||||
$target->data["Sheared"] = 1;
|
||||
$target->updateMetadata();
|
||||
if($slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}
|
||||
$needsBreak = true;
|
||||
}
|
||||
case MOB_CREEPER:
|
||||
if($slot->getID() === FLINT_AND_STEEL and $target->data["Saddled"] === 0){ //:troll~1:
|
||||
if($slot->useOn($target) and $slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}
|
||||
$target->data["Saddled"] = 1;
|
||||
$target->updateMetadata();
|
||||
$this->server->schedule(30, [$target, "updateFuse"], []); //unknown ticks
|
||||
$needsBreak = true;
|
||||
}
|
||||
case MOB_PIG:
|
||||
if($slot->getID() === SADDLE and $target->data["Saddled"] === 0){
|
||||
$this->removeItem($slot->getID(), 0, 1);
|
||||
$target->data["Saddled"] = 1;
|
||||
$target->updateMetadata();
|
||||
$needsBreak = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($packet->action === InteractPacket::ACTION_VEHICLE_EXIT){
|
||||
switch($target->class){
|
||||
case ENTITY_MOB:
|
||||
case ENTITY_OBJECT:
|
||||
switch($target->type){
|
||||
case MOB_PIG:
|
||||
case OBJECT_MINECART:
|
||||
$players = $this->server->api->player->getAll($this->level);
|
||||
$pk = new SetEntityLinkPacket();
|
||||
|
|
@ -1866,61 +1886,46 @@ class Player{
|
|||
}elseif($this->server->handle("player.interact", $data) !== false){
|
||||
$slot = $this->getSlot($this->slot);
|
||||
switch($slot->getID()){
|
||||
case WOODEN_SWORD:
|
||||
case GOLDEN_SWORD: //damage is correct
|
||||
$damage = 4;
|
||||
break;
|
||||
case STONE_SWORD:
|
||||
$damage = 5;
|
||||
break;
|
||||
case IRON_SWORD:
|
||||
$damage = 6;
|
||||
break;
|
||||
case DIAMOND_SWORD:
|
||||
$damage = 7;
|
||||
break;
|
||||
|
||||
case WOODEN_AXE:
|
||||
case GOLDEN_AXE:
|
||||
$damage = 3;
|
||||
break;
|
||||
case STONE_AXE:
|
||||
$damage = 4;
|
||||
break;
|
||||
case IRON_AXE:
|
||||
$damage = 5;
|
||||
break;
|
||||
case DIAMOND_AXE:
|
||||
$damage = 6;
|
||||
break;
|
||||
|
||||
case WOODEN_PICKAXE:
|
||||
case GOLDEN_PICKAXE:
|
||||
$damage = 2;
|
||||
break;
|
||||
case STONE_PICKAXE:
|
||||
$damage = 3;
|
||||
break;
|
||||
case IRON_PICKAXE:
|
||||
$damage = 4;
|
||||
break;
|
||||
case DIAMOND_PICKAXE:
|
||||
$damage = 5;
|
||||
break;
|
||||
|
||||
case WOODEN_SHOVEL:
|
||||
case GOLDEN_SHOVEL:
|
||||
$damage = 1;
|
||||
break;
|
||||
|
||||
case WOODEN_PICKAXE:
|
||||
case GOLDEN_PICKAXE:
|
||||
case STONE_SHOVEL:
|
||||
$damage = 2;
|
||||
break;
|
||||
|
||||
case WOODEN_AXE:
|
||||
case GOLDEN_AXE:
|
||||
case STONE_PICKAXE:
|
||||
case IRON_SHOVEL:
|
||||
$damage = 3;
|
||||
break;
|
||||
|
||||
case WOODEN_SWORD:
|
||||
case GOLDEN_SWORD:
|
||||
case STONE_AXE:
|
||||
case IRON_PICKAXE:
|
||||
case DIAMOND_SHOVEL:
|
||||
$damage = 4;
|
||||
break;
|
||||
|
||||
case STONE_SWORD:
|
||||
case IRON_AXE:
|
||||
case DIAMOND_PICKAXE:
|
||||
$damage = 5;
|
||||
break;
|
||||
|
||||
case IRON_SWORD:
|
||||
case DIAMOND_AXE:
|
||||
$damage = 6;
|
||||
break;
|
||||
|
||||
case DIAMOND_SWORD:
|
||||
$damage = 7;
|
||||
break;
|
||||
|
||||
default:
|
||||
$damage = 1;//$this->server->difficulty;
|
||||
|
|
@ -1995,7 +2000,7 @@ class Player{
|
|||
PUMPKIN_PIE => 8,
|
||||
CARROT => 4,
|
||||
POTATO => 1,
|
||||
BAKED_POTATO => 6,
|
||||
BAKED_POTATO => 6
|
||||
];
|
||||
$slot = $this->getSlot($this->slot);
|
||||
if($this->entity->getHealth() < 20 and isset($items[$slot->getID()])){
|
||||
|
|
|
|||
|
|
@ -676,14 +676,14 @@ class Entity extends Position{
|
|||
2 -> Integer
|
||||
3 -> Float
|
||||
4 -> Length of <value>, Short
|
||||
5 -> array(Short, Byte, Short)
|
||||
6 -> arry(Integer, Integer, Integer)
|
||||
5 -> [Short, Byte, Short]
|
||||
6 -> [Integer, Integer, Integer]
|
||||
******************
|
||||
0 => array("type" => 0, "value" => $flags) --> DATA_FLAGS
|
||||
1 => array("type" => 1, "value" => $this->air) --> Entity Air
|
||||
14 => array("type" => 0, "value" => 1) --> IsBaby, value: 0 => false, 1 => true
|
||||
16 => array("type" => 0, "value" => 0) --> Fuse(TNT), Saddled(Pig)
|
||||
17 => array("type" => 6, "value" => array(0, 0, 0)) --> Bed Position <?>
|
||||
0 => ["type" => 0, "value" => $flags] --> DATA_FLAGS
|
||||
1 => ["type" => 1, "value" => $this->air] --> Entity Air
|
||||
14 => ["type" => 0, "value" => 1] --> IsBaby, value: 0 => false, 1 => true
|
||||
16 => ["type" => 0, "value" => 0] --> Fuse(TNT), Saddled(Pig)
|
||||
17 => ["type" => 6, "value" => [0, 0, 0]] --> Bed Position <?>
|
||||
|
||||
|
||||
DATA FLAGS IDS
|
||||
|
|
@ -697,21 +697,21 @@ class Entity extends Position{
|
|||
$flags ^= $this->fire > 0 ? 0b1 : 0;
|
||||
$flags ^= ($this->crouched ? 0b1 : 0) << 1;
|
||||
$flags ^= ($this->inAction ? 0b1 : 0) << 4;
|
||||
$d = array(
|
||||
0 => array("type" => 0, "value" => $flags),
|
||||
1 => array("type" => 1, "value" => $this->air),
|
||||
14 => array("type" => 0, "value" => 0),
|
||||
16 => array("type" => 0, "value" => 0),
|
||||
17 => array("type" => 6, "value" => array(0, 0, 0)),
|
||||
);
|
||||
$d = [
|
||||
0 => ["type" => 0, "value" => $flags],
|
||||
1 => ["type" => 1, "value" => $this->air],
|
||||
14 => ["type" => 0, "value" => 0],
|
||||
16 => ["type" => 0, "value" => 0],
|
||||
17 => ["type" => 6, "value" => [0, 0, 0]]
|
||||
];
|
||||
if($this->class === ENTITY_MOB){ //ladder fix 2.0
|
||||
if($this->type === MOB_PIG){ /*Saddled Pig*/
|
||||
$d[16]["value"] = 0;
|
||||
}
|
||||
//if($this->type === MOB_PIG){ /*Saddled Pig*/
|
||||
//$d[16]["value"] = 0;
|
||||
//}
|
||||
}elseif($this->class === ENTITY_PLAYER){
|
||||
if($this->player->isSleeping !== false){
|
||||
$d[16]["value"] = 2;
|
||||
$d[17]["value"] = array($this->player->isSleeping->x, $this->player->isSleeping->y, $this->player->isSleeping->z);
|
||||
$d[17]["value"] = [$this->player->isSleeping->x, $this->player->isSleeping->y, $this->player->isSleeping->z];
|
||||
}
|
||||
}
|
||||
return $d;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
class Chicken extends Animal{
|
||||
const TYPE = MOB_CHICKEN;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->server->schedule(mt_rand(0,6000) + 6000, array($this, "dropAnEgg"));
|
||||
$this->server->schedule(mt_rand(0,6000) + 6000, [$this, "dropAnEgg"]);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic");
|
||||
$this->setName('Chicken');
|
||||
$this->setSize($this->isBaby() ? 0.2 : 0.4, $this->isBaby() ? 0.35 : 0.7);
|
||||
|
|
@ -17,15 +17,14 @@ class Chicken extends Animal{
|
|||
if($this->closed){
|
||||
return;
|
||||
}
|
||||
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(EGG,0,1));
|
||||
$this->server->schedule(mt_rand(0,6000) + 6000, array($this, "dropAnEgg"));
|
||||
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(EGG, 0, 1));
|
||||
$this->server->schedule(mt_rand(0,6000) + 6000, [$this, "dropAnEgg"]);
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? parent::getDrops() :
|
||||
array(
|
||||
array(FEATHER, 0, mt_rand(0,2)),
|
||||
array(($this->fire > 0 ? COOKED_CHICKEN : RAW_CHICKEN), 0, 1),
|
||||
);
|
||||
return $this->isBaby() ? parent::getDrops() : [
|
||||
[FEATHER, 0, mt_rand(0,2)],
|
||||
[[$this->fire > 0 ? COOKED_CHICKEN : RAW_CHICKEN], 0, 1]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,23 +2,23 @@
|
|||
|
||||
class Cow extends Animal{
|
||||
const TYPE = MOB_COW;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
|
||||
$this->setSize($this->isBaby() ? 0.45 : 0.9 , $this->isBaby() ? 0.7 : 1.4);
|
||||
$this->setName('Cow');
|
||||
$this->setName("Cow");
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function isFood($id){
|
||||
return $id === WHEAT;
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? parent::getDrops() :
|
||||
array(
|
||||
array(LEATHER, 0, mt_rand(0,2)),
|
||||
array(($this->fire > 0 ? STEAK:BEEF), 0, 1),
|
||||
);
|
||||
return $this->isBaby() ? parent::getDrops() : [
|
||||
[LEATHER, 0, mt_rand(0,2)],
|
||||
[($this->fire > 0 ? STEAK : BEEF), 0, mt_rand(0, 3)]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,22 +1,34 @@
|
|||
<?php
|
||||
class Pig extends Animal{
|
||||
class Pig extends Animal implements Rideable{
|
||||
const TYPE = MOB_PIG;
|
||||
public $server;
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic");
|
||||
$this->server = ServerAPI::request();
|
||||
$this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.45 : 0.9);
|
||||
$this->setName('Pig');
|
||||
$this->setName("Pig");
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getMetadata(){
|
||||
$d = parent::getMetadata();
|
||||
if(!isset($this->data["Saddled"])){
|
||||
$this->data["Saddled"] = 0;
|
||||
}
|
||||
$d[16]["value"] = ((int)$this->data["Saddled"]);
|
||||
return $d;
|
||||
}
|
||||
|
||||
public function isFood($id){
|
||||
return $id === POTATO || $id === CARROT || $id === BEETROOT;
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? parent::getDrops() :
|
||||
array(
|
||||
array(($this->fire > 0 ? COOKED_PORKCHOP:RAW_PORKCHOP), 0, mt_rand(0,2)),
|
||||
);
|
||||
return $this->isBaby() ? parent::getDrops() : ($this->data["Saddled"] ? [
|
||||
[($this->fire > 0 ? COOKED_PORKCHOP : RAW_PORKCHOP), 0, mt_rand(0,2)],
|
||||
[SADDLE, 0, 1]
|
||||
] : [
|
||||
[($this->fire > 0 ? COOKED_PORKCHOP : RAW_PORKCHOP), 0, mt_rand(0,2)]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,18 @@
|
|||
|
||||
class Sheep extends Animal{
|
||||
const TYPE = MOB_SHEEP;
|
||||
const NOT_SHEARED = 0;
|
||||
const SHEARED = 1;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
|
||||
$this->setName('Sheep');
|
||||
$this->setName("Sheep");
|
||||
$this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.675 : 1.3);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? parent::getDrops() :
|
||||
array(
|
||||
array(WOOL, $this->data["Color"] & 0x0F, 1),
|
||||
);
|
||||
return $this->isBaby() ? parent::getDrops() : [
|
||||
[WOOL, $this->data["Color"] & 0x0F, 1],
|
||||
];
|
||||
}
|
||||
|
||||
public function isFood($id){
|
||||
|
|
@ -26,18 +23,19 @@ class Sheep extends Animal{
|
|||
public function getMetadata(){
|
||||
$d = parent::getMetadata();
|
||||
if(!isset($this->data["Sheared"])){
|
||||
$this->data["Sheared"] = Sheep::NOT_SHEARED;
|
||||
$this->data["Sheared"] = 0;
|
||||
}
|
||||
if(!isset($this->data["Color"])){ //Make a new random color if it is not in data
|
||||
$this->data["Color"] = $this->sheepColor();
|
||||
}
|
||||
$d[16]["value"] = (($this->data["Sheared"] == 1 ? Sheep::SHEARED : Sheep::NOT_SHEARED) << 4) | ($this->data["Color"] & 0x0F); //dark manipulations are happening here...
|
||||
$d[16]["value"] = ($this->data["Sheared"] << 4) | ($this->data["Color"] & 0x0F); //dark manipulations are happening here...
|
||||
return $d;
|
||||
}
|
||||
|
||||
public function sheepColor(){
|
||||
$pink = 0.1558;
|
||||
$brown = 2.85;
|
||||
$lightgray_black_gray = 14.25;
|
||||
$lightgrayBlackGray = 14.25;
|
||||
$chance = Utils::randomFloat() * 100;
|
||||
switch($chance){
|
||||
case($chance <= $pink):
|
||||
|
|
@ -46,8 +44,8 @@ class Sheep extends Animal{
|
|||
case($chance > $pink and $chance <= ($brown+$pink)):
|
||||
$color = 12;
|
||||
break;
|
||||
case($chance > ($brown+$pink) and $chance <= ($lightgray_black_gray+$brown+$pink)):
|
||||
$rand = mt_rand(1,3);
|
||||
case($chance > ($brown+$pink) and $chance <= ($lightgrayBlackGray+$brown+$pink)):
|
||||
$rand = mt_rand(1, 3);
|
||||
if($rand == 1) $color = 15;
|
||||
elseif($rand == 2) $color = 7;
|
||||
else $color = 8;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,41 @@
|
|||
<?php
|
||||
class Creeper extends Monster{
|
||||
const TYPE = MOB_CREEPER;
|
||||
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:16, "generic");
|
||||
$this->setName('Creeper');
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 16, "generic");
|
||||
$this->setName("Creeper");
|
||||
$this->setSize(0.6, 1.7);
|
||||
$this->update();
|
||||
|
||||
if($this->data["Saddled"] === 1){
|
||||
$this->server->schedule(30, [$this, "updateFuse"], []); //unknown ticks
|
||||
}
|
||||
}
|
||||
|
||||
public function getMetadata(){
|
||||
$d = parent::getMetadata();
|
||||
if(!isset($this->data["Saddled"])){
|
||||
$this->data["Saddled"] = 0;
|
||||
}
|
||||
$d[16]["value"] = ((int)$this->data["Saddled"]);
|
||||
return $d;
|
||||
}
|
||||
|
||||
public function updateFuse(){
|
||||
if($this->closed === true){
|
||||
return false;
|
||||
}
|
||||
if($this->type === MOB_CREEPER){
|
||||
$this->updateMetadata();
|
||||
$this->close();
|
||||
$explosion = new Explosion($this, 3);
|
||||
$explosion->explode();
|
||||
}
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return array(
|
||||
array(GUNPOWDER, 0, mt_rand(0,2)),
|
||||
);
|
||||
return $this->data["Saddled"] === 1 ? parent::getDrops() : [
|
||||
[GUNPOWDER, 0, mt_rand(0,2)]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
<?php
|
||||
class PigZombie extends Monster{
|
||||
const TYPE = MOB_PIGMAN;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic");
|
||||
$this->setSize(0.3, 1.95);
|
||||
$this->setName('Pigman');
|
||||
$this->setName("Pigman");
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return array(
|
||||
array(COOKED_PORKCHOP, 0, mt_rand(0,2)),
|
||||
array(GOLD_INGOT, 0, mt_rand(0,1)),
|
||||
);
|
||||
return [
|
||||
[COOKED_PORKCHOP, 0, mt_rand(0,2)],
|
||||
[GOLD_INGOT, 0, mt_rand(0,1)]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,18 @@
|
|||
<?php
|
||||
class Skeleton extends Monster{
|
||||
const TYPE = MOB_SKELETON;
|
||||
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
|
||||
$this->setName('Skeleton');
|
||||
$this->setName("Skeleton");
|
||||
$this->setSize(0.6, 1.99);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return array(
|
||||
array(ARROW, 0, mt_rand(0,2)),
|
||||
array(BONE, 0, mt_rand(0,2)),
|
||||
);
|
||||
return [
|
||||
[ARROW, 0, mt_rand(0,2)],
|
||||
[BONE, 0, mt_rand(0,2)]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,17 @@
|
|||
<?php
|
||||
class Spider extends Monster{
|
||||
const TYPE = MOB_SPIDER;
|
||||
|
||||
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"] : 8, "generic");
|
||||
$this->setName('Spider');
|
||||
$this->setName("Spider");
|
||||
$this->setSize(1.4, 0.9);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return array(
|
||||
array(STRING, 0, mt_rand(0,2)),
|
||||
);
|
||||
return [
|
||||
[STRING, 0, mt_rand(0,2)]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +1,19 @@
|
|||
<?php
|
||||
class Zombie extends Monster{
|
||||
const TYPE = MOB_ZOMBIE;
|
||||
|
||||
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"] : 12, "generic");
|
||||
$this->setName('Zombie');
|
||||
$this->setName("Zombie");
|
||||
$this->setSize(0.6, 1.85);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return array(
|
||||
array(CARROT, 0, Utils::chance(0.83) ? 1 : 0),
|
||||
array(POTATO, 0, Utils::chance(0.83) ? 1 : 0),
|
||||
array(FEATHER, 0, mt_rand(0,2)),
|
||||
);
|
||||
return [
|
||||
[CARROT, 0, Utils::chance(0.83) ? 1 : 0],
|
||||
[POTATO, 0, Utils::chance(0.83) ? 1 : 0],
|
||||
[FEATHER, 0, mt_rand(0,2)]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
class Arrow extends Projectile{
|
||||
const TYPE = OBJECT_ARROW;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
//$this->server->schedule(1210, array($this, "update")); //Despawn
|
||||
}
|
||||
|
||||
public function handleUpdate(){
|
||||
$pk = new MoveEntityPacket_PosRot;
|
||||
$pk->eid = $this->eid;
|
||||
|
|
@ -16,8 +17,8 @@ class Arrow extends Projectile{
|
|||
$pk->pitch = $this->pitch;
|
||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
}
|
||||
|
||||
public function shoot($d, $d1, $d2, $f, $f1){ //original name from 0.8.1 IDA decompilation, var names are taken from b1.7.3
|
||||
|
||||
$f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2);
|
||||
$d /= $f2;
|
||||
$d1 /= $f2;
|
||||
|
|
@ -37,6 +38,7 @@ class Arrow extends Projectile{
|
|||
$this->update();
|
||||
//TODO i guess? $ticksInGround = 0;
|
||||
}
|
||||
|
||||
public function spawn($player){
|
||||
if($this->type === OBJECT_ARROW){
|
||||
$pk = new AddEntityPacket;
|
||||
|
|
|
|||
|
|
@ -2,14 +2,12 @@
|
|||
|
||||
class Minecart extends Vehicle{
|
||||
const TYPE = OBJECT_MINECART;
|
||||
|
||||
private $moveVector = [];
|
||||
const STATE_INITIAL = 0;
|
||||
const STATE_ON_RAIL = 1;
|
||||
const STATE_OFF_RAIL = 2;
|
||||
|
||||
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
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;
|
||||
|
|
@ -25,9 +23,9 @@ class Minecart extends Vehicle{
|
|||
}
|
||||
|
||||
public function getDrops(){
|
||||
return array(
|
||||
array(MINECART, 0, 1),
|
||||
);
|
||||
return [
|
||||
[MINECART, 0, 1]
|
||||
];
|
||||
}
|
||||
|
||||
public function spawn($player){
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class Painting extends Hanging{
|
||||
const TYPE = OBJECT_PAINTING;
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
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;
|
||||
|
|
@ -13,7 +13,9 @@ class Painting extends Hanging{
|
|||
}
|
||||
|
||||
public function getDrops(){
|
||||
return array(array(PAINTING, 0, 1));
|
||||
return [
|
||||
[PAINTING, 0, 1]
|
||||
];
|
||||
}
|
||||
public function spawn($player){
|
||||
$pk = new AddPaintingPacket;
|
||||
|
|
|
|||
|
|
@ -3,21 +3,22 @@
|
|||
class PrimedTNT extends Entity{
|
||||
const TYPE = OBJECT_PRIMEDTNT;
|
||||
const CLASS_TYPE = ENTITY_OBJECT;
|
||||
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
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->server->schedule(5, [$this, "updateFuse"], [], 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;
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ class Item{
|
|||
$this->block = BlockAPI::get($this->id, $this->meta);
|
||||
$this->name = $this->block->getName();
|
||||
}
|
||||
if($this->isTool() || $this->isArmor()){
|
||||
if($this->isTool() || $this->isArmor() || $this->getID() === SADDLE){
|
||||
$this->maxStackSize = 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -209,7 +209,7 @@ class Item{
|
|||
|
||||
}
|
||||
|
||||
public function useOn($object, $force = false){ //move shearing & milking code here?
|
||||
public function useOn($object, $force = false){
|
||||
if($this->isTool() or $force === true){
|
||||
if(($object instanceof Entity) and !$this->isSword()){
|
||||
$this->meta += 2;
|
||||
|
|
@ -221,6 +221,10 @@ class Item{
|
|||
if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){
|
||||
$this->meta++;
|
||||
}
|
||||
}elseif(($object instanceof Crepper) and $this->id === FLINT_STEEL){
|
||||
$this->meta++;
|
||||
}elseif(($object instanceof Sheep) and $this->id === SHEARS){
|
||||
$this->meta++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -234,7 +238,7 @@ class Item{
|
|||
return false;
|
||||
}
|
||||
|
||||
$levels = array(
|
||||
$levels = [
|
||||
2 => 40, //GOLD
|
||||
1 => 59, //WOODEN
|
||||
3 => 131, //STONE
|
||||
|
|
@ -243,7 +247,7 @@ class Item{
|
|||
FLINT_STEEL => 65, //lets assume it is correct
|
||||
SHEARS => 239, //x2
|
||||
BOW => 385 //x3
|
||||
);
|
||||
];
|
||||
|
||||
if(($type = $this->getPickaxeLevel()) === false){
|
||||
if(($type = $this->isAxe()) === false){
|
||||
|
|
@ -261,16 +265,16 @@ class Item{
|
|||
|
||||
public function getPickaxeLevel(){ //Returns false or level of the pickaxe
|
||||
switch($this->id){
|
||||
case IRON_PICKAXE:
|
||||
return 4;
|
||||
case WOODEN_PICKAXE:
|
||||
return 1;
|
||||
case STONE_PICKAXE:
|
||||
return 3;
|
||||
case DIAMOND_PICKAXE:
|
||||
return 5;
|
||||
case GOLDEN_PICKAXE:
|
||||
return 2;
|
||||
case STONE_PICKAXE:
|
||||
return 3;
|
||||
case IRON_PICKAXE:
|
||||
return 4;
|
||||
case DIAMOND_PICKAXE:
|
||||
return 5;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
@ -278,16 +282,16 @@ class Item{
|
|||
|
||||
public function isAxe(){
|
||||
switch($this->id){
|
||||
case IRON_AXE:
|
||||
return 4;
|
||||
case WOODEN_AXE:
|
||||
return 1;
|
||||
case STONE_AXE:
|
||||
return 3;
|
||||
case DIAMOND_AXE:
|
||||
return 5;
|
||||
case GOLDEN_AXE:
|
||||
return 2;
|
||||
case STONE_AXE:
|
||||
return 3;
|
||||
case IRON_AXE:
|
||||
return 4;
|
||||
case DIAMOND_AXE:
|
||||
return 5;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
@ -295,16 +299,16 @@ class Item{
|
|||
|
||||
public function isSword(){
|
||||
switch($this->id){
|
||||
case IRON_SWORD:
|
||||
return 4;
|
||||
case WOODEN_SWORD:
|
||||
return 1;
|
||||
case STONE_SWORD:
|
||||
return 3;
|
||||
case DIAMOND_SWORD:
|
||||
return 5;
|
||||
case GOLDEN_SWORD:
|
||||
return 2;
|
||||
case STONE_SWORD:
|
||||
return 3;
|
||||
case IRON_SWORD:
|
||||
return 4;
|
||||
case DIAMOND_SWORD:
|
||||
return 5;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
@ -312,16 +316,16 @@ class Item{
|
|||
|
||||
public function isShovel(){
|
||||
switch($this->id){
|
||||
case IRON_SHOVEL:
|
||||
return 4;
|
||||
case WOODEN_SHOVEL:
|
||||
return 1;
|
||||
case STONE_SHOVEL:
|
||||
return 3;
|
||||
case DIAMOND_SHOVEL:
|
||||
return 5;
|
||||
case GOLDEN_SHOVEL:
|
||||
return 2;
|
||||
case STONE_SHOVEL:
|
||||
return 3;
|
||||
case IRON_SHOVEL:
|
||||
return 4;
|
||||
case DIAMOND_SHOVEL:
|
||||
return 5;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
@ -329,11 +333,11 @@ class Item{
|
|||
|
||||
public function isHoe(){
|
||||
switch($this->id){
|
||||
case IRON_HOE:
|
||||
case WOODEN_HOE:
|
||||
case STONE_HOE:
|
||||
case DIAMOND_HOE:
|
||||
case GOLDEN_HOE:
|
||||
case STONE_HOE:
|
||||
case IRON_HOE:
|
||||
case DIAMOND_HOE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ class Level{
|
|||
"id" => $entity->type,
|
||||
"Color" => @$entity->data["Color"],
|
||||
"Sheared" => @$entity->data["Sheared"],
|
||||
"Saddled" => @$entity->data["Saddled"],
|
||||
"IsBaby" => @$entity->data["IsBaby"],
|
||||
"Health" => $entity->health,
|
||||
"Pos" => [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue