mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
rewrite of interact system, bugfixes, ai tweaks
This commit is contained in:
parent
f5222be9d2
commit
ac1a1b2449
62 changed files with 649 additions and 491 deletions
|
|
@ -234,27 +234,27 @@ class EntityAPI{
|
|||
break;
|
||||
|
||||
}while($i < 200);
|
||||
if($i == 200)
|
||||
$i = 0;
|
||||
$data = [
|
||||
"x" => $pos->x + mt_rand(-10, 10) / 50,
|
||||
"y" => $pos->y + 0.19 - $i + 1,
|
||||
"z" => $pos->z + mt_rand(-10, 10) / 50,
|
||||
"level" => $pos->level,
|
||||
//"speedX" => mt_rand(-3, 3) / 8,
|
||||
"speedY" => mt_rand(5, 8) / 2,
|
||||
//"speedZ" => mt_rand(-3, 3) / 8,
|
||||
"item" => $item,
|
||||
];
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
for($count = $item->count; $count > 0;){
|
||||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
$count -= $item->count;
|
||||
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
|
||||
$this->spawnToAll($e);
|
||||
$this->server->api->handle("entity.motion", $e);
|
||||
}
|
||||
$i %= 200; //if i >= 200, set to 0..1..2..199
|
||||
|
||||
$data = [
|
||||
"x" => $pos->x + mt_rand(-10, 10) / 50,
|
||||
"y" => $pos->y + 0.19 + 1 - $i,
|
||||
"z" => $pos->z + mt_rand(-10, 10) / 50,
|
||||
"level" => $pos->level,
|
||||
//"speedX" => mt_rand(-3, 3) / 8,
|
||||
//"speedY" => mt_rand(5, 8) / 2, speed is handled differently now
|
||||
//"speedZ" => mt_rand(-3, 3) / 8,
|
||||
"item" => $item,
|
||||
];
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
for($count = $item->count; $count > 0;){
|
||||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
$count -= $item->count;
|
||||
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
|
||||
$this->spawnToAll($e);
|
||||
$this->server->api->handle("entity.motion", $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function spawnAll(Player $player){
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
|
||||
class LevelAPI{
|
||||
/**
|
||||
* @var Level[]
|
||||
*/
|
||||
public $levels;
|
||||
private $server, $default;
|
||||
|
||||
|
|
|
|||
|
|
@ -491,4 +491,4 @@ class PlayerAPI{
|
|||
$data->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
161
src/Player.php
161
src/Player.php
|
|
@ -760,6 +760,9 @@ class Player{
|
|||
if($data->eid === $this->eid or $data->level !== $this->level){
|
||||
break;
|
||||
}
|
||||
if($data->speedX === 0 && $data->speedY === 0 && $data->speedZ === 0){ //causer of packet flood is eliminated.
|
||||
break;
|
||||
}
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk->eid = $data->eid;
|
||||
$pk->speedX = $data->speedX;
|
||||
|
|
@ -1784,7 +1787,6 @@ class Player{
|
|||
if($this->spawned === false){
|
||||
break;
|
||||
}
|
||||
$needsBreak = false;
|
||||
$packet->eid = $this->eid;
|
||||
$data = [];
|
||||
$data["target"] = $packet->target;
|
||||
|
|
@ -1794,149 +1796,7 @@ class Player{
|
|||
$this->toCraft = [];
|
||||
$target = $this->server->api->entity->get($packet->target);
|
||||
if($target instanceof Entity and $this->entity instanceof Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8){
|
||||
$data["targetentity"] = $target;
|
||||
$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;
|
||||
}
|
||||
$target->linkedEntity = $this->entity;
|
||||
$this->entity->isInMinecart = true;
|
||||
$pk = new SetEntityLinkPacket();
|
||||
$pk->rider = $target->eid;
|
||||
$pk->riding = $this->entity->eid;
|
||||
$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){
|
||||
$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;
|
||||
$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();
|
||||
$pk->rider = targetEntity . getId();
|
||||
$pk->riding = this . id;
|
||||
$pk->type = 3;
|
||||
$this->server->api->player->broadcastPacket([$this], $pk);
|
||||
$this->entity->isInMinecart = false;
|
||||
$target->linkedEntity = null;
|
||||
$pk = new SetEntityLinkPacket();
|
||||
$pk->rider = $target->eid;
|
||||
$pk->riding = 0;
|
||||
$pk->type = 3;
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
if($needsBreak){
|
||||
break;
|
||||
}
|
||||
if($target->class === ENTITY_PLAYER and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($target->player->gamemode & 0x01) === 0x01)){
|
||||
break;
|
||||
}elseif($this->server->handle("player.interact", $data) !== false){
|
||||
$slot = $this->getSlot($this->slot);
|
||||
switch($slot->getID()){
|
||||
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;
|
||||
}
|
||||
$target->harm($damage, $this->eid);
|
||||
if($slot->isTool() === true and ($this->gamemode & 0x01) === 0){
|
||||
if($slot->useOn($target) and $slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
$target->interactWith($this->entity, $packet->action);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -2297,7 +2157,16 @@ class Player{
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an Item which is currently held by player
|
||||
* @return Item
|
||||
*/
|
||||
|
||||
public function getHeldItem(){
|
||||
return $this->getSlot($this->slot);
|
||||
}
|
||||
|
||||
public function stopSleep(){
|
||||
$this->isSleeping = false;
|
||||
if($this->entity instanceof Entity){
|
||||
|
|
@ -2519,4 +2388,4 @@ class PlayerNull extends Player{
|
|||
public function __construct(){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
class PocketMinecraftServer{
|
||||
|
||||
public $tCnt;
|
||||
public $tCnt, $ticks;
|
||||
public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
|
||||
/**
|
||||
* @var ServerAPI
|
||||
*/
|
||||
public $api;
|
||||
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticks, $memoryStats, $async = [], $asyncID = 0;
|
||||
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0;
|
||||
|
||||
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
|
||||
$this->port = (int) $port;
|
||||
|
|
@ -452,35 +452,31 @@ class PocketMinecraftServer{
|
|||
}
|
||||
}
|
||||
|
||||
public function process(){
|
||||
$lastLoop = 0;
|
||||
while($this->stop === false){
|
||||
$packet = $this->interface->readPacket();
|
||||
if($packet instanceof Packet){
|
||||
$this->packetHandler($packet);
|
||||
$lastLoop = 0;
|
||||
}elseif($this->tick() > 0){
|
||||
$lastLoop = 0;
|
||||
}else{
|
||||
++$lastLoop;
|
||||
if($lastLoop < 16){
|
||||
usleep(1);
|
||||
}elseif($lastLoop < 128){
|
||||
usleep(100);
|
||||
}elseif($lastLoop < 256){
|
||||
usleep(512);
|
||||
}else{
|
||||
usleep(10000);
|
||||
}
|
||||
}
|
||||
$this->tick();
|
||||
if($this->ticks % 2 === 0){
|
||||
foreach($this->api->level->levels as $l){
|
||||
$l->onTick($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function process()
|
||||
{
|
||||
$lastLoop = 0;
|
||||
while($this->stop === false){
|
||||
$packet = $this->interface->readPacket();
|
||||
if($packet instanceof Packet){
|
||||
$this->packetHandler($packet);
|
||||
$lastLoop = 0;
|
||||
} elseif($this->tick() > 0){
|
||||
$lastLoop = 0;
|
||||
} else{
|
||||
++ $lastLoop;
|
||||
if($lastLoop < 16){
|
||||
usleep(1);
|
||||
} elseif($lastLoop < 128){
|
||||
usleep(100);
|
||||
} elseif($lastLoop < 256){
|
||||
usleep(512);
|
||||
} else{
|
||||
usleep(10000);
|
||||
}
|
||||
}
|
||||
$this->tick();
|
||||
}
|
||||
}
|
||||
|
||||
public function packetHandler(Packet $packet){
|
||||
$data =& $packet;
|
||||
|
|
@ -572,6 +568,9 @@ class PocketMinecraftServer{
|
|||
$this->tickMeasure[] = $this->lastTick = $time;
|
||||
unset($this->tickMeasure[key($this->tickMeasure)]);
|
||||
++$this->ticks;
|
||||
foreach($this->api->level->levels as $l){
|
||||
$l->onTick($this);
|
||||
}
|
||||
return $this->tickerFunction($time);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,12 @@ require_once(FILE_PATH . "/src/entity/Ageable.php");
|
|||
require_once(FILE_PATH . "/src/entity/Animal.php");
|
||||
|
||||
require_once(FILE_PATH . "/src/material/Item.php");
|
||||
|
||||
require_once(FILE_PATH . "/src/material/item/base/ItemTool.php");
|
||||
require_once(FILE_PATH . "/src/material/item/base/ItemHoe.php");
|
||||
require_once(FILE_PATH . "/src/material/item/base/ItemPickaxe.php");
|
||||
require_once(FILE_PATH . "/src/material/item/base/ItemAxe.php");
|
||||
require_once(FILE_PATH . "/src/material/item/base/ItemShovel.php");
|
||||
require_once(FILE_PATH . "/src/material/item/base/ItemSword.php");
|
||||
require_once(FILE_PATH . "/src/material/item/armor/ArmorItem.php");
|
||||
|
||||
require_once(FILE_PATH . "/src/structure/Structure.php");
|
||||
|
|
|
|||
|
|
@ -6,13 +6,18 @@ move methods
|
|||
abstract class Animal extends Creature implements Ageable, Breedable{
|
||||
|
||||
public $parent;
|
||||
|
||||
public $inLove; //do NOT add it into metadata, it doesnt send it to player
|
||||
public function isBaby(){
|
||||
if(!isset($this->data["IsBaby"])){
|
||||
$this->data["IsBaby"] = false;
|
||||
}
|
||||
return $this->data["IsBaby"];
|
||||
}
|
||||
|
||||
public function spawnChild(){
|
||||
//TODO
|
||||
//$c->parent = $this->eid;
|
||||
}
|
||||
public function getMetadata(){
|
||||
$d = parent::getMetadata();
|
||||
if(!isset($this->data["IsBaby"])){
|
||||
|
|
@ -21,6 +26,30 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
$d[14]["value"] = $this->isBaby();
|
||||
return $d;
|
||||
}
|
||||
|
||||
public function isInLove(){
|
||||
return $this->inLove > 0;
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($this->isFood($slot->getID())){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1);
|
||||
$this->inLove = 600; //600 ticks, original mehod from mcpe
|
||||
return true;
|
||||
}
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function counterUpdate(){
|
||||
parent::counterUpdate();
|
||||
if($this->isInLove()){
|
||||
--$this->inLove;
|
||||
}
|
||||
}
|
||||
|
||||
public function environmentUpdate(){
|
||||
if($this->server->api->getProperty("spawn-animals") !== true){
|
||||
$this->close();
|
||||
|
|
|
|||
|
|
@ -2,4 +2,8 @@
|
|||
|
||||
interface Breedable{
|
||||
public function isFood($id); //original name
|
||||
|
||||
public function spawnChild();
|
||||
|
||||
public function isInLove();
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ class Entity extends Position{
|
|||
public $canBeAttacked;
|
||||
public $moveTime, $lookTime, $idleTime;
|
||||
public $needsUpdate;
|
||||
public $speedModifer;
|
||||
/**
|
||||
* @var AxisAlignedBB
|
||||
*/
|
||||
|
|
@ -40,12 +41,13 @@ class Entity extends Position{
|
|||
public $player;
|
||||
public $fallY;
|
||||
public $fallStart;
|
||||
private $state;
|
||||
private $tickCounter;
|
||||
private $speedMeasure = array(0, 0, 0, 0, 0, 0, 0);
|
||||
public $server;
|
||||
private $isStatic;
|
||||
public $level;
|
||||
public $isInMinecart = false;
|
||||
public $isRiding = false;
|
||||
public $lastUpdate;
|
||||
public $linkedEntity = null;
|
||||
public $check = true;
|
||||
|
|
@ -54,10 +56,12 @@ class Entity extends Position{
|
|||
public $random;
|
||||
public $radius;
|
||||
public $inAction = false;
|
||||
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
$this->random = new Random();
|
||||
$this->canBeAttacked = false;
|
||||
$this->level = $level;
|
||||
$this->speedModifer = 0.7;
|
||||
$this->fallY = false;
|
||||
$this->fallStart = false;
|
||||
$this->server = ServerAPI::request();
|
||||
|
|
@ -79,6 +83,7 @@ class Entity extends Position{
|
|||
$this->closed = false;
|
||||
$this->isStatic = false;
|
||||
$this->name = "";
|
||||
$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);");
|
||||
$this->x = isset($this->data["x"]) ? (float) $this->data["x"] : 0;
|
||||
|
|
@ -99,6 +104,7 @@ class Entity extends Position{
|
|||
case ENTITY_PLAYER:
|
||||
$this->player = $this->data["player"];
|
||||
$this->setHealth($this->health, "generic");
|
||||
$this->speedModifer = 1;
|
||||
$this->width = 1.2;
|
||||
$this->height = 1.9;
|
||||
$this->canBeAttacked = true;
|
||||
|
|
@ -341,19 +347,20 @@ class Entity extends Position{
|
|||
for($y = $startY; $y <= $endY; ++$y){
|
||||
for($x = $startX; $x <= $endX; ++$x){
|
||||
for($z = $startZ; $z <= $endZ; ++$z){
|
||||
$b = $this->level->getBlock(new Vector3($x, $y, $z));
|
||||
$pos = new Vector3($x, $y, $z);
|
||||
$b = $this->level->getBlock($pos);
|
||||
switch($b->getID()){
|
||||
case WATER:
|
||||
case STILL_WATER: //Drowing
|
||||
if($this->fire > 0 and $this->inBlock(new Vector3($x, $y, $z))){
|
||||
if($this->fire > 0 and $this->inBlock($pos)){
|
||||
$this->fire = 0;
|
||||
$this->updateMetadata();
|
||||
}
|
||||
if($this->air <= 0){
|
||||
$this->harm(2, "water");
|
||||
$hasUpdate = true;
|
||||
}elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER) and $waterDone === false){
|
||||
$this->air -= 10;
|
||||
}elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER) and !$waterDone){
|
||||
$this->air -= 1;
|
||||
$waterDone = true;
|
||||
$this->updateMetadata();
|
||||
$hasUpdate = true;
|
||||
|
|
@ -361,7 +368,7 @@ class Entity extends Position{
|
|||
break;
|
||||
case LAVA: //Lava damage
|
||||
case STILL_LAVA:
|
||||
if($this->inBlock(new Vector3($x, $y, $z))){
|
||||
if($this->inBlock($pos)){
|
||||
$this->harm(5, "lava");
|
||||
$this->fire = 300;
|
||||
$this->updateMetadata();
|
||||
|
|
@ -369,7 +376,7 @@ class Entity extends Position{
|
|||
}
|
||||
break;
|
||||
case FIRE: //Fire block damage
|
||||
if($this->inBlock(new Vector3($x, $y, $z))){
|
||||
if($this->inBlock($pos)){
|
||||
$this->harm(1, "fire");
|
||||
$this->fire = 300;
|
||||
$this->updateMetadata();
|
||||
|
|
@ -377,13 +384,13 @@ class Entity extends Position{
|
|||
}
|
||||
break;
|
||||
case CACTUS: //Cactus damage
|
||||
if($this->touchingBlock(new Vector3($x, $y, $z))){
|
||||
if($this->touchingBlock($pos)){
|
||||
$this->harm(1, "cactus");
|
||||
$hasUpdate = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($this->inBlock(new Vector3($x, $y, $z), 0.7) and $y == $endY and $b->isTransparent === false and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)){
|
||||
if($this->inBlock($pos, 0.7) and $y == $endY and $b->isTransparent === false and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)){
|
||||
$this->harm(1, "suffocation"); //Suffocation
|
||||
$hasUpdate = true;
|
||||
}elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)){
|
||||
|
|
@ -397,13 +404,6 @@ class Entity extends Position{
|
|||
return $hasUpdate;
|
||||
}
|
||||
|
||||
protected function checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz){
|
||||
//$this->isCollidedVertically = $movY != $dy;
|
||||
//$this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz);
|
||||
//$this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically);
|
||||
$this->onGround = ($movY != $dy and $movY < 0);
|
||||
}
|
||||
|
||||
public function update(){
|
||||
if($this->closed === true){
|
||||
return false;
|
||||
|
|
@ -525,32 +525,22 @@ class Entity extends Position{
|
|||
$this->y = $ny;
|
||||
$this->speedY -= $this->speedY * $drag;
|
||||
$update = true;
|
||||
}
|
||||
if($this->moveTime > 0){
|
||||
--$this->moveTime;
|
||||
}
|
||||
if($this->lookTime > 0){
|
||||
--$this->lookTime;
|
||||
}
|
||||
if($this->idleTime > 0){
|
||||
--$this->idleTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($support === false){
|
||||
$this->speedY -= $this->class === ENTITY_FALLING ? 0.04 : 0.08; //TODO: replace with $gravity
|
||||
$this->speedY -= $this->class === ENTITY_FALLING ? 0.04 : 0.08; //TODO: replace with $gravity
|
||||
$update = true;
|
||||
}else{
|
||||
//$this->speedX = 0;
|
||||
//$this->speedY = 0;
|
||||
//$this->speedZ = 0;
|
||||
$this->server->api->handle("entity.move", $this);
|
||||
if(($this->class === ENTITY_OBJECT and $this->type !== OBJECT_PRIMEDTNT) or $this->speedY <= 0.1){
|
||||
$update = false;
|
||||
if(($this->class === ENTITY_OBJECT and $this->type !== OBJECT_PRIMEDTNT) or $this->speedY <= 0.1){
|
||||
$this->server->api->handle("entity.motion", $this);
|
||||
}
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if($update === true){
|
||||
|
|
@ -564,7 +554,7 @@ class Entity extends Position{
|
|||
$this->fallY = $y;
|
||||
$this->fallStart = microtime(true);
|
||||
}elseif($this->class === ENTITY_PLAYER and ($this->fallStart + 5) < microtime(true)){
|
||||
if($this->server->api->getProperty("allow-flight") !== true and $this->server->handle("player.flying", $this->player) !== true and $this->isInMinecart === false){
|
||||
if($this->server->api->getProperty("allow-flight") !== true and $this->server->handle("player.flying", $this->player) !== true and $this->isRiding === false){
|
||||
$this->player->close("flying");
|
||||
return;
|
||||
}
|
||||
|
|
@ -595,9 +585,17 @@ class Entity extends Position{
|
|||
}
|
||||
}
|
||||
}
|
||||
if($this->moveTime > 0){
|
||||
--$this->moveTime;
|
||||
}
|
||||
if($this->lookTime > 0){
|
||||
--$this->lookTime;
|
||||
}
|
||||
if($this->idleTime > 0){
|
||||
--$this->idleTime;
|
||||
}
|
||||
|
||||
|
||||
if($this->class !== ENTITY_PLAYER){
|
||||
if($this->class !== ENTITY_PLAYER && $update){
|
||||
$this->updateMovement();
|
||||
}
|
||||
$this->needsUpdate = $hasUpdate;
|
||||
|
|
@ -649,7 +647,27 @@ class Entity extends Position{
|
|||
|
||||
$this->lastUpdate = $now;
|
||||
}
|
||||
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($this->class === ENTITY_PLAYER and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($e->player->gamemode & 0x01) === 0x01)){
|
||||
return false;
|
||||
}
|
||||
$data["targetentity"] = $this;
|
||||
$data["entity"] = $e;
|
||||
if($this->server->handle("player.interact", $data) !== false && $action === InteractPacket::ACTION_ATTACK && $e->isPlayer()){
|
||||
$slot = $e->player->getHeldItem();
|
||||
$damage = $slot->getDamageAgainstOf($e);
|
||||
$this->harm($damage, $e->eid);
|
||||
if($slot->isTool() === true and ($e->player->gamemode & 0x01) === 0){
|
||||
if($slot->useOn($e) and $slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDirection(){
|
||||
$rotation = ($this->yaw - 90) % 360;
|
||||
if($rotation < 0) {
|
||||
|
|
@ -682,7 +700,7 @@ class Entity extends 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)
|
||||
16 => ["type" => 0, "value" => 0] --> Fuse(TNT), Saddled(Pig), Creeper(29 ticks before explosion)
|
||||
17 => ["type" => 6, "value" => [0, 0, 0]] --> Bed Position <?>
|
||||
|
||||
|
||||
|
|
@ -704,11 +722,8 @@ class Entity extends Position{
|
|||
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;
|
||||
//}
|
||||
}elseif($this->class === ENTITY_PLAYER){
|
||||
$d[16]["value"] = $this->data["State"];
|
||||
if($this->class === ENTITY_PLAYER){
|
||||
if($this->player->isSleeping !== false){
|
||||
$d[16]["value"] = 2;
|
||||
$d[17]["value"] = [$this->player->isSleeping->x, $this->player->isSleeping->y, $this->player->isSleeping->z];
|
||||
|
|
@ -856,7 +871,7 @@ class Entity extends Position{
|
|||
public function updatePosition(){
|
||||
$this->server->query("UPDATE entities SET level = '".$this->level->getName()."', x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
||||
$this->sendMoveUpdate();
|
||||
$this->sendMotion();
|
||||
//$this->sendMotion();
|
||||
$this->updateAABB();
|
||||
}
|
||||
|
||||
|
|
@ -960,7 +975,17 @@ class Entity extends Position{
|
|||
public function harm($dmg, $cause = "generic", $force = false){
|
||||
return $this->setHealth(max(-128, $this->getHealth() - ((int) $dmg)), $cause, $force);
|
||||
}
|
||||
|
||||
|
||||
public function setState($v){
|
||||
$this->state = $v;
|
||||
$this->data["State"] = $v;
|
||||
$this->updateMetadata();
|
||||
}
|
||||
|
||||
public function getState(){
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
public function heal($health, $cause = "generic"){
|
||||
return $this->setHealth(min(20, $this->getHealth() + ((int) $health)), $cause);
|
||||
}
|
||||
|
|
@ -974,6 +999,21 @@ class Entity extends Position{
|
|||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
}
|
||||
|
||||
public function linkEntity(Entity $e, $type){
|
||||
if($e->isPlayer()){
|
||||
$pk = new SetEntityLinkPacket();
|
||||
$pk->rider = $this->eid;
|
||||
$pk->riding = $type === SetEntityLinkPacket::TYPE_REMOVE ? 0 : $e->eid;
|
||||
$pk->type = $type;
|
||||
$e->player->dataPacket($pk);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function isPlayer(){
|
||||
return $this->player instanceof Player;
|
||||
}
|
||||
|
||||
public function sendMoveUpdate(){
|
||||
if($this->class === ENTITY_PLAYER){
|
||||
$this->player->teleport(new Vector3($this->x, $this->y, $this->z));
|
||||
|
|
@ -989,6 +1029,17 @@ class Entity extends Position{
|
|||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
}
|
||||
|
||||
public function moveEntityWithOffset($oX, $oY, $oZ){
|
||||
$oX = $oX === 0 ? $this->speedX : $this->getSpeedModifer() * $oX * $this->getSpeed();
|
||||
$oY = $oY === 0 ? $this->speedY : $this->getSpeedModifer() * $oY * $this->getSpeed();
|
||||
$oZ = $oZ === 0 ? $this->speedZ : $this->getSpeedModifer() * $oZ * $this->getSpeed();
|
||||
$this->setVelocity($oX, $oY, $oZ);
|
||||
}
|
||||
|
||||
public function getSpeedModifer(){
|
||||
return $this->speedModifer;
|
||||
}
|
||||
|
||||
public function setHealth($health, $cause = "generic", $force = false){
|
||||
if(!$this->canBeAttacked){
|
||||
return false;
|
||||
|
|
@ -1109,7 +1160,11 @@ class Entity extends Position{
|
|||
$this->height = $h;
|
||||
$this->radius = $w / 2;
|
||||
}
|
||||
|
||||
|
||||
public function setSpeed($s){
|
||||
$this->speed = $s;
|
||||
}
|
||||
|
||||
public function knockBack($d, $d1)
|
||||
{
|
||||
$f = sqrt($d * $d + $d1 * $d1);
|
||||
|
|
|
|||
7
src/entity/Pathfindable.php
Normal file
7
src/entity/Pathfindable.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
/*
|
||||
Illegal features
|
||||
*/
|
||||
interface Pathfindable{
|
||||
function getPathFinder();
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
|
||||
interface Rideable{
|
||||
|
||||
public function canRide($e);
|
||||
}
|
||||
13
src/entity/WalkingEntity.php
Normal file
13
src/entity/WalkingEntity.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
abstract class WalkingEntity extends Entity{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param int $tickDiff
|
||||
*
|
||||
* @return null|Vector3
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -5,12 +5,12 @@ class TaskLookAround extends TaskBase
|
|||
private $finYaw = 0;
|
||||
public function shouldBeExecuted(EntityAI $ai)
|
||||
{
|
||||
return !$ai->entity->isMoving() && $ai->entity->lookTime <= 0 && mt_rand(0,30) == 1 && $ai->entity->idleTime <= 0 && !($ai->lastTask instanceof TaskLookAround);
|
||||
return !$ai->entity->isMoving() && $ai->entity->lookTime <= 0 && mt_rand(0,30) == 1 && $ai->entity->idleTime <= 0;
|
||||
}
|
||||
|
||||
public function wasExecuted(EntityAI $ai){
|
||||
|
||||
return $ai->entity->lookTime > 0;
|
||||
return $ai->entity->lookTime > 0 && $ai->entity->moveTime <= 0;
|
||||
}
|
||||
|
||||
public function onStart(EntityAI $ai){
|
||||
|
|
@ -24,12 +24,12 @@ class TaskLookAround extends TaskBase
|
|||
//60 - 30 = 90deg rot
|
||||
//30 - 15 = -45deg rot
|
||||
if($ai->entity->lookTime === 1){
|
||||
$ai->entity->idleTime = mt_rand(40, 200);
|
||||
$ai->entity->idleTime = mt_rand(10, 40);
|
||||
}
|
||||
if(Utils::in_range($ai->entity->lookTime, 105, 120) || Utils::in_range($ai->entity->lookTime, 15, 30)){
|
||||
if(Utils::in_range($ai->entity->lookTime, 45, 60) || Utils::in_range($ai->entity->lookTime, 0, 15)){
|
||||
$ai->entity->yaw -= 3;
|
||||
}
|
||||
if(Utils::in_range($ai->entity->lookTime, 50, 80)){
|
||||
if(Utils::in_range($ai->entity->lookTime, 15, 45)){
|
||||
$ai->entity->yaw += 3;
|
||||
}
|
||||
|
||||
|
|
@ -44,4 +44,3 @@ class TaskLookAround extends TaskBase
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,19 +5,22 @@ class TaskRandomWalk extends TaskBase
|
|||
private $x, $z, $delay = 10, $newPos, $looking = false;
|
||||
public function shouldBeExecuted(EntityAI $ai)
|
||||
{
|
||||
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()){
|
||||
return false;
|
||||
}
|
||||
return !$ai->entity->pathFound && $ai->entity->moveTime <= 0 && $ai->entity->lookTime <= 0 && $ai->entity->idleTime <= 0 && !($ai->entity->target instanceof Entity) && mt_rand(0,3) == 1;
|
||||
}
|
||||
|
||||
public function wasExecuted(EntityAI $ai)
|
||||
{
|
||||
return $ai->entity->moveTime > 0;
|
||||
return $ai->entity->moveTime > 0 && ($this->x != 0 || $this->z != 0);
|
||||
}
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->x = mt_rand(-7, 7);
|
||||
$this->z = mt_rand(-7, 7);
|
||||
$this->newPos = $ai->entity->add($this->x, 0, $this->z);
|
||||
$ai->entity->moveTime = 15 * Utils::distance($ai->entity, $this->newPos);
|
||||
$ai->entity->moveTime = floor(5 * Utils::distance($ai->entity, $this->newPos));
|
||||
}
|
||||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
|
|
@ -36,12 +39,12 @@ class TaskRandomWalk extends TaskBase
|
|||
}
|
||||
}
|
||||
if($ai->entity->moveTime <= 1){
|
||||
$ai->entity->idleTime = mt_rand(10,100);
|
||||
$ai->entity->idleTime = mt_rand(10,40);
|
||||
$this->x = 0;
|
||||
$this->z = 0;
|
||||
$this->looking = false;
|
||||
}
|
||||
if(!$ai->entity->isMoving()){
|
||||
$ai->entity->addVelocity(($this->x > 0 ? 0.1 : ($this->x < 0 ? -0.1 : 0)), 0, ($this->z > 0 ? 0.1 : ($this->z < 0 ? -0.1 : 0)));
|
||||
}
|
||||
$ai->entity->moveEntityWithOffset(($this->x > 0 ? 1 : ($this->x < 0 ? -1 : 0)), 0, ($this->z > 0 ? 1 : ($this->z < 0 ? -1 : 0)));
|
||||
}
|
||||
public function updateLook($ai){
|
||||
$ai->entity->server->query("UPDATE entities SET pitch = ".$ai->entity->pitch.", yaw = ".$ai->entity->yaw." WHERE EID = ".$ai->entity->eid.";");
|
||||
|
|
@ -50,9 +53,8 @@ class TaskRandomWalk extends TaskBase
|
|||
$x = $this->newPos->x - $ai->entity->x;
|
||||
$y = $this->newPos->y - $ai->entity->y;
|
||||
$z = $this->newPos->z - $ai->entity->z;
|
||||
$ai->entity->yaw = -atan2($vX, $vZ) * 180 / M_PI;
|
||||
$ai->entity->yaw = -atan2($x, $z) * 180 / M_PI;
|
||||
$ai->entity->pitch = $y == 0 ? 0 : rad2deg(-atan2($y, sqrt(pow($x, 2) + pow($z, 2))));
|
||||
$ai->entity->server->query("UPDATE entities SET pitch = ".$ai->entity->pitch.", yaw = ".$ai->entity->yaw." WHERE EID = ".$ai->entity->eid.";");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ class Chicken extends Animal{
|
|||
$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);
|
||||
$this->setSpeed(0.25);
|
||||
$this->update();
|
||||
}
|
||||
public function isFood($id){
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class Cow extends Animal{
|
|||
$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->setSpeed(0.2);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
|
|
@ -14,6 +15,18 @@ class Cow extends Animal{
|
|||
return $id === WHEAT;
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === BUCKET && $slot->getMetadata() === 0){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); //remove only 1 bucket
|
||||
$e->player->addItem(BUCKET, 1, 1, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? parent::getDrops() : [
|
||||
[LEATHER, 0, mt_rand(0,2)],
|
||||
|
|
|
|||
|
|
@ -1,30 +1,68 @@
|
|||
<?php
|
||||
class Pig extends Animal implements Rideable{
|
||||
const TYPE = MOB_PIG;
|
||||
|
||||
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->setSpeed(0.25);
|
||||
$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;
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSaddled(){
|
||||
return (boolean) $this->getState();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $value
|
||||
*/
|
||||
public function setSaddled($value = null){
|
||||
$this->setState($value === null ? !$this->getState() : $value);
|
||||
}
|
||||
|
||||
public function canRide($e){
|
||||
return $this->isSaddled() && !($this->linkedEntity instanceof Entity);
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action)
|
||||
{
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($this->canRide($e)){
|
||||
$this->linkedEntity = $e;
|
||||
$e->isRiding = true;
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE);
|
||||
return true;
|
||||
}
|
||||
if($e->isRiding && $this->linkedEntity->eid = $e->eid){
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE);
|
||||
$e->isRiding = false;
|
||||
$this->linkedEntity = 0;
|
||||
return true;
|
||||
}
|
||||
if($slot->getID() === SADDLE){
|
||||
if(!$this->isSaddled()){
|
||||
$e->player->removeItem($slot->getID(), 0, 1);
|
||||
$this->setSaddled(1);
|
||||
}
|
||||
return true; //avoid further interactions
|
||||
}
|
||||
|
||||
}
|
||||
return parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function isFood($id){
|
||||
return $id === POTATO || $id === CARROT || $id === BEETROOT;
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? parent::getDrops() : ($this->data["Saddled"] ? [
|
||||
return $this->isBaby() ? parent::getDrops() : ($this->isSaddled() ? [
|
||||
[($this->fire > 0 ? COOKED_PORKCHOP : RAW_PORKCHOP), 0, mt_rand(0,2)],
|
||||
[SADDLE, 0, 1]
|
||||
] : [
|
||||
|
|
|
|||
|
|
@ -1,18 +1,34 @@
|
|||
<?php
|
||||
|
||||
class Sheep extends Animal{
|
||||
public $color;
|
||||
const TYPE = MOB_SHEEP;
|
||||
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->data["Color"] = isset($this->data["Color"]) ? $this->data["Color"] : $this->sheepColor();
|
||||
$this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.675 : 1.3);
|
||||
$this->setSpeed(0.25);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function setSheared($v = null){
|
||||
$this->data["Sheared"] = $v === null ? !$this->isSheared() : $v;
|
||||
$this->updateMetadata();
|
||||
}
|
||||
|
||||
public function isSheared(){
|
||||
return $this->data["Sheared"];
|
||||
}
|
||||
|
||||
public function getColor(){
|
||||
return $this->data["Color"] & 16; //color === 16 -> color = 0, color === 17 -> color = 1 ...
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? parent::getDrops() : [
|
||||
[WOOL, $this->data["Color"] & 0x0F, 1],
|
||||
[WOOL, $this->getColor() & 0x0F, 1],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -20,40 +36,49 @@ class Sheep extends Animal{
|
|||
return $id === WHEAT;
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === SHEARS){
|
||||
if(!$this->isSheared()){
|
||||
$this->setSheared(1);
|
||||
$this->server->api->entity->drop($this, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3)));
|
||||
if($slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function getMetadata(){
|
||||
$d = parent::getMetadata();
|
||||
if(!isset($this->data["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"] << 4) | ($this->data["Color"] & 0x0F); //dark manipulations are happening here...
|
||||
$d[16]["value"] = ($this->data["Sheared"] << 4) | ($this->getColor() & 0x0F);
|
||||
return $d;
|
||||
}
|
||||
|
||||
public function sheepColor(){
|
||||
$pink = 0.1558;
|
||||
$brown = 2.85;
|
||||
$lightgrayBlackGray = 14.25;
|
||||
$chance = Utils::randomFloat() * 100;
|
||||
switch($chance){
|
||||
case($chance <= $pink):
|
||||
$color = 6;
|
||||
break;
|
||||
case($chance > $pink and $chance <= ($brown+$pink)):
|
||||
$color = 12;
|
||||
break;
|
||||
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;
|
||||
break;
|
||||
default:
|
||||
$color = 0;
|
||||
break;
|
||||
public function sheepColor(){ //a method from 0.8.1
|
||||
$c = mt_rand(0,100);
|
||||
if($c <= 4){
|
||||
return 0xF; //white
|
||||
}
|
||||
return $color;
|
||||
if($c <= 9){
|
||||
return 0x7;
|
||||
}
|
||||
if($c <= 14){
|
||||
return 0x8;
|
||||
}
|
||||
if($c <= 17){
|
||||
return 0xC;
|
||||
}
|
||||
if(mt_rand(0, 500)){
|
||||
return 0x0;
|
||||
}
|
||||
return 0x0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +1,73 @@
|
|||
<?php
|
||||
class Creeper extends Monster{
|
||||
const TYPE = MOB_CREEPER;
|
||||
const EXPL_TIME = 30;
|
||||
public $timeUntilExplode;
|
||||
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->ignited = 0;
|
||||
$this->setSize(0.6, 1.7);
|
||||
$this->setSpeed(0.25);
|
||||
$this->update();
|
||||
if($this->data["Saddled"] === 1){
|
||||
$this->server->schedule(30, [$this, "updateFuse"], []); //unknown ticks
|
||||
}
|
||||
$this->timeUntilExplode = $this->isIgnited() ? self::EXPL_TIME : 0;
|
||||
}
|
||||
|
||||
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 setIgnited($v = null){
|
||||
$this->setState($v === null ? !$this->getState() : $v);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isIgnited(){
|
||||
return (boolean)$this->getState();
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === FLINT_AND_STEEL && !$this->isIgnited()){
|
||||
if($slot->useOn($e) and $slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}
|
||||
$this->ignite();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function ignite(){
|
||||
$this->setIgnited(1);
|
||||
$this->timeUntilExplode = self::EXPL_TIME;
|
||||
}
|
||||
|
||||
public function update(){
|
||||
if($this->timeUntilExplode === 1){
|
||||
$this->explode();
|
||||
}
|
||||
if($this->timeUntilExplode >= 0){
|
||||
--$this->timeUntilExplode;
|
||||
}
|
||||
parent::update();
|
||||
}
|
||||
|
||||
public function explode()
|
||||
{
|
||||
if($this->closed){
|
||||
return false;
|
||||
}
|
||||
$this->setIgnited(0);
|
||||
$explosion = new Explosion($this, 3);
|
||||
$explosion->explode();
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return $this->data["Saddled"] === 1 ? parent::getDrops() : [
|
||||
return [
|
||||
[GUNPOWDER, 0, mt_rand(0,2)]
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ class PigZombie extends Monster{
|
|||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic");
|
||||
$this->setSize(0.3, 1.95);
|
||||
$this->setName("Pigman");
|
||||
$this->setSpeed(0.25);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ class Skeleton extends Monster{
|
|||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
|
||||
$this->setName("Skeleton");
|
||||
$this->setSize(0.6, 1.99);
|
||||
$this->setSpeed(0.25);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ class Spider extends Monster{
|
|||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
|
||||
$this->setName("Spider");
|
||||
$this->setSize(1.4, 0.9);
|
||||
$this->setSpeed(0.3);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ class Zombie extends Monster{
|
|||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic");
|
||||
$this->setName("Zombie");
|
||||
$this->setSize(0.6, 1.85);
|
||||
$this->setSpeed(0.23);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class Minecart extends Vehicle{
|
|||
$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->setHealth(3, "generic");
|
||||
//$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
||||
$this->width = 1;
|
||||
/*$this->moveVector[Entity::NORTH] = new Vector3(-1, 0, 0);
|
||||
|
|
@ -46,4 +46,25 @@ class Minecart extends Vehicle{
|
|||
$pk->speedZ = $this->speedZ;
|
||||
$player->dataPacket($pk);
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($action === InteractPacket::ACTION_HOLD && $e->isPlayer() && $this->canRide($e)){
|
||||
$this->linkedEntity = $e;
|
||||
$e->isRiding = true;
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE);
|
||||
return true;
|
||||
}
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE);
|
||||
$this->linkedEntity = 0;
|
||||
$e->isRiding = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function canRide($e)
|
||||
{
|
||||
return !($this->linkedEntity instanceof Entity) && !$e->isRiding;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ class Item{
|
|||
const TOOL_SHOVEL = 3;
|
||||
const TOOL_HOE = 4;
|
||||
|
||||
const DEF_DAMAGE = 1;
|
||||
|
||||
public static $class = array(
|
||||
|
||||
//armor
|
||||
|
|
@ -150,6 +152,10 @@ class Item{
|
|||
}
|
||||
}
|
||||
|
||||
public function isPickaxe(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
|
@ -210,21 +216,13 @@ class Item{
|
|||
}
|
||||
|
||||
public function useOn($object, $force = false){
|
||||
if($this->isTool() or $force === true){
|
||||
if(($object instanceof Entity) and !$this->isSword()){
|
||||
$this->meta += 2;
|
||||
}else{
|
||||
$this->meta++;
|
||||
}
|
||||
if($force){
|
||||
if(($object instanceof Entity) and !$this->isSword()){
|
||||
$this->meta += 2;
|
||||
}else{
|
||||
$this->meta++;
|
||||
}
|
||||
return true;
|
||||
}elseif($this->isHoe()){
|
||||
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;
|
||||
}
|
||||
|
|
@ -281,67 +279,19 @@ class Item{
|
|||
}
|
||||
|
||||
public function isAxe(){
|
||||
switch($this->id){
|
||||
case WOODEN_AXE:
|
||||
return 1;
|
||||
case GOLDEN_AXE:
|
||||
return 2;
|
||||
case STONE_AXE:
|
||||
return 3;
|
||||
case IRON_AXE:
|
||||
return 4;
|
||||
case DIAMOND_AXE:
|
||||
return 5;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isSword(){
|
||||
switch($this->id){
|
||||
case WOODEN_SWORD:
|
||||
return 1;
|
||||
case GOLDEN_SWORD:
|
||||
return 2;
|
||||
case STONE_SWORD:
|
||||
return 3;
|
||||
case IRON_SWORD:
|
||||
return 4;
|
||||
case DIAMOND_SWORD:
|
||||
return 5;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isShovel(){
|
||||
switch($this->id){
|
||||
case WOODEN_SHOVEL:
|
||||
return 1;
|
||||
case GOLDEN_SHOVEL:
|
||||
return 2;
|
||||
case STONE_SHOVEL:
|
||||
return 3;
|
||||
case IRON_SHOVEL:
|
||||
return 4;
|
||||
case DIAMOND_SHOVEL:
|
||||
return 5;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isHoe(){
|
||||
switch($this->id){
|
||||
case WOODEN_HOE:
|
||||
case GOLDEN_HOE:
|
||||
case STONE_HOE:
|
||||
case IRON_HOE:
|
||||
case DIAMOND_HOE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isShears(){
|
||||
|
|
@ -352,6 +302,10 @@ class Item{
|
|||
return "Item ". $this->name ." (".$this->id.":".$this->meta.")";
|
||||
}
|
||||
|
||||
public function getDamageAgainstOf($e){
|
||||
return Item::DEF_DAMAGE;
|
||||
}
|
||||
|
||||
public function getDestroySpeed(Block $block, Player $player){
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
11
src/material/item/base/ItemAxe.php
Normal file
11
src/material/item/base/ItemAxe.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
abstract class ItemAxe extends ItemTool
|
||||
{
|
||||
public function isAxe(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
18
src/material/item/base/ItemHoe.php
Normal file
18
src/material/item/base/ItemHoe.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
abstract class ItemHoe extends ItemTool
|
||||
{
|
||||
public function isHoe(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){
|
||||
$this->meta++;
|
||||
return true;
|
||||
}else{
|
||||
return parent::useOn($object, $force);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
src/material/item/base/ItemPickaxe.php
Normal file
13
src/material/item/base/ItemPickaxe.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
abstract class ItemPickaxe extends ItemTool
|
||||
{
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isPickaxe(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
9
src/material/item/base/ItemShovel.php
Normal file
9
src/material/item/base/ItemShovel.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
class ItemShovel extends ItemTool
|
||||
{
|
||||
public function isShovel(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
10
src/material/item/base/ItemSword.php
Normal file
10
src/material/item/base/ItemSword.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
abstract class ItemSword extends ItemTool
|
||||
{
|
||||
|
||||
public function isSword(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
17
src/material/item/base/ItemTool.php
Normal file
17
src/material/item/base/ItemTool.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
abstract class ItemTool extends Item
|
||||
{
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Entity) and !$this->isSword()){
|
||||
$this->meta += 2;
|
||||
}else{
|
||||
$this->meta++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
class DiamondAxeItem extends Item{
|
||||
class DiamondAxeItem extends ItemAxe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(DIAMOND_AXE, $meta, $count, "Diamond Axe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
|
||||
class DiamondHoeItem extends Item{
|
||||
class DiamondHoeItem extends ItemHoe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(DIAMOND_HOE, $meta, $count, "Diamond Hoe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
class DiamondPickaxeItem extends Item{
|
||||
class DiamondPickaxeItem extends ItemPickaxe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(DIAMOND_PICKAXE, $meta, $count, "Diamond Pickaxe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
<?php
|
||||
|
||||
class DiamondShovelItem extends Item{
|
||||
class DiamondShovelItem extends ItemShovel{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(DIAMOND_SHOVEL, $meta, $count, "Diamond Shovel");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
<?php
|
||||
|
||||
class DiamondSwordItem extends Item{
|
||||
class DiamondSwordItem extends ItemSword{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(DIAMOND_SWORD, $meta, $count, "Diamond Sword");
|
||||
}
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
public function getDamageAgainstOf($e)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class FlintSteelItem extends Item{
|
||||
class FlintSteelItem extends ItemTool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(FLINT_STEEL, $meta, $count, "Flint and Steel");
|
||||
$this->isActivable = true;
|
||||
|
|
@ -20,7 +20,12 @@ class FlintSteelItem extends Item{
|
|||
return false;
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Creeper) and $this->id === FLINT_STEEL){
|
||||
$this->meta++;
|
||||
return true;
|
||||
}else{
|
||||
return parent::useOn($object, $force);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
<?php
|
||||
|
||||
class GoldenAxeItem extends Item{
|
||||
class GoldenAxeItem extends ItemAxe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(GOLDEN_AXE, $meta, $count, "Golden Axe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
|
||||
class GoldenHoeItem extends Item{
|
||||
class GoldenHoeItem extends ItemHoe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(GOLDEN_HOE, $meta, $count, "Golden Hoe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
class GoldenPickaxeItem extends Item{
|
||||
class GoldenPickaxeItem extends ItemPickaxe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(GOLDEN_PICKAXE, $meta, $count, "Golden Pickaxe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
|
||||
class GoldenShovelItem extends Item{
|
||||
class GoldenShovelItem extends ItemShovel{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(GOLDEN_SHOVEL, $meta, $count, "Golden Shovel");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
<?php
|
||||
|
||||
class GoldenSwordItem extends Item{
|
||||
class GoldenSwordItem extends ItemSword{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(GOLDEN_SWORD, $meta, $count, "Golden Sword");
|
||||
}
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
public function getDamageAgainstOf($e)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
class IronAxeItem extends Item{
|
||||
class IronAxeItem extends ItemAxe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(IRON_AXE, $meta, $count, "Iron Axe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
|
||||
class IronHoeItem extends Item{
|
||||
class IronHoeItem extends ItemHoe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(IRON_HOE, $meta, $count, "Iron Hoe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
class IronPickaxeItem extends Item{
|
||||
class IronPickaxeItem extends ItemPickaxe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(IRON_PICKAXE, $meta, $count, "Iron Pickaxe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
class IronShovelItem extends Item{
|
||||
class IronShovelItem extends ItemShovel{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(IRON_SHOVEL, $meta, $count, "Iron Shovel");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
class IronSwordItem extends Item{
|
||||
class IronSwordItem extends ItemSword{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(IRON_SWORD, $meta, $count, "Iron Sword");
|
||||
}
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,15 @@
|
|||
<?php
|
||||
|
||||
class ShearsItem extends Item{
|
||||
class ShearsItem extends ItemTool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(SHEARS, $meta, $count, "Shears");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Sheep) and $this->id === SHEARS){
|
||||
$this->meta++;
|
||||
return true;
|
||||
}
|
||||
parent::useOn($object, $force);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
class StoneAxeItem extends Item{
|
||||
class StoneAxeItem extends ItemAxe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(STONE_AXE, $meta, $count, "Stone Axe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
|
||||
class StoneHoeItem extends Item{
|
||||
class StoneHoeItem extends ItemHoe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(STONE_HOE, $meta, $count, "Stone Hoe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
class StonePickaxeItem extends Item{
|
||||
class StonePickaxeItem extends ItemPickaxe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(STONE_PICKAXE, $meta, $count, "Stone Pickaxe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
<?php
|
||||
|
||||
class StoneShovelItem extends Item{
|
||||
class StoneShovelItem extends ItemShovel{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(STONE_SHOVEL, $meta, $count, "Stone Shovel");
|
||||
}
|
||||
|
||||
|
||||
public function getDamageAgainstOf($e){
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
class StoneSwordItem extends Item{
|
||||
class StoneSwordItem extends ItemSword{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(STONE_SWORD, $meta, $count, "Stone Sword");
|
||||
}
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
class WoodenAxeItem extends Item{
|
||||
class WoodenAxeItem extends ItemAxe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(WOODEN_AXE, $meta, $count, "Wooden Axe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
|
||||
class WoodenHoeItem extends Item{
|
||||
class WoodenHoeItem extends ItemHoe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(WOODEN_HOE, $meta, $count, "Wooden Hoe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
class WoodenPickaxeItem extends Item{
|
||||
class WoodenPickaxeItem extends ItemPickaxe{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(WOODEN_PICKAXE, $meta, $count, "Wooden Pickaxe");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
|
||||
class WoodenShovelItem extends Item{
|
||||
class WoodenShovelItem extends ItemShovel{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(WOODEN_SHOVEL, $meta, $count, "Wooden Shovel");
|
||||
}
|
||||
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
class WoodenSwordItem extends Item{
|
||||
class WoodenSwordItem extends ItemSword{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(WOODEN_SWORD, $meta, $count, "Wooden Sword");
|
||||
}
|
||||
public function isTool(){
|
||||
return true;
|
||||
public function getDamageAgainstOf($e){
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
20
src/math/Vector3Pos.php
Normal file
20
src/math/Vector3Pos.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
class Vector3Pos extends Vector3
|
||||
{
|
||||
public $x, $y, $z;
|
||||
|
||||
public function __construct(&$x, &$y, &$z){
|
||||
$this->x = &$x;
|
||||
$this->y = &$y;
|
||||
$this->z = &$z;
|
||||
}
|
||||
|
||||
public function addToValues($v){
|
||||
$this->x += $v->x;
|
||||
$this->y += $v->y;
|
||||
$this->z += $v->z;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -523,7 +523,7 @@ class Utils{
|
|||
$lastRandom = hash("sha512", $lastRandom, true);
|
||||
return $raw === false ? bin2hex($output) : $output;
|
||||
}
|
||||
|
||||
|
||||
public static function chance($i){//GameHerobrine's code
|
||||
return self::randomFloat() <= $i / 100;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,9 +100,8 @@ class Explosion{
|
|||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1], $drop[2])); //id, meta, count
|
||||
}
|
||||
}
|
||||
$this->level->level->setBlockID($block->x, $block->y, $block->z, 0);
|
||||
ServerAPI::request()->api->block->blockUpdateAround(new Position($block->x, $block->y, $block->z, $this->level), BLOCK_UPDATE_NORMAL, 5);
|
||||
$send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
|
||||
$this->level->setBlock($block, new AirBlock(), true, false, true);
|
||||
$send[] = $block->subtract($source);
|
||||
}
|
||||
$pk = new ExplodePacket;
|
||||
$pk->x = $this->source->x;
|
||||
|
|
@ -112,4 +111,4 @@ class Explosion{
|
|||
$pk->records = $send;
|
||||
$server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ class Level{
|
|||
$x0 = floor($aABB->minX);
|
||||
$x1 = ceil($aABB->maxX);
|
||||
$y0 = floor($aABB->minY);
|
||||
$y1 = ceil($aABB->maxY);
|
||||
$y1 = round($aABB->maxY);
|
||||
$z0 = floor($aABB->minZ);
|
||||
$z1 = ceil($aABB->maxZ);
|
||||
$x0 = $x0 < 0 ? 0 : $x0;
|
||||
|
|
@ -51,11 +51,11 @@ class Level{
|
|||
$y1 = $y1 > 128 ? 128 : $y1;
|
||||
$z1 = $z1 > 256 ? 256 : $z1;
|
||||
|
||||
for($x = $x0; $x < $x1; ++$x) {
|
||||
for($x = $x0; $x <= $x1; ++$x) {
|
||||
for($y = $y0; $y < $y1; ++$y) {
|
||||
for($z = $z0; $z < $z1; ++$z) {
|
||||
for($z = $z0; $z <= $z1; ++$z) {
|
||||
$b = $this->getBlockWithoutVector($x, $y, $z);
|
||||
if($b != false && $b->isSolid) {
|
||||
if($b != false && $b->boundingBox->intersectsWith($aABB) && $b->isSolid) {
|
||||
$aABBs[] = $b->boundingBox;
|
||||
}
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ class Level{
|
|||
"id" => $entity->type,
|
||||
"Color" => @$entity->data["Color"],
|
||||
"Sheared" => @$entity->data["Sheared"],
|
||||
"Saddled" => @$entity->data["Saddled"],
|
||||
"State" => @$entity->data["State"],
|
||||
"IsBaby" => @$entity->data["IsBaby"],
|
||||
"Health" => $entity->health,
|
||||
"Pos" => [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue