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:
ArkQuark 2022-10-30 18:13:37 +03:00
parent 2a52e6c69c
commit f5222be9d2
17 changed files with 221 additions and 180 deletions

View file

@ -1798,8 +1798,10 @@ class Player{
$data["entity"] = $this->entity; $data["entity"] = $this->entity;
if($packet->action === InteractPacket::ACTION_HOLD){ if($packet->action === InteractPacket::ACTION_HOLD){
switch($target->class){ switch($target->class){
case ENTITY_MOB:
case ENTITY_OBJECT: case ENTITY_OBJECT:
switch($target->type){ switch($target->type){
case MOB_PIG:
case OBJECT_MINECART: case OBJECT_MINECART:
if($target->linkedEntity != null){ if($target->linkedEntity != null){
break; break;
@ -1812,35 +1814,53 @@ class Player{
$pk->type = 1; $pk->type = 1;
$this->dataPacket($pk); $this->dataPacket($pk);
$needsBreak = true; $needsBreak = true;
} }
case ENTITY_MOB: case ENTITY_MOB:
$slot = $this->getSlot($this->slot); $slot = $this->getSlot($this->slot);
switch($target->type){ switch($target->type){
case MOB_COW: case MOB_COW:
if($slot->getID() === BUCKET && $slot->getMetadata() === 0){ //Empty Bucket if($slot->getID() === BUCKET && $slot->getMetadata() === 0){
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); //remove a bucket $this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
$this->addItem(BUCKET, 1, $slot->count, true); //add a milk bucket $this->addItem(BUCKET, 1, $slot->count, true);
$needsBreak = true; $needsBreak = true;
} }
break; break;
case MOB_SHEEP: case MOB_SHEEP:
if($slot->getID() === SHEARS && $target->data["Sheared"] === 0 && !$target->isBaby()){ //not sheared 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))); 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(); $target->updateMetadata();
if($slot->getMetadata() >= $slot->getMaxDurability()){ if($slot->getMetadata() >= $slot->getMaxDurability()){
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); $this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
} }
$needsBreak = 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){ if($packet->action === InteractPacket::ACTION_VEHICLE_EXIT){
switch($target->class){ switch($target->class){
case ENTITY_MOB:
case ENTITY_OBJECT: case ENTITY_OBJECT:
switch($target->type){ switch($target->type){
case MOB_PIG:
case OBJECT_MINECART: case OBJECT_MINECART:
$players = $this->server->api->player->getAll($this->level); $players = $this->server->api->player->getAll($this->level);
$pk = new SetEntityLinkPacket(); $pk = new SetEntityLinkPacket();
@ -1866,61 +1886,46 @@ class Player{
}elseif($this->server->handle("player.interact", $data) !== false){ }elseif($this->server->handle("player.interact", $data) !== false){
$slot = $this->getSlot($this->slot); $slot = $this->getSlot($this->slot);
switch($slot->getID()){ 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 WOODEN_SHOVEL:
case GOLDEN_SHOVEL: case GOLDEN_SHOVEL:
$damage = 1; $damage = 1;
break; break;
case WOODEN_PICKAXE:
case GOLDEN_PICKAXE:
case STONE_SHOVEL: case STONE_SHOVEL:
$damage = 2; $damage = 2;
break; break;
case WOODEN_AXE:
case GOLDEN_AXE:
case STONE_PICKAXE:
case IRON_SHOVEL: case IRON_SHOVEL:
$damage = 3; $damage = 3;
break; break;
case WOODEN_SWORD:
case GOLDEN_SWORD:
case STONE_AXE:
case IRON_PICKAXE:
case DIAMOND_SHOVEL: case DIAMOND_SHOVEL:
$damage = 4; $damage = 4;
break; 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: default:
$damage = 1;//$this->server->difficulty; $damage = 1;//$this->server->difficulty;
@ -1995,7 +2000,7 @@ class Player{
PUMPKIN_PIE => 8, PUMPKIN_PIE => 8,
CARROT => 4, CARROT => 4,
POTATO => 1, POTATO => 1,
BAKED_POTATO => 6, BAKED_POTATO => 6
]; ];
$slot = $this->getSlot($this->slot); $slot = $this->getSlot($this->slot);
if($this->entity->getHealth() < 20 and isset($items[$slot->getID()])){ if($this->entity->getHealth() < 20 and isset($items[$slot->getID()])){

View file

@ -676,14 +676,14 @@ class Entity extends Position{
2 -> Integer 2 -> Integer
3 -> Float 3 -> Float
4 -> Length of <value>, Short 4 -> Length of <value>, Short
5 -> array(Short, Byte, Short) 5 -> [Short, Byte, Short]
6 -> arry(Integer, Integer, Integer) 6 -> [Integer, Integer, Integer]
****************** ******************
0 => array("type" => 0, "value" => $flags) --> DATA_FLAGS 0 => ["type" => 0, "value" => $flags] --> DATA_FLAGS
1 => array("type" => 1, "value" => $this->air) --> Entity Air 1 => ["type" => 1, "value" => $this->air] --> Entity Air
14 => array("type" => 0, "value" => 1) --> IsBaby, value: 0 => false, 1 => true 14 => ["type" => 0, "value" => 1] --> IsBaby, value: 0 => false, 1 => true
16 => array("type" => 0, "value" => 0) --> Fuse(TNT), Saddled(Pig) 16 => ["type" => 0, "value" => 0] --> Fuse(TNT), Saddled(Pig)
17 => array("type" => 6, "value" => array(0, 0, 0)) --> Bed Position <?> 17 => ["type" => 6, "value" => [0, 0, 0]] --> Bed Position <?>
DATA FLAGS IDS DATA FLAGS IDS
@ -697,21 +697,21 @@ class Entity extends Position{
$flags ^= $this->fire > 0 ? 0b1 : 0; $flags ^= $this->fire > 0 ? 0b1 : 0;
$flags ^= ($this->crouched ? 0b1 : 0) << 1; $flags ^= ($this->crouched ? 0b1 : 0) << 1;
$flags ^= ($this->inAction ? 0b1 : 0) << 4; $flags ^= ($this->inAction ? 0b1 : 0) << 4;
$d = array( $d = [
0 => array("type" => 0, "value" => $flags), 0 => ["type" => 0, "value" => $flags],
1 => array("type" => 1, "value" => $this->air), 1 => ["type" => 1, "value" => $this->air],
14 => array("type" => 0, "value" => 0), 14 => ["type" => 0, "value" => 0],
16 => array("type" => 0, "value" => 0), 16 => ["type" => 0, "value" => 0],
17 => array("type" => 6, "value" => array(0, 0, 0)), 17 => ["type" => 6, "value" => [0, 0, 0]]
); ];
if($this->class === ENTITY_MOB){ //ladder fix 2.0 if($this->class === ENTITY_MOB){ //ladder fix 2.0
if($this->type === MOB_PIG){ /*Saddled Pig*/ //if($this->type === MOB_PIG){ /*Saddled Pig*/
$d[16]["value"] = 0; //$d[16]["value"] = 0;
} //}
}elseif($this->class === ENTITY_PLAYER){ }elseif($this->class === ENTITY_PLAYER){
if($this->player->isSleeping !== false){ if($this->player->isSleeping !== false){
$d[16]["value"] = 2; $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; return $d;

View file

@ -2,9 +2,9 @@
class Chicken extends Animal{ class Chicken extends Animal{
const TYPE = MOB_CHICKEN; 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); 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->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic");
$this->setName('Chicken'); $this->setName('Chicken');
$this->setSize($this->isBaby() ? 0.2 : 0.4, $this->isBaby() ? 0.35 : 0.7); $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){ if($this->closed){
return; 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)); 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")); $this->server->schedule(mt_rand(0,6000) + 6000, [$this, "dropAnEgg"]);
} }
public function getDrops(){ public function getDrops(){
return $this->isBaby() ? parent::getDrops() : return $this->isBaby() ? parent::getDrops() : [
array( [FEATHER, 0, mt_rand(0,2)],
array(FEATHER, 0, mt_rand(0,2)), [[$this->fire > 0 ? COOKED_CHICKEN : RAW_CHICKEN], 0, 1]
array(($this->fire > 0 ? COOKED_CHICKEN : RAW_CHICKEN), 0, 1), ];
);
} }
} }

View file

@ -2,23 +2,23 @@
class Cow extends Animal{ class Cow extends Animal{
const TYPE = MOB_COW; 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); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); $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->setSize($this->isBaby() ? 0.45 : 0.9 , $this->isBaby() ? 0.7 : 1.4);
$this->setName('Cow'); $this->setName("Cow");
$this->update(); $this->update();
} }
public function isFood($id){ public function isFood($id){
return $id === WHEAT; return $id === WHEAT;
} }
public function getDrops(){ public function getDrops(){
return $this->isBaby() ? parent::getDrops() : return $this->isBaby() ? parent::getDrops() : [
array( [LEATHER, 0, mt_rand(0,2)],
array(LEATHER, 0, mt_rand(0,2)), [($this->fire > 0 ? STEAK : BEEF), 0, mt_rand(0, 3)]
array(($this->fire > 0 ? STEAK:BEEF), 0, 1), ];
);
} }
} }

View file

@ -1,22 +1,34 @@
<?php <?php
class Pig extends Animal{ class Pig extends Animal implements Rideable{
const TYPE = MOB_PIG; const TYPE = MOB_PIG;
public $server; public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic"); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic");
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.45 : 0.9); $this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.45 : 0.9);
$this->setName('Pig'); $this->setName("Pig");
$this->update(); $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){ public function isFood($id){
return $id === POTATO || $id === CARROT || $id === BEETROOT; return $id === POTATO || $id === CARROT || $id === BEETROOT;
} }
public function getDrops(){ public function getDrops(){
return $this->isBaby() ? parent::getDrops() : return $this->isBaby() ? parent::getDrops() : ($this->data["Saddled"] ? [
array( [($this->fire > 0 ? COOKED_PORKCHOP : RAW_PORKCHOP), 0, mt_rand(0,2)],
array(($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)]
]);
} }
} }

View file

@ -2,21 +2,18 @@
class Sheep extends Animal{ class Sheep extends Animal{
const TYPE = MOB_SHEEP; const TYPE = MOB_SHEEP;
const NOT_SHEARED = 0; function __construct(Level $level, $eid, $class, $type = 0, $data = []){
const SHEARED = 1;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic"); $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->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.675 : 1.3);
$this->update(); $this->update();
} }
public function getDrops(){ public function getDrops(){
return $this->isBaby() ? parent::getDrops() : return $this->isBaby() ? parent::getDrops() : [
array( [WOOL, $this->data["Color"] & 0x0F, 1],
array(WOOL, $this->data["Color"] & 0x0F, 1), ];
);
} }
public function isFood($id){ public function isFood($id){
@ -26,18 +23,19 @@ class Sheep extends Animal{
public function getMetadata(){ public function getMetadata(){
$d = parent::getMetadata(); $d = parent::getMetadata();
if(!isset($this->data["Sheared"])){ 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 if(!isset($this->data["Color"])){ //Make a new random color if it is not in data
$this->data["Color"] = $this->sheepColor(); $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; return $d;
} }
public function sheepColor(){ public function sheepColor(){
$pink = 0.1558; $pink = 0.1558;
$brown = 2.85; $brown = 2.85;
$lightgray_black_gray = 14.25; $lightgrayBlackGray = 14.25;
$chance = Utils::randomFloat() * 100; $chance = Utils::randomFloat() * 100;
switch($chance){ switch($chance){
case($chance <= $pink): case($chance <= $pink):
@ -46,8 +44,8 @@ class Sheep extends Animal{
case($chance > $pink and $chance <= ($brown+$pink)): case($chance > $pink and $chance <= ($brown+$pink)):
$color = 12; $color = 12;
break; break;
case($chance > ($brown+$pink) and $chance <= ($lightgray_black_gray+$brown+$pink)): case($chance > ($brown+$pink) and $chance <= ($lightgrayBlackGray+$brown+$pink)):
$rand = mt_rand(1,3); $rand = mt_rand(1, 3);
if($rand == 1) $color = 15; if($rand == 1) $color = 15;
elseif($rand == 2) $color = 7; elseif($rand == 2) $color = 7;
else $color = 8; else $color = 8;

View file

@ -1,19 +1,41 @@
<?php <?php
class Creeper extends Monster{ class Creeper extends Monster{
const TYPE = MOB_CREEPER; const TYPE = MOB_CREEPER;
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:16, "generic"); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 16, "generic");
$this->setName('Creeper'); $this->setName("Creeper");
$this->setSize(0.6, 1.7); $this->setSize(0.6, 1.7);
$this->update(); $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(){ public function getDrops(){
return array( return $this->data["Saddled"] === 1 ? parent::getDrops() : [
array(GUNPOWDER, 0, mt_rand(0,2)), [GUNPOWDER, 0, mt_rand(0,2)]
); ];
} }
} }

View file

@ -1,18 +1,18 @@
<?php <?php
class PigZombie extends Monster{ class PigZombie extends Monster{
const TYPE = MOB_PIGMAN; 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); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic"); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic");
$this->setSize(0.3, 1.95); $this->setSize(0.3, 1.95);
$this->setName('Pigman'); $this->setName("Pigman");
$this->update(); $this->update();
} }
public function getDrops(){ public function getDrops(){
return array( return [
array(COOKED_PORKCHOP, 0, mt_rand(0,2)), [COOKED_PORKCHOP, 0, mt_rand(0,2)],
array(GOLD_INGOT, 0, mt_rand(0,1)), [GOLD_INGOT, 0, mt_rand(0,1)]
); ];
} }
} }

View file

@ -1,19 +1,18 @@
<?php <?php
class Skeleton extends Monster{ class Skeleton extends Monster{
const TYPE = MOB_SKELETON; const TYPE = MOB_SKELETON;
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
$this->setName('Skeleton'); $this->setName("Skeleton");
$this->setSize(0.6, 1.99); $this->setSize(0.6, 1.99);
$this->update(); $this->update();
} }
public function getDrops(){ public function getDrops(){
return array( return [
array(ARROW, 0, mt_rand(0,2)), [ARROW, 0, mt_rand(0,2)],
array(BONE, 0, mt_rand(0,2)), [BONE, 0, mt_rand(0,2)]
); ];
} }
} }

View file

@ -1,18 +1,17 @@
<?php <?php
class Spider extends Monster{ class Spider extends Monster{
const TYPE = MOB_SPIDER; const TYPE = MOB_SPIDER;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic"); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
$this->setName('Spider'); $this->setName("Spider");
$this->setSize(1.4, 0.9); $this->setSize(1.4, 0.9);
$this->update(); $this->update();
} }
public function getDrops(){ public function getDrops(){
return array( return [
array(STRING, 0, mt_rand(0,2)), [STRING, 0, mt_rand(0,2)]
); ];
} }
} }

View file

@ -1,20 +1,19 @@
<?php <?php
class Zombie extends Monster{ class Zombie extends Monster{
const TYPE = MOB_ZOMBIE; const TYPE = MOB_ZOMBIE;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic"); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic");
$this->setName('Zombie'); $this->setName("Zombie");
$this->setSize(0.6, 1.85); $this->setSize(0.6, 1.85);
$this->update(); $this->update();
} }
public function getDrops(){ public function getDrops(){
return array( return [
array(CARROT, 0, Utils::chance(0.83) ? 1 : 0), [CARROT, 0, Utils::chance(0.83) ? 1 : 0],
array(POTATO, 0, Utils::chance(0.83) ? 1 : 0), [POTATO, 0, Utils::chance(0.83) ? 1 : 0],
array(FEATHER, 0, mt_rand(0,2)), [FEATHER, 0, mt_rand(0,2)]
); ];
} }
} }

View file

@ -2,10 +2,11 @@
class Arrow extends Projectile{ class Arrow extends Projectile{
const TYPE = OBJECT_ARROW; 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); parent::__construct($level, $eid, $class, $type, $data);
//$this->server->schedule(1210, array($this, "update")); //Despawn //$this->server->schedule(1210, array($this, "update")); //Despawn
} }
public function handleUpdate(){ public function handleUpdate(){
$pk = new MoveEntityPacket_PosRot; $pk = new MoveEntityPacket_PosRot;
$pk->eid = $this->eid; $pk->eid = $this->eid;
@ -16,8 +17,8 @@ class Arrow extends Projectile{
$pk->pitch = $this->pitch; $pk->pitch = $this->pitch;
$this->server->api->player->broadcastPacket($this->level->players, $pk); $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 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); $f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2);
$d /= $f2; $d /= $f2;
$d1 /= $f2; $d1 /= $f2;
@ -37,6 +38,7 @@ class Arrow extends Projectile{
$this->update(); $this->update();
//TODO i guess? $ticksInGround = 0; //TODO i guess? $ticksInGround = 0;
} }
public function spawn($player){ public function spawn($player){
if($this->type === OBJECT_ARROW){ if($this->type === OBJECT_ARROW){
$pk = new AddEntityPacket; $pk = new AddEntityPacket;

View file

@ -2,14 +2,12 @@
class Minecart extends Vehicle{ class Minecart extends Vehicle{
const TYPE = OBJECT_MINECART; const TYPE = OBJECT_MINECART;
private $moveVector = []; private $moveVector = [];
const STATE_INITIAL = 0; const STATE_INITIAL = 0;
const STATE_ON_RAIL = 1; const STATE_ON_RAIL = 1;
const STATE_OFF_RAIL = 2; const STATE_OFF_RAIL = 2;
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x; $this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x;
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y; $this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y;
@ -25,9 +23,9 @@ class Minecart extends Vehicle{
} }
public function getDrops(){ public function getDrops(){
return array( return [
array(MINECART, 0, 1), [MINECART, 0, 1]
); ];
} }
public function spawn($player){ public function spawn($player){

View file

@ -2,7 +2,7 @@
class Painting extends Hanging{ class Painting extends Hanging{
const TYPE = OBJECT_PAINTING; 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); parent::__construct($level, $eid, $class, $type, $data);
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x; $this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x;
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y; $this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y;
@ -13,7 +13,9 @@ class Painting extends Hanging{
} }
public function getDrops(){ public function getDrops(){
return array(array(PAINTING, 0, 1)); return [
[PAINTING, 0, 1]
];
} }
public function spawn($player){ public function spawn($player){
$pk = new AddPaintingPacket; $pk = new AddPaintingPacket;

View file

@ -3,21 +3,22 @@
class PrimedTNT extends Entity{ class PrimedTNT extends Entity{
const TYPE = OBJECT_PRIMEDTNT; const TYPE = OBJECT_PRIMEDTNT;
const CLASS_TYPE = ENTITY_OBJECT; const CLASS_TYPE = ENTITY_OBJECT;
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
if(!isset($this->data["fuse"])){ if(!isset($this->data["fuse"])){
$this->data["fuse"] = 0; $this->data["fuse"] = 0;
} }
$this->setHealth(10000000, "generic"); $this->setHealth(10000000, "generic");
$this->server->schedule(5, array($this, "updateFuse"), array(), true); $this->server->schedule(5, [$this, "updateFuse"], [], true);
$this->update(); $this->update();
} }
public function getMetadata(){ public function getMetadata(){
$d = parent::getMetadata(); $d = parent::getMetadata();
$d[16]["value"] = (int) max(0, $this->data["fuse"] - (microtime(true) - $this->spawntime) * 20); $d[16]["value"] = (int) max(0, $this->data["fuse"] - (microtime(true) - $this->spawntime) * 20);
return $d; return $d;
} }
public function updateFuse(){ public function updateFuse(){
if($this->closed === true){ if($this->closed === true){
return false; return false;

View file

@ -145,7 +145,7 @@ class Item{
$this->block = BlockAPI::get($this->id, $this->meta); $this->block = BlockAPI::get($this->id, $this->meta);
$this->name = $this->block->getName(); $this->name = $this->block->getName();
} }
if($this->isTool() || $this->isArmor()){ if($this->isTool() || $this->isArmor() || $this->getID() === SADDLE){
$this->maxStackSize = 1; $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($this->isTool() or $force === true){
if(($object instanceof Entity) and !$this->isSword()){ if(($object instanceof Entity) and !$this->isSword()){
$this->meta += 2; $this->meta += 2;
@ -221,6 +221,10 @@ class Item{
if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){ if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){
$this->meta++; $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; return false;
} }
@ -234,7 +238,7 @@ class Item{
return false; return false;
} }
$levels = array( $levels = [
2 => 40, //GOLD 2 => 40, //GOLD
1 => 59, //WOODEN 1 => 59, //WOODEN
3 => 131, //STONE 3 => 131, //STONE
@ -243,7 +247,7 @@ class Item{
FLINT_STEEL => 65, //lets assume it is correct FLINT_STEEL => 65, //lets assume it is correct
SHEARS => 239, //x2 SHEARS => 239, //x2
BOW => 385 //x3 BOW => 385 //x3
); ];
if(($type = $this->getPickaxeLevel()) === false){ if(($type = $this->getPickaxeLevel()) === false){
if(($type = $this->isAxe()) === false){ if(($type = $this->isAxe()) === false){
@ -261,16 +265,16 @@ class Item{
public function getPickaxeLevel(){ //Returns false or level of the pickaxe public function getPickaxeLevel(){ //Returns false or level of the pickaxe
switch($this->id){ switch($this->id){
case IRON_PICKAXE:
return 4;
case WOODEN_PICKAXE: case WOODEN_PICKAXE:
return 1; return 1;
case STONE_PICKAXE:
return 3;
case DIAMOND_PICKAXE:
return 5;
case GOLDEN_PICKAXE: case GOLDEN_PICKAXE:
return 2; return 2;
case STONE_PICKAXE:
return 3;
case IRON_PICKAXE:
return 4;
case DIAMOND_PICKAXE:
return 5;
default: default:
return false; return false;
} }
@ -278,16 +282,16 @@ class Item{
public function isAxe(){ public function isAxe(){
switch($this->id){ switch($this->id){
case IRON_AXE:
return 4;
case WOODEN_AXE: case WOODEN_AXE:
return 1; return 1;
case STONE_AXE:
return 3;
case DIAMOND_AXE:
return 5;
case GOLDEN_AXE: case GOLDEN_AXE:
return 2; return 2;
case STONE_AXE:
return 3;
case IRON_AXE:
return 4;
case DIAMOND_AXE:
return 5;
default: default:
return false; return false;
} }
@ -295,16 +299,16 @@ class Item{
public function isSword(){ public function isSword(){
switch($this->id){ switch($this->id){
case IRON_SWORD:
return 4;
case WOODEN_SWORD: case WOODEN_SWORD:
return 1; return 1;
case STONE_SWORD:
return 3;
case DIAMOND_SWORD:
return 5;
case GOLDEN_SWORD: case GOLDEN_SWORD:
return 2; return 2;
case STONE_SWORD:
return 3;
case IRON_SWORD:
return 4;
case DIAMOND_SWORD:
return 5;
default: default:
return false; return false;
} }
@ -312,16 +316,16 @@ class Item{
public function isShovel(){ public function isShovel(){
switch($this->id){ switch($this->id){
case IRON_SHOVEL:
return 4;
case WOODEN_SHOVEL: case WOODEN_SHOVEL:
return 1; return 1;
case STONE_SHOVEL:
return 3;
case DIAMOND_SHOVEL:
return 5;
case GOLDEN_SHOVEL: case GOLDEN_SHOVEL:
return 2; return 2;
case STONE_SHOVEL:
return 3;
case IRON_SHOVEL:
return 4;
case DIAMOND_SHOVEL:
return 5;
default: default:
return false; return false;
} }
@ -329,11 +333,11 @@ class Item{
public function isHoe(){ public function isHoe(){
switch($this->id){ switch($this->id){
case IRON_HOE:
case WOODEN_HOE: case WOODEN_HOE:
case STONE_HOE:
case DIAMOND_HOE:
case GOLDEN_HOE: case GOLDEN_HOE:
case STONE_HOE:
case IRON_HOE:
case DIAMOND_HOE:
return true; return true;
default: default:
return false; return false;

View file

@ -89,6 +89,7 @@ class Level{
"id" => $entity->type, "id" => $entity->type,
"Color" => @$entity->data["Color"], "Color" => @$entity->data["Color"],
"Sheared" => @$entity->data["Sheared"], "Sheared" => @$entity->data["Sheared"],
"Saddled" => @$entity->data["Saddled"],
"IsBaby" => @$entity->data["IsBaby"], "IsBaby" => @$entity->data["IsBaby"],
"Health" => $entity->health, "Health" => $entity->health,
"Pos" => [ "Pos" => [