mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-14 21:35:07 +00:00
Compare commits
208 Commits
Alpha_1.4d
...
api/1.11.0
Author | SHA1 | Date | |
---|---|---|---|
891eeff75a | |||
b4f62bf423 | |||
7c76c1e3d7 | |||
37bc1273ee | |||
ffcdf49912 | |||
3e893ed0f7 | |||
bfb7e8bb9e | |||
5067b96184 | |||
cb2157ea80 | |||
5b3e65345f | |||
8aa8ae5094 | |||
220d2b7bee | |||
807107e581 | |||
9158cc4f19 | |||
2cd757d80a | |||
be20f61a93 | |||
59e9446fe5 | |||
4f47dac8ec | |||
b54c0835b7 | |||
9ca3ad8971 | |||
a644b46ec4 | |||
9d3f59fab6 | |||
6309d4abf1 | |||
39291e4061 | |||
bb71a3c4a6 | |||
eb0525e892 | |||
f49db47b2e | |||
3ff5e12302 | |||
99ad65ba44 | |||
5f4f996efe | |||
21e0739845 | |||
3a157d0f02 | |||
8e56782138 | |||
116ede3679 | |||
7c0f5987d3 | |||
547e152e40 | |||
7905fbdd29 | |||
ae65701a23 | |||
9134a69936 | |||
907fe8aff6 | |||
afa9acf22f | |||
9a5afff4ab | |||
2f8c281a2e | |||
2096dace68 | |||
8421985102 | |||
f63e859b3a | |||
c56eb0b9df | |||
3f2e5bbef4 | |||
9886eb4768 | |||
ea44eee5df | |||
9173f930ca | |||
80b6a8ebaf | |||
7c64a33389 | |||
9fac896f28 | |||
5bd76e955c | |||
63f1a50be4 | |||
24c6cca664 | |||
9fac990b19 | |||
e8e7938490 | |||
f6c4a726b3 | |||
8eec5e6b5e | |||
bd7fa71d7f | |||
7d406066a7 | |||
3e9196d224 | |||
f30986d187 | |||
f8c144be31 | |||
c61e4adcf1 | |||
5a55040ab9 | |||
83360187c9 | |||
9d97a940a6 | |||
cd21c28d46 | |||
37fd0372cc | |||
ed02026815 | |||
042a143dd6 | |||
4b73dbd9f8 | |||
d4e4430df0 | |||
469ef84733 | |||
efe75f2836 | |||
53f2f21f2d | |||
9c28f0a5be | |||
5bf5014b60 | |||
f37e79b611 | |||
7a0118820c | |||
c8b5c023cd | |||
f9dd929e04 | |||
87970726e4 | |||
1daf9a96a3 | |||
6c8b33fcc8 | |||
438591bd75 | |||
7ef8edccf4 | |||
074c8b876d | |||
f9762c870a | |||
4039895d3c | |||
d207a5daea | |||
8e3667c95b | |||
0da628deca | |||
04bdb13103 | |||
e8ad828498 | |||
f46473bbe8 | |||
692045d714 | |||
47cbf56725 | |||
3de14d8ba6 | |||
5fffabe05b | |||
3128ae9736 | |||
7be4e2fa81 | |||
95b305ce87 | |||
767800662c | |||
fe32e6f5d0 | |||
2cec0d9f36 | |||
d800a21bd4 | |||
8d9fbec4ce | |||
ab72c32769 | |||
346626305c | |||
fafbd500e1 | |||
2db2e8cfc4 | |||
854479180f | |||
902ba81e02 | |||
1ac17abec0 | |||
714ea54121 | |||
aa992684ba | |||
0c58de86b7 | |||
7ecac019a9 | |||
6cb88afe1a | |||
a677bcb331 | |||
2f6007342c | |||
b6c0eb8c96 | |||
afa8496767 | |||
d7be2ce439 | |||
6dcb5da069 | |||
3cf1692c96 | |||
d04af590d1 | |||
d4c43215b1 | |||
a40918aabf | |||
20f9352714 | |||
a605e90dfc | |||
9fc250956f | |||
db2dfc47a6 | |||
408a537001 | |||
922bfb33ac | |||
8e47c93fbc | |||
c175485cd8 | |||
b6981cc31d | |||
1f9cd6a99b | |||
ded7ada7d7 | |||
1b50879823 | |||
1bd9cbd4d3 | |||
96122d3be7 | |||
71d602a4cf | |||
c81bbdaaa9 | |||
2752393c42 | |||
312e064b07 | |||
94f91967f3 | |||
fe900b417e | |||
4c30b6b8a1 | |||
c41ac7b0a2 | |||
b220bd2a45 | |||
04ee94dc91 | |||
ea8f10efa4 | |||
04ecbd1a76 | |||
ddfc9d9ce1 | |||
a4735eaf76 | |||
306f492fc0 | |||
5e5f8bf33d | |||
3bb2f12cde | |||
1041bb0e6a | |||
49e93cee80 | |||
8b6681c56d | |||
9e3d432b9e | |||
841a3d5ee6 | |||
a5294d5ec7 | |||
5373e6be07 | |||
075137bd3c | |||
68da4b5b39 | |||
e4557a2e8e | |||
964bf98ca6 | |||
747f7685e7 | |||
bb82e7be50 | |||
7506f01302 | |||
a98da3bab1 | |||
f0d6128282 | |||
161e7ae7ec | |||
6104c5b5a3 | |||
af82d616c1 | |||
a0d4bff385 | |||
79236c971c | |||
20e63ae543 | |||
add7879720 | |||
1a064d38b1 | |||
294e680d5d | |||
811970e58d | |||
941961f5ef | |||
1963d8fde0 | |||
e44ed4da3b | |||
a72488d41e | |||
3930f379cf | |||
66ba327e62 | |||
329ca62465 | |||
26e47ef694 | |||
61ea149ff0 | |||
b3c3f896a3 | |||
d139e5f342 | |||
3abf36ad07 | |||
0bc9a9bdab | |||
98340522d9 | |||
6d09754ea7 | |||
a3b1d318cc | |||
f866efb622 | |||
b1c4578726 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@ players/*
|
||||
worlds/*
|
||||
plugins/*
|
||||
bin/*
|
||||
timings/*
|
||||
*.log
|
||||
*.txt
|
||||
*.phar
|
||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -9,3 +9,6 @@
|
||||
[submodule "src/spl"]
|
||||
path = src/spl
|
||||
url = https://github.com/PocketMine/PocketMine-SPL.git
|
||||
[submodule "tests/TesterPlugin"]
|
||||
path = tests/TesterPlugin
|
||||
url = https://github.com/PocketMine/TesterPlugin.git
|
||||
|
@ -42,7 +42,10 @@ class CrashDump{
|
||||
$this->time = time();
|
||||
$this->server = $server;
|
||||
$this->path = $this->server->getDataPath() . "CrashDump_" . date("D_M_j-H.i.s-T_Y", $this->time) . ".log";
|
||||
$this->fp = fopen($this->path, "wb");
|
||||
$this->fp = @fopen($this->path, "wb");
|
||||
if(!is_resource($this->fp)){
|
||||
throw new \RuntimeException("Could not create Crash Dump");
|
||||
}
|
||||
$this->data["time"] = $this->time;
|
||||
$this->addLine($this->server->getName() . " Crash Dump " . date("D M j H:i:s T Y", $this->time));
|
||||
$this->addLine();
|
||||
@ -137,7 +140,7 @@ class CrashDump{
|
||||
$error = $lastExceptionError;
|
||||
}else{
|
||||
$error = (array) error_get_last();
|
||||
$error["trace"] = @getTrace(4);
|
||||
$error["trace"] = @getTrace(3);
|
||||
$errorConversion = [
|
||||
E_ERROR => "E_ERROR",
|
||||
E_WARNING => "E_WARNING",
|
||||
|
@ -68,6 +68,7 @@ use pocketmine\inventory\InventoryHolder;
|
||||
use pocketmine\inventory\PlayerInventory;
|
||||
use pocketmine\inventory\SimpleTransactionGroup;
|
||||
use pocketmine\inventory\StonecutterShapelessRecipe;
|
||||
use pocketmine\item\Armor;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\format\FullChunk;
|
||||
use pocketmine\level\format\LevelProvider;
|
||||
@ -147,6 +148,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
protected $moveToSend = [];
|
||||
protected $motionToSend = [];
|
||||
|
||||
/** @var Vector3 */
|
||||
public $speed = null;
|
||||
|
||||
public $blocked = false;
|
||||
public $achievements = [];
|
||||
public $lastCorrect;
|
||||
@ -167,8 +171,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
protected $iusername;
|
||||
protected $displayName;
|
||||
protected $startAction = false;
|
||||
/** @var Vector3|bool */
|
||||
protected $sleeping = false;
|
||||
/** @var Vector3 */
|
||||
protected $sleeping = null;
|
||||
protected $clientID = null;
|
||||
|
||||
protected $stepHeight = 0.6;
|
||||
@ -191,6 +195,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
private $inAction = false;
|
||||
|
||||
protected $inAirTicks = 0;
|
||||
protected $lastSpeedTick = 0;
|
||||
protected $speedTicks = 0;
|
||||
protected $highSpeedTicks = 0;
|
||||
|
||||
|
||||
private $needACK = [];
|
||||
@ -210,6 +217,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
public function setBanned($value){
|
||||
if($value === true){
|
||||
$this->server->getNameBans()->addBan($this->getName(), null, null, null);
|
||||
$this->kick("You have been banned");
|
||||
}else{
|
||||
$this->server->getNameBans()->remove($this->getName());
|
||||
}
|
||||
@ -251,20 +259,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
* @param Player $player
|
||||
*/
|
||||
public function spawnTo(Player $player){
|
||||
if($this->spawned === true and $this->dead !== true and $this !== $player and $player->getLevel() === $this->level and $player->canSee($this)){
|
||||
if($this->spawned === true and $this->dead !== true and $player->dead !== true and $player->getLevel() === $this->level and $player->canSee($this)){
|
||||
parent::spawnTo($player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
*/
|
||||
public function despawnFrom(Player $player){
|
||||
if($this->spawned === true and $this->dead !== true){
|
||||
parent::despawnFrom($player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Server
|
||||
*/
|
||||
@ -323,6 +322,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function resetFallDistance(){
|
||||
parent::resetFallDistance();
|
||||
$this->inAirTicks = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@ -526,7 +530,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
* @return bool
|
||||
*/
|
||||
public function isSleeping(){
|
||||
return $this->sleeping instanceof Vector3;
|
||||
return $this->sleeping !== null;
|
||||
}
|
||||
|
||||
public function unloadChunk($x, $z){
|
||||
@ -616,6 +620,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$X = null;
|
||||
$Z = null;
|
||||
Level::getXZ($index, $X, $Z);
|
||||
|
||||
if(!$this->level->isChunkPopulated($X, $Z)){
|
||||
$this->level->generateChunk($X, $Z);
|
||||
if($this->spawned){
|
||||
@ -668,6 +673,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->server->broadcastMessage($ev->getJoinMessage());
|
||||
}
|
||||
|
||||
$this->noDamageTicks = 60;
|
||||
|
||||
$this->spawnToAll();
|
||||
|
||||
if($this->server->getUpdater()->hasUpdate() and $this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)){
|
||||
@ -696,7 +703,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
for($Z = -$side; $Z <= $side; ++$Z){
|
||||
$chunkX = $X + $centerX;
|
||||
$chunkZ = $Z + $centerZ;
|
||||
if(!isset($this->usedChunks[$index = "$chunkX:$chunkZ"])){
|
||||
if(!isset($this->usedChunks[$index = Level::chunkHash($chunkX, $chunkZ)])){
|
||||
$newOrder[$index] = abs($X) + abs($Z);
|
||||
}else{
|
||||
$currentQueue[$index] = abs($X) + abs($Z);
|
||||
@ -802,7 +809,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
public function sleepOn(Vector3 $pos){
|
||||
foreach($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p){
|
||||
if($p instanceof Player){
|
||||
if($p->sleeping instanceof Vector3){
|
||||
if($p->sleeping !== null){
|
||||
if($pos->distance($p->sleeping) <= 0.1){
|
||||
return false;
|
||||
}
|
||||
@ -871,7 +878,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
if($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE){
|
||||
foreach($this->level->getPlayers() as $p){
|
||||
if($p->sleeping === false){
|
||||
if($p->sleeping === null){
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1050,7 +1057,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
protected function getCreativeBlock(Item $item){
|
||||
foreach(Block::$creative as $i => $d){
|
||||
if($d[0] === $item->getID() and $d[1] === $item->getDamage()){
|
||||
if($d[0] === $item->getId() and $d[1] === $item->getDamage()){
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
@ -1068,6 +1075,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
protected function processMovement($currentTick){
|
||||
if($this->dead or !$this->spawned or !($this->newPosition instanceof Vector3)){
|
||||
$diff = ($currentTick - $this->lastSpeedTick);
|
||||
if($diff >= 10){
|
||||
$this->speed = new Vector3(0, 0, 0);
|
||||
}elseif($diff > 5 and $this->speedTicks < 20){
|
||||
++$this->speedTicks;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1075,7 +1089,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$revert = false;
|
||||
|
||||
if($distanceSquared > 10000){
|
||||
if($distanceSquared > 100){
|
||||
$revert = true;
|
||||
}else{
|
||||
if($this->chunk === null or !$this->chunk->isGenerated()){
|
||||
@ -1097,8 +1111,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$dy = $this->newPosition->y - $this->y;
|
||||
$dz = $this->newPosition->z - $this->z;
|
||||
|
||||
//$this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z);
|
||||
$revert = !$this->move($dx, $dy, $dz);
|
||||
$this->fastMove($dx, $dy, $dz);
|
||||
|
||||
$diffX = $this->x - $this->newPosition->x;
|
||||
$diffZ = $this->z - $this->newPosition->z;
|
||||
@ -1109,17 +1122,19 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$diff = $diffX ** 2 + $diffY ** 2 + $diffZ ** 2;
|
||||
|
||||
if(!$revert and !$this->isSleeping() and $this->isSurvival()){
|
||||
if($diff > 0.0625){
|
||||
$revert = true;
|
||||
//$this->server->getLogger()->warning($this->getName()." moved wrongly!");
|
||||
}elseif($diff > 0){
|
||||
$this->x = $this->newPosition->x;
|
||||
$this->y = $this->newPosition->y;
|
||||
$this->z = $this->newPosition->z;
|
||||
$radius = $this->width / 2;
|
||||
$this->boundingBox->setBounds($this->x - $radius, $this->y + $this->ySize, $this->z - $radius, $this->x + $radius, $this->y + $this->height + $this->ySize, $this->z + $radius);
|
||||
if($this->isSurvival()){
|
||||
if(!$revert and !$this->isSleeping()){
|
||||
if($diff > 0.0625){
|
||||
$revert = true;
|
||||
$this->server->getLogger()->warning($this->getName()." moved wrongly!");
|
||||
}
|
||||
}
|
||||
}elseif($diff > 0){
|
||||
$this->x = $this->newPosition->x;
|
||||
$this->y = $this->newPosition->y;
|
||||
$this->z = $this->newPosition->z;
|
||||
$radius = $this->width / 2;
|
||||
$this->boundingBox->setBounds($this->x - $radius, $this->y + $this->ySize, $this->z - $radius, $this->x + $radius, $this->y + $this->height + $this->ySize, $this->z + $radius);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1130,6 +1145,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch);
|
||||
|
||||
if(!$revert and ($delta > (1 / 16) or $deltaAngle > 10)){
|
||||
|
||||
$isFirst = ($this->lastX === null or $this->lastY === null or $this->lastZ === null);
|
||||
|
||||
$this->lastX = $to->x;
|
||||
$this->lastY = $to->y;
|
||||
$this->lastZ = $to->z;
|
||||
@ -1137,29 +1155,53 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->lastYaw = $to->yaw;
|
||||
$this->lastPitch = $to->pitch;
|
||||
|
||||
$ev = new PlayerMoveEvent($this, $from, $to);
|
||||
if(!$isFirst){
|
||||
$ev = new PlayerMoveEvent($this, $from, $to);
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
|
||||
if(!($revert = $ev->isCancelled())){ //Yes, this is intended
|
||||
if($to->distance($ev->getTo()) > 0.1){ //If plugins modify the destination
|
||||
$this->teleport($ev->getTo());
|
||||
}else{
|
||||
$pk = new MovePlayerPacket();
|
||||
$pk->eid = $this->id;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$pk->bodyYaw = $this->yaw;
|
||||
if(!($revert = $ev->isCancelled())){ //Yes, this is intended
|
||||
if($to->distanceSquared($ev->getTo()) > 0.01){ //If plugins modify the destination
|
||||
$this->teleport($ev->getTo());
|
||||
}else{
|
||||
$pk = new MovePlayerPacket();
|
||||
$pk->eid = $this->id;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$pk->bodyYaw = $this->yaw;
|
||||
|
||||
Server::broadcastPacket($this->hasSpawned, $pk);
|
||||
Server::broadcastPacket($this->hasSpawned, $pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ticks = min(20, $currentTick - $this->lastSpeedTick + 0.5);
|
||||
if($this->speedTicks > 0){
|
||||
$ticks += $this->speedTicks;
|
||||
}
|
||||
$this->speed = $from->subtract($to)->divide($ticks);
|
||||
$this->lastSpeedTick = $currentTick;
|
||||
}elseif($distanceSquared == 0){
|
||||
$this->speed = new Vector3(0, 0, 0);
|
||||
$this->lastSpeedTick = $currentTick;
|
||||
}
|
||||
|
||||
if($this->speedTicks > 0){
|
||||
--$this->speedTicks;
|
||||
}
|
||||
|
||||
if($revert){
|
||||
|
||||
$this->lastX = $from->x;
|
||||
$this->lastY = $from->y;
|
||||
$this->lastZ = $from->z;
|
||||
|
||||
$this->lastYaw = $from->yaw;
|
||||
$this->lastPitch = $from->pitch;
|
||||
|
||||
$pk = new MovePlayerPacket();
|
||||
$pk->eid = 0;
|
||||
$pk->x = $from->x;
|
||||
@ -1171,13 +1213,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$pk->teleport = true;
|
||||
$this->directDataPacket($pk);
|
||||
$this->forceMovement = new Vector3($from->x, $from->y, $from->z);
|
||||
$this->newPosition = null;
|
||||
}else{
|
||||
$this->forceMovement = null;
|
||||
if($distanceSquared != 0 and $this->nextChunkOrderRun > 20){
|
||||
$this->nextChunkOrderRun = 20;
|
||||
}
|
||||
}
|
||||
|
||||
$this->newPosition = null;
|
||||
}
|
||||
|
||||
public function updateMovement(){
|
||||
@ -1185,8 +1228,16 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
|
||||
public function onUpdate($currentTick){
|
||||
if($this->dead === true){
|
||||
return true;
|
||||
if(!$this->loggedIn){
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->dead === true and $this->spawned){
|
||||
++$this->deadTicks;
|
||||
if($this->deadTicks >= 10){
|
||||
$this->despawnFromAll();
|
||||
}
|
||||
return $this->deadTicks < 10;
|
||||
}
|
||||
|
||||
$this->timings->startTiming();
|
||||
@ -1198,15 +1249,43 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$this->entityBaseTick(1);
|
||||
|
||||
if($this->speed and $this->forceMovement === null and $this->isSurvival()){
|
||||
$speed = sqrt($this->speed->x ** 2 + $this->speed->z ** 2);
|
||||
if($speed > 0.45){
|
||||
$this->highSpeedTicks += $speed > 3 ? 2 : 1;
|
||||
if($this->highSpeedTicks > 40 and !$this->server->getAllowFlight()){
|
||||
if($this->kick("Flying is not enabled on this server")){
|
||||
return false;
|
||||
}
|
||||
}elseif($this->highSpeedTicks >= 10 and $this->highSpeedTicks % 4 === 0){
|
||||
$this->forceMovement = $this->getPosition();
|
||||
}
|
||||
}elseif($this->highSpeedTicks > 0){
|
||||
if($speed < 22){
|
||||
$this->highSpeedTicks = 0;
|
||||
}else{
|
||||
$this->highSpeedTicks--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($this->onGround){
|
||||
$this->inAirTicks = 0;
|
||||
}else{
|
||||
if($this->inAirTicks > 100 and $this->isSurvival() and !$this->isSleeping() and $this->spawned and !$this->server->getAllowFlight()){
|
||||
$this->kick("Flying is not enabled on this server");
|
||||
return false;
|
||||
}else{
|
||||
++$this->inAirTicks;
|
||||
if($this->inAirTicks > 10 and $this->isSurvival() and !$this->isSleeping()){
|
||||
$expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - 2));
|
||||
$diff = sqrt(abs($this->speed->y - $expectedVelocity));
|
||||
|
||||
if($diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()){
|
||||
if($this->inAirTicks < 100){
|
||||
$this->setMotion(new Vector3(0, $expectedVelocity, 0));
|
||||
}elseif($this->kick("Flying is not enabled on this server")){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
++$this->inAirTicks;
|
||||
}
|
||||
|
||||
foreach($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity){
|
||||
@ -1228,11 +1307,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$pk = new TakeItemEntityPacket();
|
||||
$pk->eid = 0;
|
||||
$pk->target = $entity->getID();
|
||||
$pk->target = $entity->getId();
|
||||
$this->dataPacket($pk);
|
||||
$pk = new TakeItemEntityPacket();
|
||||
$pk->eid = $this->getID();
|
||||
$pk->target = $entity->getID();
|
||||
$pk->eid = $this->getId();
|
||||
$pk->target = $entity->getId();
|
||||
Server::broadcastPacket($entity->getViewers(), $pk);
|
||||
$this->inventory->addItem(clone $item, $this);
|
||||
$entity->kill();
|
||||
@ -1251,7 +1330,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
continue;
|
||||
}
|
||||
|
||||
switch($item->getID()){
|
||||
switch($item->getId()){
|
||||
case Item::WOOD:
|
||||
$this->awardAchievement("mineWood");
|
||||
break;
|
||||
@ -1262,11 +1341,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$pk = new TakeItemEntityPacket();
|
||||
$pk->eid = 0;
|
||||
$pk->target = $entity->getID();
|
||||
$pk->target = $entity->getId();
|
||||
$this->dataPacket($pk);
|
||||
$pk = new TakeItemEntityPacket();
|
||||
$pk->eid = $this->getID();
|
||||
$pk->target = $entity->getID();
|
||||
$pk->eid = $this->getId();
|
||||
$pk->target = $entity->getId();
|
||||
Server::broadcastPacket($entity->getViewers(), $pk);
|
||||
$this->inventory->addItem(clone $item, $this);
|
||||
$entity->kill();
|
||||
@ -1505,6 +1584,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if($this->spawned === false or $this->dead === true){
|
||||
break;
|
||||
}
|
||||
$packet->yaw %= 360;
|
||||
$packet->pitch %= 360;
|
||||
|
||||
if($packet->yaw < 0){
|
||||
$packet->yaw += 360;
|
||||
}
|
||||
|
||||
$this->setRotation($packet->yaw, $this->pitch);
|
||||
break;
|
||||
case ProtocolInfo::MOVE_PLAYER_PACKET:
|
||||
@ -1517,11 +1603,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->forceMovement = new Vector3($this->x, $this->y, $this->z);
|
||||
}
|
||||
|
||||
if($this->forceMovement instanceof Vector3 and ($revert or $newPos->distance($this->forceMovement) > 0.2)){
|
||||
if($this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.04 or $revert)){
|
||||
$pk = new MovePlayerPacket();
|
||||
$pk->eid = 0;
|
||||
$pk->x = $this->forceMovement->x;
|
||||
$pk->y = $this->forceMovement->y + $this->getEyeHeight() + 0.01;
|
||||
$pk->y = $this->forceMovement->y + $this->getEyeHeight();
|
||||
$pk->z = $this->forceMovement->z;
|
||||
$pk->bodyYaw = $packet->bodyYaw;
|
||||
$pk->pitch = $packet->pitch;
|
||||
@ -1579,7 +1665,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}else{
|
||||
$this->inventory->setHeldItemSlot($packet->slot); //set Air
|
||||
}
|
||||
}elseif(!isset($item) or $slot === -1 or $item->getID() !== $packet->item or $item->getDamage() !== $packet->meta){ // packet error or not implemented
|
||||
}elseif(!isset($item) or $slot === -1 or $item->getId() !== $packet->item or $item->getDamage() !== $packet->meta){ // packet error or not implemented
|
||||
$this->inventory->sendContents($this);
|
||||
break;
|
||||
}elseif($this->isCreative()){
|
||||
@ -1624,14 +1710,17 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){
|
||||
break;
|
||||
}
|
||||
}elseif($this->inventory->getItemInHand()->getID() !== $packet->item or (($damage = $this->inventory->getItemInHand()->getDamage()) !== $packet->meta and $damage !== null)){
|
||||
}elseif($this->inventory->getItemInHand()->getId() !== $packet->item or (($damage = $this->inventory->getItemInHand()->getDamage()) !== $packet->meta and $damage !== null)){
|
||||
$this->inventory->sendHeldItem($this);
|
||||
}else{
|
||||
$item = $this->inventory->getItemInHand();
|
||||
$oldItem = clone $item;
|
||||
//TODO: Implement adventure mode checks
|
||||
if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){
|
||||
$this->inventory->setItemInHand($item, $this);
|
||||
$this->inventory->sendHeldItem($this->hasSpawned);
|
||||
if(!$item->equals($oldItem, true) or $item->getCount() !== $oldItem->getCount()){
|
||||
$this->inventory->setItemInHand($item, $this);
|
||||
$this->inventory->sendHeldItem($this->hasSpawned);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1642,7 +1731,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$pk->x = $target->x;
|
||||
$pk->y = $target->y;
|
||||
$pk->z = $target->z;
|
||||
$pk->block = $target->getID();
|
||||
$pk->block = $target->getId();
|
||||
$pk->meta = $target->getDamage();
|
||||
$this->dataPacket($pk);
|
||||
|
||||
@ -1650,14 +1739,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$pk->x = $block->x;
|
||||
$pk->y = $block->y;
|
||||
$pk->z = $block->z;
|
||||
$pk->block = $block->getID();
|
||||
$pk->block = $block->getId();
|
||||
$pk->meta = $block->getDamage();
|
||||
$this->dataPacket($pk);
|
||||
break;
|
||||
}elseif($packet->face === 0xff){
|
||||
if($this->isCreative()){
|
||||
$item = $this->inventory->getItemInHand();
|
||||
}elseif($this->inventory->getItemInHand()->getID() !== $packet->item or (($damage = $this->inventory->getItemInHand()->getDamage()) !== $packet->meta and $damage !== null)){
|
||||
}elseif($this->inventory->getItemInHand()->getId() !== $packet->item or (($damage = $this->inventory->getItemInHand()->getDamage()) !== $packet->meta and $damage !== null)){
|
||||
$this->inventory->sendHeldItem($this);
|
||||
break;
|
||||
}else{
|
||||
@ -1674,7 +1763,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
break;
|
||||
}
|
||||
|
||||
if($item->getID() === Item::SNOWBALL){
|
||||
if($item->getId() === Item::SNOWBALL){
|
||||
$nbt = new Compound("", [
|
||||
"Pos" => new Enum("Pos", [
|
||||
new Double("", $this->x),
|
||||
@ -1724,7 +1813,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
switch($packet->action){
|
||||
case 5: //Shot arrow
|
||||
if($this->inventory->getItemInHand()->getID() === Item::BOW){
|
||||
if($this->inventory->getItemInHand()->getId() === Item::BOW){
|
||||
$bow = $this->inventory->getItemInHand();
|
||||
if($this->isSurvival()){
|
||||
if(!$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){
|
||||
@ -1736,19 +1825,19 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$nbt = new Compound("", [
|
||||
"Pos" => new Enum("Pos", [
|
||||
new Double("", $this->x),
|
||||
new Double("", $this->y + $this->getEyeHeight()),
|
||||
new Double("", $this->z)
|
||||
]),
|
||||
new Double("", $this->x),
|
||||
new Double("", $this->y + $this->getEyeHeight()),
|
||||
new Double("", $this->z)
|
||||
]),
|
||||
"Motion" => new Enum("Motion", [
|
||||
new Double("", -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)),
|
||||
new Double("", -sin($this->pitch / 180 * M_PI)),
|
||||
new Double("", cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI))
|
||||
]),
|
||||
new Double("", -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)),
|
||||
new Double("", -sin($this->pitch / 180 * M_PI)),
|
||||
new Double("", cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI))
|
||||
]),
|
||||
"Rotation" => new Enum("Rotation", [
|
||||
new Float("", $this->yaw),
|
||||
new Float("", $this->pitch)
|
||||
]),
|
||||
new Float("", $this->yaw),
|
||||
new Float("", $this->pitch)
|
||||
]),
|
||||
]);
|
||||
|
||||
$f = 1.5;
|
||||
@ -1802,13 +1891,17 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if($this->isCreative()){
|
||||
$item = $this->inventory->getItemInHand();
|
||||
}else{
|
||||
$item = clone $this->inventory->getItemInHand();
|
||||
$item = $this->inventory->getItemInHand();
|
||||
}
|
||||
|
||||
$oldItem = clone $item;
|
||||
|
||||
if($this->level->useBreakOn($vector, $item, $this) === true){
|
||||
if($this->isSurvival()){
|
||||
$this->inventory->setItemInHand($item, $this);
|
||||
$this->inventory->sendHeldItem($this->hasSpawned);
|
||||
if(!$item->equals($oldItem, true) or $item->getCount() !== $oldItem->getCount()){
|
||||
$this->inventory->setItemInHand($item, $this);
|
||||
$this->inventory->sendHeldItem($this->hasSpawned);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1821,7 +1914,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$pk->x = $target->x;
|
||||
$pk->y = $target->y;
|
||||
$pk->z = $target->z;
|
||||
$pk->block = $target->getID();
|
||||
$pk->block = $target->getId();
|
||||
$pk->meta = $target->getDamage();
|
||||
$this->dataPacket($pk);
|
||||
|
||||
@ -1855,7 +1948,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if($target instanceof Entity and $this->getGamemode() !== Player::VIEW and $this->dead !== true and $target->dead !== true){
|
||||
if($target instanceof DroppedItem or $target instanceof Arrow){
|
||||
$this->kick("Attempting to attack an invalid entity");
|
||||
$this->server->getLogger()->warning("Player ". $this->getName() ." tried to attack an invalid entity");
|
||||
$this->server->getLogger()->warning("Player " . $this->getName() . " tried to attack an invalid entity");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1887,9 +1980,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
];
|
||||
|
||||
$damage = [
|
||||
EntityDamageEvent::MODIFIER_BASE => isset($damageTable[$item->getID()]) ? $damageTable[$item->getID()] : 1,
|
||||
EntityDamageEvent::MODIFIER_BASE => isset($damageTable[$item->getId()]) ? $damageTable[$item->getId()] : 1,
|
||||
];
|
||||
|
||||
$points = 0;
|
||||
if($this->distance($target) > 8){
|
||||
$cancelled = true;
|
||||
}elseif($target instanceof Player){
|
||||
@ -1899,34 +1993,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$cancelled = true;
|
||||
}
|
||||
|
||||
$armorValues = [
|
||||
Item::LEATHER_CAP => 1,
|
||||
Item::LEATHER_TUNIC => 3,
|
||||
Item::LEATHER_PANTS => 2,
|
||||
Item::LEATHER_BOOTS => 1,
|
||||
Item::CHAIN_HELMET => 1,
|
||||
Item::CHAIN_CHESTPLATE => 5,
|
||||
Item::CHAIN_LEGGINGS => 4,
|
||||
Item::CHAIN_BOOTS => 1,
|
||||
Item::GOLD_HELMET => 1,
|
||||
Item::GOLD_CHESTPLATE => 5,
|
||||
Item::GOLD_LEGGINGS => 3,
|
||||
Item::GOLD_BOOTS => 1,
|
||||
Item::IRON_HELMET => 2,
|
||||
Item::IRON_CHESTPLATE => 6,
|
||||
Item::IRON_LEGGINGS => 5,
|
||||
Item::IRON_BOOTS => 2,
|
||||
Item::DIAMOND_HELMET => 3,
|
||||
Item::DIAMOND_CHESTPLATE => 8,
|
||||
Item::DIAMOND_LEGGINGS => 6,
|
||||
Item::DIAMOND_BOOTS => 3,
|
||||
];
|
||||
$points = 0;
|
||||
foreach($target->getInventory()->getArmorContents() as $index => $i){
|
||||
if(isset($armorValues[$i->getID()])){
|
||||
$points += $armorValues[$i->getID()];
|
||||
}
|
||||
}
|
||||
$points = $target->getInventory()->getArmorPoints();
|
||||
|
||||
$damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04);
|
||||
}
|
||||
@ -1954,7 +2021,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case ProtocolInfo::ANIMATE_PACKET:
|
||||
if($this->spawned === false or $this->dead === true){
|
||||
@ -1967,7 +2033,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
|
||||
$pk = new AnimatePacket();
|
||||
$pk->eid = $this->getID();
|
||||
$pk->eid = $this->getId();
|
||||
$pk->action = $ev->getAnimationType();
|
||||
Server::broadcastPacket($this->getViewers(), $pk);
|
||||
break;
|
||||
@ -1981,11 +2047,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn()));
|
||||
|
||||
$this->teleport($ev->getRespawnPosition());
|
||||
|
||||
$this->fireTicks = 0;
|
||||
$this->airTicks = 300;
|
||||
$this->deadTicks = 0;
|
||||
$this->noDamageTicks = 60;
|
||||
|
||||
$this->setHealth(20);
|
||||
$this->dead = false;
|
||||
|
||||
$this->sendMetadata($this->getViewers());
|
||||
$this->sendMetadata($this);
|
||||
|
||||
@ -1993,9 +2063,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->inventory->sendContents($this);
|
||||
$this->inventory->sendArmorContents($this);
|
||||
|
||||
$this->spawnToAll();
|
||||
|
||||
$this->blocked = false;
|
||||
|
||||
$this->spawnToAll();
|
||||
$this->scheduleUpdate();
|
||||
break;
|
||||
case ProtocolInfo::SET_HEALTH_PACKET: //Not used
|
||||
break;
|
||||
@ -2033,7 +2104,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
//Item::RAW_FISH => 2,
|
||||
];
|
||||
$slot = $this->inventory->getItemInHand();
|
||||
if($this->getHealth() < 20 and isset($items[$slot->getID()])){
|
||||
if($this->getHealth() < 20 and isset($items[$slot->getId()])){
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $slot));
|
||||
if($ev->isCancelled()){
|
||||
$this->inventory->sendContents($this);
|
||||
@ -2044,10 +2115,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$pk->eid = 0;
|
||||
$pk->event = 9;
|
||||
$this->dataPacket($pk);
|
||||
$pk->eid = $this->getID();
|
||||
$pk->eid = $this->getId();
|
||||
Server::broadcastPacket($this->getViewers(), $pk);
|
||||
|
||||
$amount = $items[$slot->getID()];
|
||||
$amount = $items[$slot->getId()];
|
||||
$this->server->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($this, $amount, EntityRegainHealthEvent::CAUSE_EATING));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->heal($ev->getAmount(), $ev);
|
||||
@ -2055,7 +2126,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
--$slot->count;
|
||||
$this->inventory->setItemInHand($slot, $this);
|
||||
if($slot->getID() === Item::MUSHROOM_STEW or $slot->getID() === Item::BEETROOT_SOUP){
|
||||
if($slot->getId() === Item::MUSHROOM_STEW or $slot->getId() === Item::BEETROOT_SOUP){
|
||||
$this->inventory->addItem(Item::get(Item::BOWL, 0, 1), $this);
|
||||
}
|
||||
}
|
||||
@ -2162,7 +2233,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
|
||||
|
||||
if($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < (microtime(true) - 0.4)){
|
||||
if($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < (microtime(true) - 8)){
|
||||
if($this->currentTransaction instanceof SimpleTransactionGroup){
|
||||
foreach($this->currentTransaction->getInventories() as $inventory){
|
||||
if($inventory instanceof PlayerInventory){
|
||||
@ -2177,19 +2248,16 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->currentTransaction->addTransaction($transaction);
|
||||
|
||||
if($this->currentTransaction->canExecute()){
|
||||
if(!$this->currentTransaction->execute()){
|
||||
$this->currentTransaction = null;
|
||||
break;
|
||||
}
|
||||
|
||||
foreach($this->currentTransaction->getTransactions() as $ts){
|
||||
$inv = $ts->getInventory();
|
||||
if($inv instanceof FurnaceInventory){
|
||||
if($ts->getSlot() === 2){
|
||||
switch($inv->getResult()->getID()){
|
||||
case Item::IRON_INGOT:
|
||||
$this->awardAchievement("acquireIron");
|
||||
break;
|
||||
if($this->currentTransaction->execute()){
|
||||
foreach($this->currentTransaction->getTransactions() as $ts){
|
||||
$inv = $ts->getInventory();
|
||||
if($inv instanceof FurnaceInventory){
|
||||
if($ts->getSlot() === 2){
|
||||
switch($inv->getResult()->getId()){
|
||||
case Item::IRON_INGOT:
|
||||
$this->awardAchievement("acquireIron");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2207,7 +2275,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
|
||||
if($craftingGroup->execute()){
|
||||
switch($craftingGroup->getResult()->getID()){
|
||||
switch($craftingGroup->getResult()->getId()){
|
||||
case Item::WORKBENCH:
|
||||
$this->awardAchievement("buildWorkBench");
|
||||
break;
|
||||
@ -2354,6 +2422,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->server->getOnlinePlayers() as $player){
|
||||
if(!$player->canSee($this)){
|
||||
$player->showPlayer($this);
|
||||
}
|
||||
}
|
||||
$this->hiddenPlayers = [];
|
||||
|
||||
foreach($this->windowIndex as $window){
|
||||
$this->removeWindow($window);
|
||||
}
|
||||
@ -2516,7 +2591,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
|
||||
$message = $this->getName() . " blew up";
|
||||
break;
|
||||
|
||||
|
||||
case EntityDamageEvent::CAUSE_MAGIC:
|
||||
case EntityDamageEvent::CAUSE_CUSTOM:
|
||||
|
||||
@ -2546,8 +2621,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS);
|
||||
}
|
||||
|
||||
$this->despawnFromAll();
|
||||
|
||||
if($this->server->isHardcore()){
|
||||
$this->setBanned(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function setHealth($amount){
|
||||
@ -2563,6 +2639,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if($this->dead === true){
|
||||
return;
|
||||
}
|
||||
|
||||
if($this->isCreative()){
|
||||
if($source instanceof EntityDamageEvent){
|
||||
$cause = $source->getCause();
|
||||
@ -2585,8 +2662,24 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
parent::attack($damage, $source);
|
||||
|
||||
if($source instanceof EntityDamageEvent and $source->isCancelled()){
|
||||
return;
|
||||
if($source instanceof EntityDamageEvent){
|
||||
if($source->isCancelled()){
|
||||
return;
|
||||
}
|
||||
if($source->getDamage(EntityDamageEvent::MODIFIER_ARMOR) > 0){
|
||||
for($i = 0; $i < 4; $i++){
|
||||
$piece = $this->getInventory()->getArmorItem($i);
|
||||
if($piece instanceof Armor){
|
||||
$damage = $piece->getDamage();
|
||||
if($damage >= $piece->getMaxDurability()){
|
||||
$this->getInventory()->setArmorItem($i, Item::get(Item::AIR));
|
||||
}else{
|
||||
$piece->setDamage($damage + 1);
|
||||
$this->getInventory()->setArmorItem($i, $piece);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($this->getLastDamageCause() === $source){
|
||||
@ -2595,13 +2688,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$pk->event = 2;
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function getData(){ //TODO
|
||||
$flags = 0;
|
||||
$flags |= $this->fireTicks > 0 ? 1 : 0;
|
||||
//$flags |= ($this->crouched === true ? 0b10:0) << 1;
|
||||
$flags |= ($this->inAction === true ? 0b10000:0);
|
||||
$flags |= ($this->inAction === true ? 0b10000 : 0);
|
||||
$d = [
|
||||
0 => ["type" => 0, "value" => $flags],
|
||||
1 => ["type" => 1, "value" => $this->airTicks],
|
||||
@ -2630,11 +2725,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
|
||||
$this->airTicks = 300;
|
||||
$this->fallDistance = 0;
|
||||
$this->resetFallDistance();
|
||||
$this->orderChunks();
|
||||
$this->nextChunkOrderRun = 0;
|
||||
$this->forceMovement = $pos;
|
||||
$this->newPosition = $pos;
|
||||
$this->forceMovement = new Vector3($this->x, $this->y, $this->z);
|
||||
$this->newPosition = null;
|
||||
|
||||
$pk = new MovePlayerPacket();
|
||||
$pk->eid = 0;
|
||||
|
@ -70,10 +70,10 @@ namespace pocketmine {
|
||||
use pocketmine\utils\Utils;
|
||||
use pocketmine\wizard\Installer;
|
||||
|
||||
const VERSION = "Alpha_1.4dev";
|
||||
const API_VERSION = "1.7.1";
|
||||
const VERSION = "1.4.1";
|
||||
const API_VERSION = "1.11.0";
|
||||
const CODENAME = "絶好(Zekkou)ケーキ(Cake)";
|
||||
const MINECRAFT_VERSION = "v0.10.4 alpha";
|
||||
const MINECRAFT_VERSION = "v0.10.5 alpha";
|
||||
|
||||
/*
|
||||
* Startup code. Do not look at it, it may harm you.
|
||||
@ -95,6 +95,7 @@ namespace pocketmine {
|
||||
}
|
||||
|
||||
if(!class_exists("ClassLoader", false)){
|
||||
require_once(\pocketmine\PATH . "src/spl/ThreadedFactory.php");
|
||||
require_once(\pocketmine\PATH . "src/spl/ClassLoader.php");
|
||||
require_once(\pocketmine\PATH . "src/spl/BaseClassLoader.php");
|
||||
require_once(\pocketmine\PATH . "src/pocketmine/CompatibleClassLoader.php");
|
||||
@ -103,7 +104,6 @@ namespace pocketmine {
|
||||
$autoloader = new CompatibleClassLoader();
|
||||
$autoloader->addPath(\pocketmine\PATH . "src");
|
||||
$autoloader->addPath(\pocketmine\PATH . "src" . DIRECTORY_SEPARATOR . "spl");
|
||||
$autoloader->addPath(\pocketmine\PATH . "src" . DIRECTORY_SEPARATOR . "raklib");
|
||||
$autoloader->register(true);
|
||||
|
||||
|
||||
@ -116,7 +116,7 @@ namespace pocketmine {
|
||||
ini_set("display_startup_errors", 1);
|
||||
ini_set("default_charset", "utf-8");
|
||||
|
||||
ini_set("memory_limit", "256M"); //Default
|
||||
ini_set("memory_limit", -1);
|
||||
define("pocketmine\\START_TIME", microtime(true));
|
||||
|
||||
$opts = getopt("", ["enable-ansi", "disable-ansi", "data:", "plugins:", "no-wizard", "enable-profiler"]);
|
||||
@ -127,7 +127,9 @@ namespace pocketmine {
|
||||
define("pocketmine\\ANSI", (Utils::getOS() !== "win" or isset($opts["enable-ansi"])) and !isset($opts["disable-ansi"]));
|
||||
|
||||
|
||||
@mkdir(\pocketmine\DATA, 0777, true);
|
||||
if(!file_exists(\pocketmine\DATA)){
|
||||
mkdir(\pocketmine\DATA, 0777, true);
|
||||
}
|
||||
|
||||
//Logger has a dependency on timezone, so we'll set it to UTC until we can get the actual timezone.
|
||||
date_default_timezone_set("UTC");
|
||||
@ -143,8 +145,8 @@ namespace pocketmine {
|
||||
if($response = Utils::getURL("http://ip-api.com/json")
|
||||
and $ip_geolocation_data = json_decode($response, true)
|
||||
and $ip_geolocation_data['status'] != 'fail'
|
||||
and date_default_timezone_set($ip_geolocation_data['timezone']))
|
||||
{
|
||||
and date_default_timezone_set($ip_geolocation_data['timezone'])
|
||||
){
|
||||
//Again, for redundancy.
|
||||
ini_set("date.timezone", $ip_geolocation_data['timezone']);
|
||||
}else{
|
||||
@ -192,8 +194,7 @@ namespace pocketmine {
|
||||
//Detect the Time Zone string
|
||||
preg_match($regex, $string, $matches);
|
||||
|
||||
if(!isset($matches[2]))
|
||||
{
|
||||
if(!isset($matches[2])){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -251,6 +252,7 @@ namespace pocketmine {
|
||||
|
||||
/**
|
||||
* @param string $offset In the format of +09:00, +02:00, -04:00 etc.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function parse_offset($offset){
|
||||
@ -331,7 +333,7 @@ namespace pocketmine {
|
||||
$args = $trace[$i]["params"];
|
||||
}
|
||||
foreach($args as $name => $value){
|
||||
$params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", ";
|
||||
$params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . (is_array($value) ? "Array()" : @strval($value))) . ", ";
|
||||
}
|
||||
}
|
||||
$messages[] = "#$j " . (isset($trace[$i]["file"]) ? cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")";
|
||||
@ -367,8 +369,8 @@ namespace pocketmine {
|
||||
if(substr_count($pthreads_version, ".") < 2){
|
||||
$pthreads_version = "0.$pthreads_version";
|
||||
}
|
||||
if(version_compare($pthreads_version, "2.0.8") < 0){
|
||||
$logger->critical("pthreads >= 2.0.8 is required, while you have $pthreads_version.");
|
||||
if(version_compare($pthreads_version, "2.0.9") < 0){
|
||||
$logger->critical("pthreads >= 2.0.9 is required, while you have $pthreads_version.");
|
||||
++$errors;
|
||||
}
|
||||
|
||||
@ -432,7 +434,7 @@ namespace pocketmine {
|
||||
new Installer();
|
||||
}
|
||||
|
||||
if(substr(__FILE__, 0, 7) !== "phar://"){
|
||||
if(\Phar::running(true) === ""){
|
||||
$logger->warning("Non-packaged PocketMine-MP installation detected, do not use on production.");
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ use pocketmine\inventory\InventoryType;
|
||||
use pocketmine\inventory\Recipe;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\format\anvil\Anvil;
|
||||
use pocketmine\level\format\leveldb\LevelDB;
|
||||
use pocketmine\level\format\LevelProviderManager;
|
||||
use pocketmine\level\format\mcregion\McRegion;
|
||||
use pocketmine\level\generator\Flat;
|
||||
@ -85,6 +86,7 @@ use pocketmine\plugin\Plugin;
|
||||
use pocketmine\plugin\PluginLoadOrder;
|
||||
use pocketmine\plugin\PluginManager;
|
||||
use pocketmine\scheduler\CallbackTask;
|
||||
use pocketmine\scheduler\GarbageCollectionTask;
|
||||
use pocketmine\scheduler\SendUsageTask;
|
||||
use pocketmine\scheduler\ServerScheduler;
|
||||
use pocketmine\tile\Chest;
|
||||
@ -149,8 +151,8 @@ class Server{
|
||||
*/
|
||||
private $tickCounter;
|
||||
private $nextTick = 0;
|
||||
private $tickAverage = [20,20,20,20,20];
|
||||
private $useAverage = [20,20,20,20,20];
|
||||
private $tickAverage = [20, 20, 20, 20, 20];
|
||||
private $useAverage = [20, 20, 20, 20, 20];
|
||||
|
||||
/** @var \AttachableThreadedLogger */
|
||||
private $logger;
|
||||
@ -299,7 +301,7 @@ class Server{
|
||||
* @return int
|
||||
*/
|
||||
public function getViewDistance(){
|
||||
return max(56, $this->getProperty("chunk-sending.max-chunks"));
|
||||
return max(56, $this->getProperty("chunk-sending.max-chunks", 256));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -313,7 +315,7 @@ class Server{
|
||||
* @return string
|
||||
*/
|
||||
public function getServerName(){
|
||||
return $this->getConfigString("motd", "Unknown server");
|
||||
return $this->getConfigString("motd", "Minecraft: PE Server");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -621,6 +623,16 @@ class Server{
|
||||
$this->mainInterface->putRaw($address, $port, $payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocks an IP address from the main interface. Setting timeout to -1 will block it forever
|
||||
*
|
||||
* @param string $address
|
||||
* @param int $timeout
|
||||
*/
|
||||
public function blockAddress($address, $timeout = 300){
|
||||
$this->mainInterface->blockAddress($address, $timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $address
|
||||
* @param int $port
|
||||
@ -632,9 +644,13 @@ class Server{
|
||||
$this->queryHandler->handle($address, $port, $payload);
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
if($this->logger instanceof MainLogger){
|
||||
$this->logger->logException($e);
|
||||
if(\pocketmine\DEBUG > 1){
|
||||
if($this->logger instanceof MainLogger){
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
}
|
||||
|
||||
$this->blockAddress($address, 600);
|
||||
}
|
||||
//TODO: add raw packet events
|
||||
}
|
||||
@ -667,7 +683,7 @@ class Server{
|
||||
$result = $this->getPlayerExact($name);
|
||||
|
||||
if($result === null){
|
||||
return new OfflinePlayer($this, $name);
|
||||
$result = new OfflinePlayer($this, $name);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -795,8 +811,15 @@ class Server{
|
||||
*/
|
||||
public function saveOfflinePlayerData($name, Compound $nbtTag){
|
||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||
$nbt->setData($nbtTag);
|
||||
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
|
||||
try{
|
||||
$nbt->setData($nbtTag);
|
||||
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
|
||||
}catch(\Exception $e){
|
||||
$this->logger->critical("Could not save player " . $name . ": " . $e->getMessage());
|
||||
if(\pocketmine\DEBUG > 1 and $this->logger instanceof MainLogger){
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -944,7 +967,7 @@ class Server{
|
||||
*/
|
||||
public function unloadLevel(Level $level, $forceUnload = false){
|
||||
if($level->unload($forceUnload) === true){
|
||||
unset($this->levels[$level->getID()]);
|
||||
unset($this->levels[$level->getId()]);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -991,11 +1014,13 @@ class Server{
|
||||
$level = new Level($this, $name, $path, $provider);
|
||||
}catch(\Exception $e){
|
||||
$this->logger->error("Could not load level \"" . $name . "\": " . $e->getMessage());
|
||||
|
||||
if($this->logger instanceof MainLogger){
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->levels[$level->getID()] = $level;
|
||||
$this->levels[$level->getId()] = $level;
|
||||
|
||||
$level->initLevel();
|
||||
|
||||
@ -1114,10 +1139,11 @@ class Server{
|
||||
|
||||
$seed = $seed === null ? Binary::readInt(@Utils::getRandomBytes(4, false)) : (int) $seed;
|
||||
|
||||
if($generator !== null and class_exists($generator) and is_subclass_of($generator, Generator::class)){
|
||||
$generator = new $generator($options);
|
||||
}else{
|
||||
if(!isset($options["presey"])){
|
||||
$options["preset"] = $this->getConfigString("generator-settings", "");
|
||||
}
|
||||
|
||||
if(!($generator !== null and class_exists($generator, true) and is_subclass_of($generator, Generator::class))){
|
||||
$generator = Generator::getGenerator($this->getLevelType());
|
||||
}
|
||||
|
||||
@ -1125,14 +1151,22 @@ class Server{
|
||||
$provider = LevelProviderManager::getProviderByName($providerName = "mcregion");
|
||||
}
|
||||
|
||||
$path = $this->getDataPath() . "worlds/" . $name . "/";
|
||||
/** @var \pocketmine\level\format\LevelProvider $provider */
|
||||
$provider::generate($path, $name, $seed, $generator, $options);
|
||||
try{
|
||||
$path = $this->getDataPath() . "worlds/" . $name . "/";
|
||||
/** @var \pocketmine\level\format\LevelProvider $provider */
|
||||
$provider::generate($path, $name, $seed, $generator, $options);
|
||||
|
||||
$level = new Level($this, $name, $path, $provider);
|
||||
$this->levels[$level->getID()] = $level;
|
||||
$level = new Level($this, $name, $path, $provider);
|
||||
$this->levels[$level->getId()] = $level;
|
||||
|
||||
$level->initLevel();
|
||||
$level->initLevel();
|
||||
}catch(\Exception $e){
|
||||
$this->logger->error("Could not generate level \"" . $name . "\": " . $e->getMessage());
|
||||
if($this->logger instanceof MainLogger){
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->getPluginManager()->callEvent(new LevelInitEvent($level));
|
||||
|
||||
@ -1224,24 +1258,9 @@ class Server{
|
||||
* @return mixed
|
||||
*/
|
||||
public function getProperty($variable, $defaultValue = null){
|
||||
$vars = explode(".", $variable);
|
||||
$base = array_shift($vars);
|
||||
if($this->config->exists($base)){
|
||||
$base = $this->config->get($base);
|
||||
}else{
|
||||
return $defaultValue;
|
||||
}
|
||||
$value = $this->config->getNested($variable);
|
||||
|
||||
while(count($vars) > 0){
|
||||
$baseKey = array_shift($vars);
|
||||
if(is_array($base) and isset($base[$baseKey])){
|
||||
$base = $base[$baseKey];
|
||||
}else{
|
||||
return $defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $base;
|
||||
return $value === null ? $defaultValue : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1444,7 +1463,7 @@ class Server{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ClassLoader $autoloader
|
||||
* @param \ClassLoader $autoloader
|
||||
* @param \ThreadedLogger $logger
|
||||
* @param string $filePath
|
||||
* @param string $dataPath
|
||||
@ -1456,31 +1475,22 @@ class Server{
|
||||
$this->autoloader = $autoloader;
|
||||
$this->logger = $logger;
|
||||
$this->filePath = $filePath;
|
||||
@mkdir($dataPath . "worlds/", 0777);
|
||||
@mkdir($dataPath . "players/", 0777);
|
||||
@mkdir($pluginPath, 0777);
|
||||
if(!file_exists($dataPath . "worlds/")){
|
||||
mkdir($dataPath . "worlds/", 0777);
|
||||
}
|
||||
|
||||
if(!file_exists($dataPath . "players/")){
|
||||
mkdir($dataPath . "players/", 0777);
|
||||
}
|
||||
|
||||
if(!file_exists($pluginPath)){
|
||||
mkdir($pluginPath, 0777);
|
||||
}
|
||||
|
||||
$this->dataPath = realpath($dataPath) . DIRECTORY_SEPARATOR;
|
||||
$this->pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR;
|
||||
|
||||
$this->entityMetadata = new EntityMetadataStore();
|
||||
$this->playerMetadata = new PlayerMetadataStore();
|
||||
$this->levelMetadata = new LevelMetadataStore();
|
||||
|
||||
$this->operators = new Config($this->dataPath . "ops.txt", Config::ENUM);
|
||||
$this->whitelist = new Config($this->dataPath . "white-list.txt", Config::ENUM);
|
||||
if(file_exists($this->dataPath . "banned.txt") and !file_exists($this->dataPath . "banned-players.txt")){
|
||||
@rename($this->dataPath . "banned.txt", $this->dataPath . "banned-players.txt");
|
||||
}
|
||||
@touch($this->dataPath . "banned-players.txt");
|
||||
$this->banByName = new BanList($this->dataPath . "banned-players.txt");
|
||||
$this->banByName->load();
|
||||
@touch($this->dataPath . "banned-ips.txt");
|
||||
$this->banByIP = new BanList($this->dataPath . "banned-ips.txt");
|
||||
$this->banByIP->load();
|
||||
|
||||
$this->consoleThreaded = new \Threaded();
|
||||
$this->console = new CommandReader($this->consoleThreaded);
|
||||
$this->console = new CommandReader();
|
||||
|
||||
$version = new VersionString($this->getPocketMineVersion());
|
||||
$this->logger->info("Starting Minecraft: PE server version " . TextFormat::AQUA . $this->getVersion());
|
||||
@ -1499,7 +1509,7 @@ class Server{
|
||||
$this->properties = new Config($this->dataPath . "server.properties", Config::PROPERTIES, [
|
||||
"motd" => "Minecraft: PE Server",
|
||||
"server-port" => 19132,
|
||||
"memory-limit" => "256M",
|
||||
"memory-limit" => -1,
|
||||
"white-list" => false,
|
||||
"announce-player-achievements" => true,
|
||||
"spawn-protection" => 16,
|
||||
@ -1530,18 +1540,34 @@ class Server{
|
||||
$this->rcon = new RCON($this, $this->getConfigString("rcon.password", ""), $this->getConfigInt("rcon.port", $this->getPort()), ($ip = $this->getIp()) != "" ? $ip : "0.0.0.0", $this->getConfigInt("rcon.threads", 1), $this->getConfigInt("rcon.clients-per-thread", 50));
|
||||
}
|
||||
|
||||
$this->entityMetadata = new EntityMetadataStore();
|
||||
$this->playerMetadata = new PlayerMetadataStore();
|
||||
$this->levelMetadata = new LevelMetadataStore();
|
||||
|
||||
$this->operators = new Config($this->dataPath . "ops.txt", Config::ENUM);
|
||||
$this->whitelist = new Config($this->dataPath . "white-list.txt", Config::ENUM);
|
||||
if(file_exists($this->dataPath . "banned.txt") and !file_exists($this->dataPath . "banned-players.txt")){
|
||||
@rename($this->dataPath . "banned.txt", $this->dataPath . "banned-players.txt");
|
||||
}
|
||||
@touch($this->dataPath . "banned-players.txt");
|
||||
$this->banByName = new BanList($this->dataPath . "banned-players.txt");
|
||||
$this->banByName->load();
|
||||
@touch($this->dataPath . "banned-ips.txt");
|
||||
$this->banByIP = new BanList($this->dataPath . "banned-ips.txt");
|
||||
$this->banByIP->load();
|
||||
|
||||
$this->maxPlayers = $this->getConfigInt("max-players", 20);
|
||||
$this->setAutoSave($this->getConfigBoolean("auto-save", true));
|
||||
|
||||
if(($memory = str_replace("B", "", strtoupper($this->getConfigString("memory-limit", "256M")))) !== false){
|
||||
if(($memory = str_replace("B", "", strtoupper($this->getConfigString("memory-limit", -1)))) !== false and $memory > 1){
|
||||
$value = ["M" => 1, "G" => 1024];
|
||||
$real = ((int) substr($memory, 0, -1)) * $value[substr($memory, -1)];
|
||||
if($real < 128){
|
||||
$this->logger->warning($this->getName() . " may not work right with less than 128MB of RAM", true, true, 0);
|
||||
$this->logger->warning($this->getName() . " may not work right with less than 128MB of RAM");
|
||||
}
|
||||
@ini_set("memory_limit", $memory);
|
||||
}else{
|
||||
$this->setConfigString("memory-limit", "256M");
|
||||
$this->setConfigString("memory-limit", -1);
|
||||
}
|
||||
|
||||
if($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3){
|
||||
@ -1569,8 +1595,8 @@ class Server{
|
||||
|
||||
$this->addInterface($this->mainInterface = new RakLibInterface($this));
|
||||
|
||||
$this->logger->info("This server is running " . $this->getName() . " version " . ($version->isDev() ? TextFormat::YELLOW : "") . $version->get(true) . TextFormat::WHITE . " \"" . $this->getCodename() . "\" (API " . $this->getApiVersion() . ")", true, true, 0);
|
||||
$this->logger->info($this->getName() . " is distributed under the LGPL License", true, true, 0);
|
||||
$this->logger->info("This server is running " . $this->getName() . " version " . ($version->isDev() ? TextFormat::YELLOW : "") . $version->get(true) . TextFormat::WHITE . " \"" . $this->getCodename() . "\" (API " . $this->getApiVersion() . ")");
|
||||
$this->logger->info($this->getName() . " is distributed under the LGPL License");
|
||||
|
||||
PluginManager::$pluginParentTimer = new TimingsHandler("** Plugins");
|
||||
Timings::init();
|
||||
@ -1609,20 +1635,17 @@ class Server{
|
||||
|
||||
LevelProviderManager::addProvider($this, Anvil::class);
|
||||
LevelProviderManager::addProvider($this, McRegion::class);
|
||||
if(extension_loaded("leveldb")){
|
||||
$this->logger->debug("Enabling LevelDB support");
|
||||
LevelProviderManager::addProvider($this, LevelDB::class);
|
||||
}
|
||||
|
||||
|
||||
Generator::addGenerator(Flat::class, "flat");
|
||||
Generator::addGenerator(Normal::class, "normal");
|
||||
Generator::addGenerator(Normal::class, "default");
|
||||
|
||||
//Temporal workaround, pthreads static property nullification test
|
||||
if(PluginManager::$pluginParentTimer === null or Timings::$serverTickTimer === null){
|
||||
$this->getLogger()->emergency("You are using an invalid pthreads version. Please update your binaries.");
|
||||
kill(getmypid());
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($this->getProperty("worlds", []) as $name => $worldSetting){
|
||||
foreach((array) $this->getProperty("worlds", []) as $name => $worldSetting){
|
||||
if($this->loadLevel($name) === false){
|
||||
$seed = $this->getProperty("worlds.$name.seed", time());
|
||||
$options = explode(":", $this->getProperty("worlds.$name.generator", Generator::getGenerator("default")));
|
||||
@ -1673,14 +1696,16 @@ class Server{
|
||||
$this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "doLevelGC"]), $this->getProperty("chunk-gc.period-in-ticks", 600), $this->getProperty("chunk-gc.period-in-ticks", 600));
|
||||
}
|
||||
|
||||
$this->scheduler->scheduleRepeatingTask(new GarbageCollectionTask(), 900);
|
||||
|
||||
$this->enablePlugins(PluginLoadOrder::POSTWORLD);
|
||||
|
||||
$this->start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
* @param Player[]|null $recipients
|
||||
* @param $message
|
||||
* @param Player[] $recipients
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@ -1688,6 +1713,8 @@ class Server{
|
||||
if(!is_array($recipients)){
|
||||
return $this->broadcast($message, self::BROADCAST_CHANNEL_USERS);
|
||||
}
|
||||
|
||||
/** @var Player[] $recipients */
|
||||
foreach($recipients as $recipient){
|
||||
$recipient->sendMessage($message);
|
||||
}
|
||||
@ -1825,7 +1852,7 @@ class Server{
|
||||
$this->properties->reload();
|
||||
$this->maxPlayers = $this->getConfigInt("max-players", 20);
|
||||
|
||||
if(($memory = str_replace("B", "", strtoupper($this->getConfigString("memory-limit", "256M")))) !== false){
|
||||
if(($memory = str_replace("B", "", strtoupper($this->getConfigString("memory-limit", -1)))) !== false and $memory > 1){
|
||||
$value = ["M" => 1, "G" => 1024];
|
||||
$real = ((int) substr($memory, 0, -1)) * $value[substr($memory, -1)];
|
||||
if($real < 256){
|
||||
@ -1833,7 +1860,7 @@ class Server{
|
||||
}
|
||||
@ini_set("memory_limit", $memory);
|
||||
}else{
|
||||
$this->setConfigString("memory-limit", "256M");
|
||||
$this->setConfigString("memory-limit", -1);
|
||||
}
|
||||
|
||||
if($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3){
|
||||
@ -1845,6 +1872,9 @@ class Server{
|
||||
$this->reloadWhitelist();
|
||||
$this->operators->reload();
|
||||
|
||||
foreach($this->getIPBans()->getEntries() as $entry){
|
||||
$this->blockAddress($entry->getName(), -1);
|
||||
}
|
||||
|
||||
$this->pluginManager->registerInterface(PharPluginLoader::class);
|
||||
$this->pluginManager->loadPlugins($this->pluginPath);
|
||||
@ -1905,7 +1935,7 @@ class Server{
|
||||
foreach($this->interfaces as $interface){
|
||||
$interface->shutdown();
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
}catch(\Exception $e){
|
||||
$this->logger->emergency("Crashed while crashing, killing process");
|
||||
@kill(getmypid());
|
||||
}
|
||||
@ -1922,6 +1952,9 @@ class Server{
|
||||
|
||||
}
|
||||
|
||||
foreach($this->getIPBans()->getEntries() as $entry){
|
||||
$this->blockAddress($entry->getName(), -1);
|
||||
}
|
||||
|
||||
if($this->getProperty("settings.send-usage", true) !== false){
|
||||
$this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "sendUsage"]), 6000, 6000);
|
||||
@ -1968,16 +2001,6 @@ class Server{
|
||||
}
|
||||
}
|
||||
|
||||
public function checkMemory(){
|
||||
//TODO
|
||||
$info = $this->debugInfo();
|
||||
$data = $info["memory_usage"] . "," . $info["players"] . "," . $info["entities"];
|
||||
$i = count($this->memoryStats) - 1;
|
||||
if($i < 0 or $this->memoryStats[$i] !== $data){
|
||||
$this->memoryStats[] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
public function exceptionHandler(\Exception $e, $trace = null){
|
||||
if($e === null){
|
||||
return;
|
||||
@ -1985,6 +2008,10 @@ class Server{
|
||||
|
||||
global $lastError;
|
||||
|
||||
if($trace === null){
|
||||
$trace = $e->getTrace();
|
||||
}
|
||||
|
||||
$errstr = $e->getMessage();
|
||||
$errfile = $e->getFile();
|
||||
$errno = $e->getCode();
|
||||
@ -2007,7 +2034,7 @@ class Server{
|
||||
"fullFile" => $e->getFile(),
|
||||
"file" => $errfile,
|
||||
"line" => $errline,
|
||||
"trace" => @getTrace($trace === null ? 3 : 0, $trace)
|
||||
"trace" => @getTrace(1, $trace)
|
||||
];
|
||||
|
||||
global $lastExceptionError, $lastError;
|
||||
@ -2025,7 +2052,12 @@ class Server{
|
||||
ini_set("error_reporting", 0);
|
||||
ini_set("memory_limit", -1); //Fix error dump not dumped on memory problems
|
||||
$this->logger->emergency("An unrecoverable error has occurred and the server has crashed. Creating a crash dump");
|
||||
$dump = new CrashDump($this);
|
||||
try{
|
||||
$dump = new CrashDump($this);
|
||||
}catch(\Exception $e){
|
||||
$this->logger->critical("Could not create Crash Dump: " . $e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
$this->logger->emergency("Please submit the \"" . $dump->getPath() . "\" file to the Bug Reporting page. Give as much info as you can.");
|
||||
|
||||
@ -2090,9 +2122,9 @@ class Server{
|
||||
foreach($this->getLevels() as $level){
|
||||
try{
|
||||
$level->doTick($currentTick);
|
||||
}catch (\Exception $e){
|
||||
$this->logger->critical("Could not tick level ".$level->getName().": ".$e->getMessage());
|
||||
if($this->logger instanceof MainLogger){
|
||||
}catch(\Exception $e){
|
||||
$this->logger->critical("Could not tick level " . $level->getName() . ": " . $e->getMessage());
|
||||
if(\pocketmine\DEBUG > 1 and $this->logger instanceof MainLogger){
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
}
|
||||
@ -2125,7 +2157,7 @@ class Server{
|
||||
|
||||
public function sendUsage(){
|
||||
if($this->lastSendUsage instanceof SendUsageTask){
|
||||
if(!$this->lastSendUsage->isFinished()){ //do not call multiple times
|
||||
if(!$this->lastSendUsage->isGarbage()){ //do not call multiple times
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -2137,7 +2169,7 @@ class Server{
|
||||
}
|
||||
|
||||
$version = new VersionString();
|
||||
$this->lastSendUsage = new SendUsageTask("http://stats.pocketmine.net/usage.php", [
|
||||
$this->lastSendUsage = new SendUsageTask("https://stats.pocketmine.net/usage.php", [
|
||||
"serverid" => $this->serverID,
|
||||
"port" => $this->getPort(),
|
||||
"os" => Utils::getOS(),
|
||||
@ -2159,7 +2191,7 @@ class Server{
|
||||
|
||||
private function titleTick(){
|
||||
if(defined("pocketmine\\DEBUG") and \pocketmine\DEBUG >= 0 and \pocketmine\ANSI === true){
|
||||
echo "\x1b]0;". $this->getName() . " " . $this->getPocketMineVersion() . " | Online " . count($this->players) . "/" . $this->getMaxPlayers() . " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . "/" . round((memory_get_usage(true) / 1024) / 1024, 2) . " MB | U " . round($this->mainInterface->getUploadUsage() / 1024, 2) . " D " . round($this->mainInterface->getDownloadUsage() / 1024, 2) . " kB/s | TPS " . $this->getTicksPerSecond() . " | Load ". $this->getTickUsage() . "%\x07";
|
||||
echo "\x1b]0;" . $this->getName() . " " . $this->getPocketMineVersion() . " | Online " . count($this->players) . "/" . $this->getMaxPlayers() . " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . "/" . round((memory_get_usage(true) / 1024) / 1024, 2) . " MB | U " . round($this->mainInterface->getUploadUsage() / 1024, 2) . " D " . round($this->mainInterface->getDownloadUsage() / 1024, 2) . " kB/s | TPS " . $this->getTicksPerSecond() . " | Load " . $this->getTickUsage() . "%\x07";
|
||||
}
|
||||
}
|
||||
|
||||
@ -2204,13 +2236,15 @@ class Server{
|
||||
}
|
||||
}
|
||||
|
||||
Timings::$generationTimer->startTiming();
|
||||
try{
|
||||
$this->generationManager->process();
|
||||
}catch (\Exception $e){
|
||||
}catch(\Exception $e){
|
||||
if($this->logger instanceof MainLogger){
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
}
|
||||
Timings::$generationTimer->stopTiming();
|
||||
|
||||
if(($this->tickCounter % 100) === 0){
|
||||
foreach($this->levels as $level){
|
||||
|
@ -26,9 +26,13 @@ namespace pocketmine;
|
||||
*/
|
||||
abstract class Thread extends \Thread{
|
||||
|
||||
public final function start($options = PTHREADS_INHERIT_ALL){
|
||||
public function start($options = PTHREADS_INHERIT_ALL){
|
||||
ThreadManager::getInstance()->add($this);
|
||||
|
||||
return parent::start($options);
|
||||
if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()){
|
||||
return parent::start($options);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -26,9 +26,13 @@ namespace pocketmine;
|
||||
*/
|
||||
abstract class Worker extends \Worker{
|
||||
|
||||
public final function start($options = PTHREADS_INHERIT_ALL){
|
||||
public function start($options = PTHREADS_INHERIT_ALL){
|
||||
ThreadManager::getInstance()->add($this);
|
||||
|
||||
return parent::start($options);
|
||||
if(!$this->isRunning() and !$this->isJoined() and !$this->isTerminated() and !$this->isShutdown()){
|
||||
return parent::start($options);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -24,8 +24,15 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class AcaciaWoodStairs extends Stair{
|
||||
|
||||
protected $id = self::ACACIA_WOOD_STAIRS;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::ACACIA_WOOD_STAIRS, $meta, "Acacia Wood Stairs");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Acacia Wood Stairs";
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -21,29 +21,45 @@
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
|
||||
|
||||
/**
|
||||
* Air block
|
||||
*/
|
||||
class Air extends Transparent{
|
||||
public $isActivable = false;
|
||||
public $breakable = false;
|
||||
public $isFlowable = true;
|
||||
public $isTransparent = true;
|
||||
public $isReplaceable = true;
|
||||
public $isPlaceable = false;
|
||||
public $hasPhysics = false;
|
||||
public $isSolid = false;
|
||||
public $isFullBlock = true;
|
||||
|
||||
protected $id = self::AIR;
|
||||
protected $meta = 0;
|
||||
protected $name = "Air";
|
||||
protected $hardness = 0;
|
||||
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Air";
|
||||
}
|
||||
|
||||
public function isBreakable(Item $item){
|
||||
return false;
|
||||
}
|
||||
|
||||
public function canBeFlowedInto(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canBeReplaced(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canBePlaced(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isSolid(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getBoundingBox(){
|
||||
return null;
|
||||
}
|
||||
|
@ -28,11 +28,23 @@ use pocketmine\network\protocol\ChatPacket;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Bed extends Transparent{
|
||||
public function __construct($type = 0){
|
||||
parent::__construct(self::BED_BLOCK, $type, "Bed Block");
|
||||
$this->isActivable = true;
|
||||
$this->isFullBlock = false;
|
||||
$this->hardness = 1;
|
||||
|
||||
protected $id = self::BED_BLOCK;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function canBeActivated(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Bed Block";
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox(){
|
||||
@ -67,13 +79,13 @@ class Bed extends Transparent{
|
||||
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
|
||||
$b = $this;
|
||||
}else{ //Bottom Part of Bed
|
||||
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
|
||||
if($blockNorth->getId() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
|
||||
$b = $blockNorth;
|
||||
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
|
||||
}elseif($blockSouth->getId() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
|
||||
$b = $blockSouth;
|
||||
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
|
||||
}elseif($blockEast->getId() === $this->id and ($blockEast->meta & 0x08) === 0x08){
|
||||
$b = $blockEast;
|
||||
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
|
||||
}elseif($blockWest->getId() === $this->id and ($blockWest->meta & 0x08) === 0x08){
|
||||
$b = $blockWest;
|
||||
}else{
|
||||
if($player instanceof Player){
|
||||
@ -97,7 +109,7 @@ class Bed extends Transparent{
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$down = $this->getSide(0);
|
||||
if($down->isTransparent === false){
|
||||
if($down->isTransparent() === false){
|
||||
$faces = [
|
||||
0 => 3,
|
||||
1 => 4,
|
||||
@ -107,7 +119,7 @@ class Bed extends Transparent{
|
||||
$d = $player instanceof Player ? $player->getDirection() : 0;
|
||||
$next = $this->getSide($faces[(($d + 3) % 4)]);
|
||||
$downNext = $this->getSide(0);
|
||||
if($next->isReplaceable === true and $downNext->isTransparent === false){
|
||||
if($next->canBeReplaced() === true and $downNext->isTransparent() === false){
|
||||
$meta = (($d + 3) % 4) & 0x03;
|
||||
$this->getLevel()->setBlock($block, Block::get($this->id, $meta), true, true);
|
||||
$this->getLevel()->setBlock($next, Block::get($this->id, $meta | 0x08), true, true);
|
||||
@ -126,23 +138,23 @@ class Bed extends Transparent{
|
||||
$blockWest = $this->getSide(4);
|
||||
|
||||
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
|
||||
if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right
|
||||
if($blockNorth->getId() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right
|
||||
$this->getLevel()->setBlock($blockNorth, new Air(), true, true);
|
||||
}elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){
|
||||
}elseif($blockSouth->getId() === $this->id and $blockSouth->meta !== 0x08){
|
||||
$this->getLevel()->setBlock($blockSouth, new Air(), true, true);
|
||||
}elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){
|
||||
}elseif($blockEast->getId() === $this->id and $blockEast->meta !== 0x08){
|
||||
$this->getLevel()->setBlock($blockEast, new Air(), true, true);
|
||||
}elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){
|
||||
}elseif($blockWest->getId() === $this->id and $blockWest->meta !== 0x08){
|
||||
$this->getLevel()->setBlock($blockWest, new Air(), true, true);
|
||||
}
|
||||
}else{ //Bottom Part of Bed
|
||||
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
|
||||
if($blockNorth->getId() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
|
||||
$this->getLevel()->setBlock($blockNorth, new Air(), true, true);
|
||||
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
|
||||
}elseif($blockSouth->getId() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
|
||||
$this->getLevel()->setBlock($blockSouth, new Air(), true, true);
|
||||
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
|
||||
}elseif($blockEast->getId() === $this->id and ($blockEast->meta & 0x08) === 0x08){
|
||||
$this->getLevel()->setBlock($blockEast, new Air(), true, true);
|
||||
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
|
||||
}elseif($blockWest->getId() === $this->id and ($blockWest->meta & 0x08) === 0x08){
|
||||
$this->getLevel()->setBlock($blockWest, new Air(), true, true);
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Bedrock extends Solid{
|
||||
|
||||
protected $id = self::BEDROCK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::BEDROCK, 0, "Bedrock");
|
||||
$this->breakable = false;
|
||||
$this->hardness = 18000000;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Bedrock";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 18000000;
|
||||
}
|
||||
|
||||
public function isBreakable(Item $item){
|
||||
|
@ -24,8 +24,15 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Beetroot extends Crops{
|
||||
|
||||
protected $id = self::BEETROOT_BLOCK;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::BEETROOT_BLOCK, $meta, "Beetroot Block");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Beetroot Block";
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -24,8 +24,15 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class BirchWoodStairs extends Stair{
|
||||
|
||||
protected $id = self::BIRCH_WOOD_STAIRS;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::BIRCH_WOOD_STAIRS, $meta, "Birch Wood Stairs");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Birch Wood Stairs";
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -144,7 +144,6 @@ class Block extends Position implements Metadatable{
|
||||
const SUGARCANE_BLOCK = 83;
|
||||
|
||||
const FENCE = 85;
|
||||
const FENCE_OAK = 85;
|
||||
const PUMPKIN = 86;
|
||||
const NETHERRACK = 87;
|
||||
const SOUL_SAND = 88;
|
||||
@ -180,7 +179,7 @@ class Block extends Position implements Metadatable{
|
||||
|
||||
const NETHER_BRICKS_STAIRS = 114;
|
||||
|
||||
const END_PORTAL = 120;
|
||||
const END_PORTAL_FRAME = 120;
|
||||
const END_STONE = 121;
|
||||
|
||||
const SANDSTONE_STAIRS = 128;
|
||||
@ -229,16 +228,13 @@ class Block extends Position implements Metadatable{
|
||||
const HARDENED_CLAY = 172;
|
||||
const COAL_BLOCK = 173;
|
||||
|
||||
const DOUBLE_PLANT = 175;
|
||||
|
||||
const FENCE_GATE_SPRUCE = 183;
|
||||
const FENCE_GATE_BIRCH = 184;
|
||||
const FENCE_GATE_JUNGLE = 185;
|
||||
const FENCE_GATE_DARK_OAK = 186;
|
||||
const FENCE_GATE_ACACIA = 187;
|
||||
const FENCE_SPRUCE = 188;
|
||||
const FENCE_BIRCH = 189;
|
||||
const FENCE_JUNGLE = 190;
|
||||
const FENCE_DARK_OAK = 191;
|
||||
const FENCE_ACACIA = 192;
|
||||
|
||||
const PODZOL = 243;
|
||||
const BEETROOT_BLOCK = 244;
|
||||
@ -366,10 +362,11 @@ class Block extends Position implements Metadatable{
|
||||
[Item::WOODEN_DOOR, 0],
|
||||
[Item::TRAPDOOR, 0],
|
||||
[Item::FENCE, 0],
|
||||
[Item::FENCE_SPRUCE, 0],
|
||||
[Item::FENCE_BIRCH, 0],
|
||||
[Item::FENCE_DARK_OAK, 0],
|
||||
[Item::FENCE_JUNGLE, 0],
|
||||
[Item::FENCE, 1],
|
||||
[Item::FENCE, 2],
|
||||
[Item::FENCE, 3],
|
||||
[Item::FENCE, 4],
|
||||
[Item::FENCE, 5],
|
||||
[Item::FENCE_GATE, 0],
|
||||
[Item::FENCE_GATE_BIRCH, 0],
|
||||
[Item::FENCE_GATE_SPRUCE, 0],
|
||||
@ -528,180 +525,240 @@ class Block extends Position implements Metadatable{
|
||||
|
||||
/** @var \SplFixedArray */
|
||||
public static $list = null;
|
||||
/** @var \SplFixedArray */
|
||||
public static $fullList = null;
|
||||
|
||||
/** @var \SplFixedArray */
|
||||
public static $light = null;
|
||||
/** @var \SplFixedArray */
|
||||
public static $lightFilter = null;
|
||||
/** @var \SplFixedArray */
|
||||
public static $solid = null;
|
||||
/** @var \SplFixedArray */
|
||||
public static $hardness = null;
|
||||
/** @var \SplFixedArray */
|
||||
public static $transparent = null;
|
||||
|
||||
protected $id;
|
||||
protected $meta;
|
||||
protected $name = "Unknown";
|
||||
protected $breakTime = 0.20;
|
||||
protected $hardness = 10;
|
||||
public $hasEntityCollision = false;
|
||||
public $isActivable = false;
|
||||
public $breakable = true;
|
||||
public $isFlowable = false;
|
||||
public $isSolid = true;
|
||||
public $isTransparent = false;
|
||||
public $isReplaceable = false;
|
||||
public $isPlaceable = true;
|
||||
public $hasPhysics = false;
|
||||
public $isLiquid = false;
|
||||
public $isFullBlock = true;
|
||||
public $x = 0;
|
||||
public $y = 0;
|
||||
public $z = 0;
|
||||
public $frictionFactor = 0.6;
|
||||
protected $meta = 0;
|
||||
|
||||
/** @var AxisAlignedBB */
|
||||
protected $boundingBox = null;
|
||||
|
||||
/**
|
||||
* Backwards-compatibility with old way to define block properties
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key){
|
||||
static $map = [
|
||||
"hardness" => "getHardness",
|
||||
"lightLevel" => "getLightLevel",
|
||||
"frictionFactor" => "getFrictionFactor",
|
||||
"name" => "getName",
|
||||
"isPlaceable" => "canBePlaced",
|
||||
"isReplaceable" => "canBeReplaced",
|
||||
"isTransparent" => "isTransparent",
|
||||
"isSolid" => "isSolid",
|
||||
"isFlowable" => "canBeFlowedInto",
|
||||
"isActivable" => "canBeActivated",
|
||||
"hasEntityCollision" => "hasEntityCollision"
|
||||
];
|
||||
return isset($map[$key]) ? $this->{$map[$key]}() : null;
|
||||
}
|
||||
|
||||
public static function init(){
|
||||
if(self::$list === null){
|
||||
self::$list = new \SplFixedArray(256);
|
||||
self::$list[self::AIR] = Air::class;;
|
||||
self::$list[self::STONE] = Stone::class;;
|
||||
self::$list[self::GRASS] = Grass::class;;
|
||||
self::$list[self::DIRT] = Dirt::class;;
|
||||
self::$list[self::COBBLESTONE] = Cobblestone::class;;
|
||||
self::$list[self::PLANKS] = Planks::class;;
|
||||
self::$list[self::SAPLING] = Sapling::class;;
|
||||
self::$list[self::BEDROCK] = Bedrock::class;;
|
||||
self::$list[self::WATER] = Water::class;;
|
||||
self::$list[self::STILL_WATER] = StillWater::class;;
|
||||
self::$list[self::LAVA] = Lava::class;;
|
||||
self::$list[self::STILL_LAVA] = StillLava::class;;
|
||||
self::$list[self::SAND] = Sand::class;;
|
||||
self::$list[self::GRAVEL] = Gravel::class;;
|
||||
self::$list[self::GOLD_ORE] = GoldOre::class;;
|
||||
self::$list[self::IRON_ORE] = IronOre::class;;
|
||||
self::$list[self::COAL_ORE] = CoalOre::class;;
|
||||
self::$list[self::WOOD] = Wood::class;;
|
||||
self::$list[self::LEAVES] = Leaves::class;;
|
||||
self::$list[self::SPONGE] = Sponge::class;;
|
||||
self::$list[self::GLASS] = Glass::class;;
|
||||
self::$list[self::LAPIS_ORE] = LapisOre::class;;
|
||||
self::$list[self::LAPIS_BLOCK] = Lapis::class;;
|
||||
self::$list[self::SANDSTONE] = Sandstone::class;;
|
||||
self::$list[self::BED_BLOCK] = Bed::class;;
|
||||
self::$list[self::COBWEB] = Cobweb::class;;
|
||||
self::$list[self::TALL_GRASS] = TallGrass::class;;
|
||||
self::$list[self::DEAD_BUSH] = DeadBush::class;;
|
||||
self::$list[self::WOOL] = Wool::class;;
|
||||
self::$list[self::DANDELION] = Dandelion::class;;
|
||||
self::$list[self::POPPY] = CyanFlower::class;;
|
||||
self::$list[self::BROWN_MUSHROOM] = BrownMushroom::class;;
|
||||
self::$list[self::RED_MUSHROOM] = RedMushroom::class;;
|
||||
self::$list[self::GOLD_BLOCK] = Gold::class;;
|
||||
self::$list[self::IRON_BLOCK] = Iron::class;;
|
||||
self::$list[self::DOUBLE_SLAB] = DoubleSlab::class;;
|
||||
self::$list[self::SLAB] = Slab::class;;
|
||||
self::$list[self::BRICKS_BLOCK] = Bricks::class;;
|
||||
self::$list[self::TNT] = TNT::class;;
|
||||
self::$list[self::BOOKSHELF] = Bookshelf::class;;
|
||||
self::$list[self::MOSS_STONE] = MossStone::class;;
|
||||
self::$list[self::OBSIDIAN] = Obsidian::class;;
|
||||
self::$list[self::TORCH] = Torch::class;;
|
||||
self::$list[self::FIRE] = Fire::class;;
|
||||
self::$list[self::MONSTER_SPAWNER] = MonsterSpawner::class;;
|
||||
self::$list[self::WOOD_STAIRS] = WoodStairs::class;;
|
||||
self::$list[self::CHEST] = Chest::class;;
|
||||
self::$fullList = new \SplFixedArray(4096);
|
||||
self::$light = new \SplFixedArray(256);
|
||||
self::$lightFilter = new \SplFixedArray(256);
|
||||
self::$solid = new \SplFixedArray(256);
|
||||
self::$hardness = new \SplFixedArray(256);
|
||||
self::$transparent = new \SplFixedArray(256);
|
||||
self::$list[self::AIR] = Air::class;
|
||||
self::$list[self::STONE] = Stone::class;
|
||||
self::$list[self::GRASS] = Grass::class;
|
||||
self::$list[self::DIRT] = Dirt::class;
|
||||
self::$list[self::COBBLESTONE] = Cobblestone::class;
|
||||
self::$list[self::PLANKS] = Planks::class;
|
||||
self::$list[self::SAPLING] = Sapling::class;
|
||||
self::$list[self::BEDROCK] = Bedrock::class;
|
||||
self::$list[self::WATER] = Water::class;
|
||||
self::$list[self::STILL_WATER] = StillWater::class;
|
||||
self::$list[self::LAVA] = Lava::class;
|
||||
self::$list[self::STILL_LAVA] = StillLava::class;
|
||||
self::$list[self::SAND] = Sand::class;
|
||||
self::$list[self::GRAVEL] = Gravel::class;
|
||||
self::$list[self::GOLD_ORE] = GoldOre::class;
|
||||
self::$list[self::IRON_ORE] = IronOre::class;
|
||||
self::$list[self::COAL_ORE] = CoalOre::class;
|
||||
self::$list[self::WOOD] = Wood::class;
|
||||
self::$list[self::LEAVES] = Leaves::class;
|
||||
self::$list[self::SPONGE] = Sponge::class;
|
||||
self::$list[self::GLASS] = Glass::class;
|
||||
self::$list[self::LAPIS_ORE] = LapisOre::class;
|
||||
self::$list[self::LAPIS_BLOCK] = Lapis::class;
|
||||
self::$list[self::SANDSTONE] = Sandstone::class;
|
||||
self::$list[self::BED_BLOCK] = Bed::class;
|
||||
self::$list[self::COBWEB] = Cobweb::class;
|
||||
self::$list[self::TALL_GRASS] = TallGrass::class;
|
||||
self::$list[self::DEAD_BUSH] = DeadBush::class;
|
||||
self::$list[self::WOOL] = Wool::class;
|
||||
self::$list[self::DANDELION] = Dandelion::class;
|
||||
self::$list[self::POPPY] = Poppy::class;
|
||||
self::$list[self::BROWN_MUSHROOM] = BrownMushroom::class;
|
||||
self::$list[self::RED_MUSHROOM] = RedMushroom::class;
|
||||
self::$list[self::GOLD_BLOCK] = Gold::class;
|
||||
self::$list[self::IRON_BLOCK] = Iron::class;
|
||||
self::$list[self::DOUBLE_SLAB] = DoubleSlab::class;
|
||||
self::$list[self::SLAB] = Slab::class;
|
||||
self::$list[self::BRICKS_BLOCK] = Bricks::class;
|
||||
self::$list[self::TNT] = TNT::class;
|
||||
self::$list[self::BOOKSHELF] = Bookshelf::class;
|
||||
self::$list[self::MOSS_STONE] = MossStone::class;
|
||||
self::$list[self::OBSIDIAN] = Obsidian::class;
|
||||
self::$list[self::TORCH] = Torch::class;
|
||||
self::$list[self::FIRE] = Fire::class;
|
||||
self::$list[self::MONSTER_SPAWNER] = MonsterSpawner::class;
|
||||
self::$list[self::WOOD_STAIRS] = WoodStairs::class;
|
||||
self::$list[self::CHEST] = Chest::class;
|
||||
|
||||
self::$list[self::DIAMOND_ORE] = DiamondOre::class;;
|
||||
self::$list[self::DIAMOND_BLOCK] = Diamond::class;;
|
||||
self::$list[self::WORKBENCH] = Workbench::class;;
|
||||
self::$list[self::WHEAT_BLOCK] = Wheat::class;;
|
||||
self::$list[self::FARMLAND] = Farmland::class;;
|
||||
self::$list[self::FURNACE] = Furnace::class;;
|
||||
self::$list[self::BURNING_FURNACE] = BurningFurnace::class;;
|
||||
self::$list[self::SIGN_POST] = SignPost::class;;
|
||||
self::$list[self::WOOD_DOOR_BLOCK] = WoodDoor::class;;
|
||||
self::$list[self::LADDER] = Ladder::class;;
|
||||
self::$list[self::DIAMOND_ORE] = DiamondOre::class;
|
||||
self::$list[self::DIAMOND_BLOCK] = Diamond::class;
|
||||
self::$list[self::WORKBENCH] = Workbench::class;
|
||||
self::$list[self::WHEAT_BLOCK] = Wheat::class;
|
||||
self::$list[self::FARMLAND] = Farmland::class;
|
||||
self::$list[self::FURNACE] = Furnace::class;
|
||||
self::$list[self::BURNING_FURNACE] = BurningFurnace::class;
|
||||
self::$list[self::SIGN_POST] = SignPost::class;
|
||||
self::$list[self::WOOD_DOOR_BLOCK] = WoodDoor::class;
|
||||
self::$list[self::LADDER] = Ladder::class;
|
||||
|
||||
self::$list[self::COBBLESTONE_STAIRS] = CobblestoneStairs::class;;
|
||||
self::$list[self::WALL_SIGN] = WallSign::class;;
|
||||
self::$list[self::COBBLESTONE_STAIRS] = CobblestoneStairs::class;
|
||||
self::$list[self::WALL_SIGN] = WallSign::class;
|
||||
|
||||
self::$list[self::IRON_DOOR_BLOCK] = IronDoor::class;;
|
||||
self::$list[self::REDSTONE_ORE] = RedstoneOre::class;;
|
||||
self::$list[self::GLOWING_REDSTONE_ORE] = GlowingRedstoneOre::class;;
|
||||
self::$list[self::IRON_DOOR_BLOCK] = IronDoor::class;
|
||||
self::$list[self::REDSTONE_ORE] = RedstoneOre::class;
|
||||
self::$list[self::GLOWING_REDSTONE_ORE] = GlowingRedstoneOre::class;
|
||||
|
||||
self::$list[self::SNOW_LAYER] = SnowLayer::class;;
|
||||
self::$list[self::ICE] = Ice::class;;
|
||||
self::$list[self::SNOW_BLOCK] = Snow::class;;
|
||||
self::$list[self::CACTUS] = Cactus::class;;
|
||||
self::$list[self::CLAY_BLOCK] = Clay::class;;
|
||||
self::$list[self::SUGARCANE_BLOCK] = Sugarcane::class;;
|
||||
self::$list[self::SNOW_LAYER] = SnowLayer::class;
|
||||
self::$list[self::ICE] = Ice::class;
|
||||
self::$list[self::SNOW_BLOCK] = Snow::class;
|
||||
self::$list[self::CACTUS] = Cactus::class;
|
||||
self::$list[self::CLAY_BLOCK] = Clay::class;
|
||||
self::$list[self::SUGARCANE_BLOCK] = Sugarcane::class;
|
||||
|
||||
self::$list[self::FENCE] = Fence::class;;
|
||||
self::$list[self::PUMPKIN] = Pumpkin::class;;
|
||||
self::$list[self::NETHERRACK] = Netherrack::class;;
|
||||
self::$list[self::SOUL_SAND] = SoulSand::class;;
|
||||
self::$list[self::GLOWSTONE_BLOCK] = Glowstone::class;;
|
||||
self::$list[self::FENCE] = Fence::class;
|
||||
self::$list[self::PUMPKIN] = Pumpkin::class;
|
||||
self::$list[self::NETHERRACK] = Netherrack::class;
|
||||
self::$list[self::SOUL_SAND] = SoulSand::class;
|
||||
self::$list[self::GLOWSTONE_BLOCK] = Glowstone::class;
|
||||
|
||||
self::$list[self::LIT_PUMPKIN] = LitPumpkin::class;;
|
||||
self::$list[self::CAKE_BLOCK] = Cake::class;;
|
||||
self::$list[self::LIT_PUMPKIN] = LitPumpkin::class;
|
||||
self::$list[self::CAKE_BLOCK] = Cake::class;
|
||||
|
||||
self::$list[self::TRAPDOOR] = Trapdoor::class;;
|
||||
self::$list[self::TRAPDOOR] = Trapdoor::class;
|
||||
|
||||
self::$list[self::STONE_BRICKS] = StoneBricks::class;;
|
||||
self::$list[self::STONE_BRICKS] = StoneBricks::class;
|
||||
|
||||
self::$list[self::IRON_BARS] = IronBars::class;;
|
||||
self::$list[self::GLASS_PANE] = GlassPane::class;;
|
||||
self::$list[self::MELON_BLOCK] = Melon::class;;
|
||||
self::$list[self::PUMPKIN_STEM] = PumpkinStem::class;;
|
||||
self::$list[self::MELON_STEM] = MelonStem::class;;
|
||||
self::$list[self::VINE] = Vine::class;;
|
||||
self::$list[self::FENCE_GATE] = FenceGate::class;;
|
||||
self::$list[self::BRICK_STAIRS] = BrickStairs::class;;
|
||||
self::$list[self::STONE_BRICK_STAIRS] = StoneBrickStairs::class;;
|
||||
self::$list[self::IRON_BARS] = IronBars::class;
|
||||
self::$list[self::GLASS_PANE] = GlassPane::class;
|
||||
self::$list[self::MELON_BLOCK] = Melon::class;
|
||||
self::$list[self::PUMPKIN_STEM] = PumpkinStem::class;
|
||||
self::$list[self::MELON_STEM] = MelonStem::class;
|
||||
self::$list[self::VINE] = Vine::class;
|
||||
self::$list[self::FENCE_GATE] = FenceGate::class;
|
||||
self::$list[self::BRICK_STAIRS] = BrickStairs::class;
|
||||
self::$list[self::STONE_BRICK_STAIRS] = StoneBrickStairs::class;
|
||||
|
||||
self::$list[self::MYCELIUM] = Mycelium::class;;
|
||||
self::$list[self::NETHER_BRICKS] = NetherBrick::class;;
|
||||
self::$list[self::MYCELIUM] = Mycelium::class;
|
||||
self::$list[self::NETHER_BRICKS] = NetherBrick::class;
|
||||
|
||||
self::$list[self::NETHER_BRICKS_STAIRS] = NetherBrickStairs::class;;
|
||||
self::$list[self::NETHER_BRICKS_STAIRS] = NetherBrickStairs::class;
|
||||
|
||||
self::$list[self::END_PORTAL] = EndPortal::class;;
|
||||
self::$list[self::END_STONE] = EndStone::class;;
|
||||
self::$list[self::SANDSTONE_STAIRS] = SandstoneStairs::class;;
|
||||
self::$list[self::EMERALD_ORE] = EmeraldOre::class;;
|
||||
self::$list[self::END_PORTAL_FRAME] = EndPortalFrame::class;
|
||||
self::$list[self::END_STONE] = EndStone::class;
|
||||
self::$list[self::SANDSTONE_STAIRS] = SandstoneStairs::class;
|
||||
self::$list[self::EMERALD_ORE] = EmeraldOre::class;
|
||||
|
||||
self::$list[self::EMERALD_BLOCK] = Emerald::class;;
|
||||
self::$list[self::SPRUCE_WOOD_STAIRS] = SpruceWoodStairs::class;;
|
||||
self::$list[self::BIRCH_WOOD_STAIRS] = BirchWoodStairs::class;;
|
||||
self::$list[self::JUNGLE_WOOD_STAIRS] = JungleWoodStairs::class;;
|
||||
self::$list[self::STONE_WALL] = StoneWall::class;;
|
||||
self::$list[self::EMERALD_BLOCK] = Emerald::class;
|
||||
self::$list[self::SPRUCE_WOOD_STAIRS] = SpruceWoodStairs::class;
|
||||
self::$list[self::BIRCH_WOOD_STAIRS] = BirchWoodStairs::class;
|
||||
self::$list[self::JUNGLE_WOOD_STAIRS] = JungleWoodStairs::class;
|
||||
self::$list[self::STONE_WALL] = StoneWall::class;
|
||||
|
||||
self::$list[self::CARROT_BLOCK] = Carrot::class;;
|
||||
self::$list[self::POTATO_BLOCK] = Potato::class;;
|
||||
self::$list[self::CARROT_BLOCK] = Carrot::class;
|
||||
self::$list[self::POTATO_BLOCK] = Potato::class;
|
||||
|
||||
self::$list[self::QUARTZ_BLOCK] = Quartz::class;;
|
||||
self::$list[self::QUARTZ_STAIRS] = QuartzStairs::class;;
|
||||
self::$list[self::DOUBLE_WOOD_SLAB] = DoubleWoodSlab::class;;
|
||||
self::$list[self::WOOD_SLAB] = WoodSlab::class;;
|
||||
self::$list[self::STAINED_CLAY] = StainedClay::class;;
|
||||
self::$list[self::QUARTZ_BLOCK] = Quartz::class;
|
||||
self::$list[self::QUARTZ_STAIRS] = QuartzStairs::class;
|
||||
self::$list[self::DOUBLE_WOOD_SLAB] = DoubleWoodSlab::class;
|
||||
self::$list[self::WOOD_SLAB] = WoodSlab::class;
|
||||
self::$list[self::STAINED_CLAY] = StainedClay::class;
|
||||
|
||||
self::$list[self::LEAVES2] = Leaves2::class;;
|
||||
self::$list[self::WOOD2] = Wood2::class;;
|
||||
self::$list[self::ACACIA_WOOD_STAIRS] = AcaciaWoodStairs::class;;
|
||||
self::$list[self::DARK_OAK_WOOD_STAIRS] = DarkOakWoodStairs::class;;
|
||||
self::$list[self::LEAVES2] = Leaves2::class;
|
||||
self::$list[self::WOOD2] = Wood2::class;
|
||||
self::$list[self::ACACIA_WOOD_STAIRS] = AcaciaWoodStairs::class;
|
||||
self::$list[self::DARK_OAK_WOOD_STAIRS] = DarkOakWoodStairs::class;
|
||||
|
||||
self::$list[self::HAY_BALE] = HayBale::class;;
|
||||
self::$list[self::CARPET] = Carpet::class;;
|
||||
self::$list[self::HARDENED_CLAY] = HardenedClay::class;;
|
||||
self::$list[self::COAL_BLOCK] = Coal::class;;
|
||||
self::$list[self::HAY_BALE] = HayBale::class;
|
||||
self::$list[self::CARPET] = Carpet::class;
|
||||
self::$list[self::HARDENED_CLAY] = HardenedClay::class;
|
||||
self::$list[self::COAL_BLOCK] = Coal::class;
|
||||
|
||||
self::$list[self::DOUBLE_PLANT] = DoublePlant::class;
|
||||
|
||||
self::$list[self::FENCE_GATE_SPRUCE] = FenceGateSpruce::class;
|
||||
self::$list[self::FENCE_GATE_BIRCH] = FenceGateBirch::class;
|
||||
self::$list[self::FENCE_GATE_JUNGLE] = FenceGateJungle::class;
|
||||
self::$list[self::FENCE_GATE_DARK_OAK] = FenceGateDarkOak::class;
|
||||
self::$list[self::FENCE_GATE_ACACIA] = FenceGateAcacia::class;
|
||||
self::$list[self::FENCE_SPRUCE] = FenceSpruce::class;
|
||||
self::$list[self::FENCE_BIRCH] = FenceBirch::class;
|
||||
self::$list[self::FENCE_DARK_OAK] = FenceDarkOak::class;
|
||||
self::$list[self::FENCE_JUNGLE] = FenceJungle::class;
|
||||
self::$list[self::FENCE_ACACIA] = FenceAcacia::class;
|
||||
|
||||
self::$list[self::PODZOL] = Podzol::class;;
|
||||
self::$list[self::BEETROOT_BLOCK] = Beetroot::class;;
|
||||
self::$list[self::STONECUTTER] = Stonecutter::class;;
|
||||
self::$list[self::GLOWING_OBSIDIAN] = GlowingObsidian::class;;
|
||||
self::$list[self::NETHER_REACTOR] = NetherReactor::class;;
|
||||
self::$list[self::PODZOL] = Podzol::class;
|
||||
self::$list[self::BEETROOT_BLOCK] = Beetroot::class;
|
||||
self::$list[self::STONECUTTER] = Stonecutter::class;
|
||||
self::$list[self::GLOWING_OBSIDIAN] = GlowingObsidian::class;
|
||||
self::$list[self::NETHER_REACTOR] = NetherReactor::class;
|
||||
|
||||
foreach(self::$list as $id => $class){
|
||||
if($class !== null){
|
||||
/** @var Block $block */
|
||||
$block = new $class();
|
||||
|
||||
for($data = 0; $data < 16; ++$data){
|
||||
self::$fullList[($id << 4) | $data] = new $class($data);
|
||||
}
|
||||
|
||||
self::$solid[$id] = $block->isSolid();
|
||||
self::$transparent[$id] = $block->isTransparent();
|
||||
self::$hardness[$id] = $block->getHardness();
|
||||
self::$light[$id] = $block->getLightLevel();
|
||||
|
||||
if($block->isSolid()){
|
||||
if($block->isTransparent()){
|
||||
if($block instanceof Liquid or $block instanceof Ice){
|
||||
self::$lightFilter[$id] = 2;
|
||||
}else{
|
||||
self::$lightFilter[$id] = 1;
|
||||
}
|
||||
}else{
|
||||
self::$lightFilter[$id] = 15;
|
||||
}
|
||||
}else{
|
||||
self::$lightFilter[$id] = 1;
|
||||
}
|
||||
}else{
|
||||
self::$lightFilter[$id] = 1;
|
||||
for($data = 0; $data < 16; ++$data){
|
||||
self::$fullList[($id << 4) | $data] = new Block($id, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -735,14 +792,12 @@ class Block extends Position implements Metadatable{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
public function __construct($id, $meta = 0){
|
||||
$this->id = (int) $id;
|
||||
$this->meta = (int) $meta;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -771,7 +826,7 @@ class Block extends Position implements Metadatable{
|
||||
* @return bool
|
||||
*/
|
||||
public function isBreakable(Item $item){
|
||||
return $this->breakable;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -805,21 +860,86 @@ class Block extends Position implements Metadatable{
|
||||
* @return bool
|
||||
*/
|
||||
public function onActivate(Item $item, Player $player = null){
|
||||
return $this->isActivable;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
final public function getHardness(){
|
||||
return $this->hardness;
|
||||
public function getHardness(){
|
||||
return 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getFrictionFactor(){
|
||||
return 0.6;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int 0-15
|
||||
*/
|
||||
public function getLightLevel(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* AKA: Block->isPlaceable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canBePlaced(){
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* AKA: Block->canBeReplaced()
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canBeReplaced(){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isTransparent(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isSolid(){
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* AKA: Block->isFlowable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canBeFlowedInto(){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* AKA: Block->isActivable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canBeActivated(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasEntityCollision(){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
final public function getName(){
|
||||
return $this->name;
|
||||
public function getName(){
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -844,7 +964,7 @@ class Block extends Position implements Metadatable{
|
||||
* @param int $meta
|
||||
*/
|
||||
final public function setDamage($meta){
|
||||
$this->meta = $meta & 0x0F;
|
||||
$this->meta = $meta & 0x0f;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -857,6 +977,7 @@ class Block extends Position implements Metadatable{
|
||||
$this->y = (int) $v->y;
|
||||
$this->z = (int) $v->z;
|
||||
$this->level = $v->level;
|
||||
$this->boundingBox = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -884,7 +1005,7 @@ class Block extends Position implements Metadatable{
|
||||
* @return float
|
||||
*/
|
||||
public function getBreakTime(Item $item){
|
||||
return $this->breakTime;
|
||||
return 0.20;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -896,19 +1017,18 @@ class Block extends Position implements Metadatable{
|
||||
* @return Block
|
||||
*/
|
||||
public function getSide($side, $step = 1){
|
||||
$v = parent::getSide($side, $step);
|
||||
if($this->isValid()){
|
||||
return $this->getLevel()->getBlock($v);
|
||||
return $this->getLevel()->getBlock(Vector3::getSide($side, $step));
|
||||
}
|
||||
|
||||
return Block::get(Item::AIR, 0, $v);
|
||||
return Block::get(Item::AIR, 0, Position::fromObject(Vector3::getSide($side, $step)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
final public function __toString(){
|
||||
return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")";
|
||||
public function __toString(){
|
||||
return "Block[" . $this->getName() . "] (" . $this->id . ":" . $this->meta . ")";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -919,7 +1039,7 @@ class Block extends Position implements Metadatable{
|
||||
*/
|
||||
public function collidesWithBB(AxisAlignedBB $bb, &$list = []){
|
||||
$bb2 = $this->getBoundingBox();
|
||||
if($bb2 !== null and $bb2->intersectsWith($bb)){
|
||||
if($bb2 !== null and $bb->intersectsWith($bb2)){
|
||||
$list[] = $bb2;
|
||||
}
|
||||
}
|
||||
@ -935,11 +1055,10 @@ class Block extends Position implements Metadatable{
|
||||
* @return AxisAlignedBB
|
||||
*/
|
||||
public function getBoundingBox(){
|
||||
if($this->boundingBox !== null){
|
||||
return $this->boundingBox;
|
||||
}else{
|
||||
return $this->boundingBox = $this->recalculateBoundingBox();
|
||||
if($this->boundingBox === null){
|
||||
$this->boundingBox = $this->recalculateBoundingBox();
|
||||
}
|
||||
return $this->boundingBox;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,9 +23,19 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class Bookshelf extends Solid{
|
||||
|
||||
protected $id = self::BOOKSHELF;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::BOOKSHELF, 0, "Bookshelf");
|
||||
$this->hardness = 7.5;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Bookshelf";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 7.5;
|
||||
}
|
||||
|
||||
}
|
@ -23,8 +23,15 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class BrickStairs extends Stair{
|
||||
|
||||
protected $id = self::BRICK_STAIRS;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::BRICK_STAIRS, $meta, "Brick Stairs");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Brick Stairs";
|
||||
}
|
||||
|
||||
}
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Bricks extends Solid{
|
||||
|
||||
protected $id = self::BRICKS_BLOCK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::BRICKS_BLOCK, 0, "Bricks");
|
||||
$this->hardness = 30;
|
||||
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Bricks";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -26,14 +26,24 @@ use pocketmine\level\Level;
|
||||
use pocketmine\Player;
|
||||
|
||||
class BrownMushroom extends Flowable{
|
||||
public function __construct(){
|
||||
parent::__construct(self::BROWN_MUSHROOM, 0, "Brown Mushroom");
|
||||
$this->hardness = 0;
|
||||
|
||||
protected $id = self::BROWN_MUSHROOM;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Brown Mushroom";
|
||||
}
|
||||
|
||||
public function getLightLevel(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){
|
||||
if($this->getSide(0)->isTransparent() === true){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
@ -45,7 +55,7 @@ class BrownMushroom extends Flowable{
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$down = $this->getSide(0);
|
||||
if($down->isTransparent === false){
|
||||
if($down->isTransparent() === false){
|
||||
$this->getLevel()->setBlock($block, $this, true, true);
|
||||
|
||||
return true;
|
||||
|
@ -32,10 +32,27 @@ use pocketmine\tile\Furnace;
|
||||
use pocketmine\tile\Tile;
|
||||
|
||||
class BurningFurnace extends Solid{
|
||||
|
||||
protected $id = self::BURNING_FURNACE;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::BURNING_FURNACE, $meta, "Burning Furnace");
|
||||
$this->isActivable = true;
|
||||
$this->hardness = 17.5;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Burning Furnace";
|
||||
}
|
||||
|
||||
public function canBeActivated(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 17.5;
|
||||
}
|
||||
|
||||
public function getLightLevel(){
|
||||
return 13;
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -15,7 +15,7 @@
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@ -25,6 +25,8 @@ use pocketmine\entity\Entity;
|
||||
use pocketmine\event\block\BlockGrowEvent;
|
||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\inventory\InventoryHolder;
|
||||
use pocketmine\inventory\PlayerInventory;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
@ -34,12 +36,22 @@ use pocketmine\Server;
|
||||
|
||||
class Cactus extends Transparent{
|
||||
|
||||
public $hasEntityCollision = true;
|
||||
protected $id = self::CACTUS;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::CACTUS, $meta, "Cactus");
|
||||
$this->isFullBlock = false;
|
||||
$this->hardness = 2;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function hasEntityCollision(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Cactus";
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox(){
|
||||
@ -55,29 +67,36 @@ class Cactus extends Transparent{
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1);
|
||||
$damage = [EntityDamageEvent::MODIFIER_BASE => 1];
|
||||
if($entity instanceof InventoryHolder){
|
||||
$inventory = $entity->getInventory();
|
||||
if($inventory instanceof PlayerInventory){
|
||||
$damage[EntityDamageEvent::MODIFIER_ARMOR] = $inventory->getArmorPoints();
|
||||
}
|
||||
}
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, $damage);
|
||||
$entity->attack($ev->getFinalDamage(), $ev);
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() !== self::SAND and $down->getID() !== self::CACTUS){
|
||||
if($down->getId() !== self::SAND and $down->getId() !== self::CACTUS){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
}else{
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if(!$b->isFlowable){
|
||||
if(!$b->canBeFlowedInto()){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||
if($this->getSide(0)->getID() !== self::CACTUS){
|
||||
if($this->getSide(0)->getId() !== self::CACTUS){
|
||||
if($this->meta == 0x0F){
|
||||
for($y = 1; $y < 3; ++$y){
|
||||
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||
if($b->getID() === self::AIR){
|
||||
if($b->getId() === self::AIR){
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Cactus()));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->getLevel()->setBlock($b, $ev->getNewState(), true);
|
||||
@ -98,12 +117,12 @@ class Cactus extends Transparent{
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === self::SAND or $down->getID() === self::CACTUS){
|
||||
if($down->getId() === self::SAND or $down->getId() === self::CACTUS){
|
||||
$block0 = $this->getSide(2);
|
||||
$block1 = $this->getSide(3);
|
||||
$block2 = $this->getSide(4);
|
||||
$block3 = $this->getSide(5);
|
||||
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
|
||||
if($block0->isTransparent() === true and $block1->isTransparent() === true and $block2->isTransparent() === true and $block3->isTransparent() === true){
|
||||
$this->getLevel()->setBlock($this, $this, true);
|
||||
|
||||
return true;
|
||||
@ -118,4 +137,4 @@ class Cactus extends Transparent{
|
||||
[$this->id, 0, 1],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,12 +29,23 @@ use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
|
||||
class Cake extends Transparent{
|
||||
|
||||
protected $id = self::CAKE_BLOCK;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::CAKE_BLOCK, 0, "Cake Block");
|
||||
$this->isFullBlock = false;
|
||||
$this->isActivable = true;
|
||||
$this->meta = $meta & 0x07;
|
||||
$this->hardness = 2.5;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function canBeActivated(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2.5;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Cake Block";
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox(){
|
||||
@ -53,7 +64,7 @@ class Cake extends Transparent{
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() !== self::AIR){
|
||||
if($down->getId() !== self::AIR){
|
||||
$this->getLevel()->setBlock($block, $this, true, true);
|
||||
|
||||
return true;
|
||||
@ -64,7 +75,7 @@ class Cake extends Transparent{
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||
if($this->getSide(0)->getId() === self::AIR){ //Replace with common break method
|
||||
$this->getLevel()->setBlock($this, new Air(), true);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
|
@ -27,9 +27,19 @@ use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Carpet extends Flowable{
|
||||
|
||||
protected $id = self::CARPET;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::CARPET, $meta, "Carpet");
|
||||
$names = [
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function isSolid(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
0 => "White Carpet",
|
||||
1 => "Orange Carpet",
|
||||
2 => "Magenta Carpet",
|
||||
@ -47,10 +57,7 @@ class Carpet extends Flowable{
|
||||
14 => "Red Carpet",
|
||||
15 => "Black Carpet",
|
||||
];
|
||||
$this->name = $names[$this->meta];
|
||||
$this->hardness = 0;
|
||||
$this->isFullBlock = false;
|
||||
$this->isSolid = true;
|
||||
return $names[$this->meta & 0x0f];
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox(){
|
||||
@ -67,7 +74,7 @@ class Carpet extends Flowable{
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() !== self::AIR){
|
||||
if($down->getId() !== self::AIR){
|
||||
$this->getLevel()->setBlock($block, $this, true, true);
|
||||
|
||||
return true;
|
||||
@ -78,7 +85,7 @@ class Carpet extends Flowable{
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->getID() === self::AIR){
|
||||
if($this->getSide(0)->getId() === self::AIR){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
|
@ -24,8 +24,15 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Carrot extends Crops{
|
||||
|
||||
protected $id = self::CARROT_BLOCK;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::CARROT_BLOCK, $meta, "Carrot Block");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Carrot Block";
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -34,16 +34,25 @@ use pocketmine\tile\Tile;
|
||||
|
||||
class Chest extends Transparent{
|
||||
|
||||
const SLOTS = 27;
|
||||
protected $id = self::CHEST;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::CHEST, $meta, "Chest");
|
||||
$this->isActivable = true;
|
||||
$this->hardness = 15;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function canBeActivated(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Chest";
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox(){
|
||||
|
||||
return new AxisAlignedBB(
|
||||
$this->x + 0.0625,
|
||||
$this->y,
|
||||
@ -113,7 +122,7 @@ class Chest extends Transparent{
|
||||
public function onActivate(Item $item, Player $player = null){
|
||||
if($player instanceof Player){
|
||||
$top = $this->getSide(1);
|
||||
if($top->isTransparent !== true){
|
||||
if($top->isTransparent() !== true){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Clay extends Solid{
|
||||
|
||||
protected $id = self::CLAY_BLOCK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::CLAY_BLOCK, 0, "Clay Block");
|
||||
$this->hardness = 3;
|
||||
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Clay Block";
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Coal extends Solid{
|
||||
|
||||
protected $id = self::COAL_BLOCK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::COAL_BLOCK, 0, "Coal Block");
|
||||
$this->hardness = 30;
|
||||
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Coal Block";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class CoalOre extends Solid{
|
||||
|
||||
protected $id = self::COAL_ORE;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::COAL_ORE, 0, "Coal Ore");
|
||||
$this->hardness = 15;
|
||||
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Coal Ore";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Cobblestone extends Solid{
|
||||
|
||||
protected $id = self::COBBLESTONE;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::COBBLESTONE, 0, "Cobblestone");
|
||||
$this->hardness = 30;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Cobblestone";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -23,8 +23,15 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class CobblestoneStairs extends Stair{
|
||||
|
||||
protected $id = self::COBBLESTONE_STAIRS;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::COBBLESTONE_STAIRS, $meta, "Cobblestone Stairs");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Cobblestone Stairs";
|
||||
}
|
||||
|
||||
}
|
@ -26,20 +26,30 @@ use pocketmine\item\Item;
|
||||
|
||||
class Cobweb extends Flowable{
|
||||
|
||||
public $hasEntityCollision = true;
|
||||
protected $id = self::COBWEB;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::COBWEB, 0, "Cobweb");
|
||||
$this->isSolid = true;
|
||||
$this->isFullBlock = false;
|
||||
$this->hardness = 25;
|
||||
|
||||
}
|
||||
|
||||
public function hasEntityCollision(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Cobweb";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 25;
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$entity->fallDistance = 0;
|
||||
$entity->resetFallDistance();
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
//TODO: correct drops
|
||||
return [];
|
||||
}
|
||||
}
|
@ -29,17 +29,13 @@ use pocketmine\Server;
|
||||
|
||||
abstract class Crops extends Flowable{
|
||||
|
||||
public $isActivable = true;
|
||||
public $hardness = 0;
|
||||
|
||||
|
||||
public function getBoundingBox(){
|
||||
return null;
|
||||
public function canBeActivated(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === self::FARMLAND){
|
||||
if($down->getId() === self::FARMLAND){
|
||||
$this->getLevel()->setBlock($block, $this, true, true);
|
||||
|
||||
return true;
|
||||
@ -50,7 +46,7 @@ abstract class Crops extends Flowable{
|
||||
|
||||
|
||||
public function onActivate(Item $item, Player $player = null){
|
||||
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
|
||||
if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
|
||||
$block = clone $this;
|
||||
$block->meta += mt_rand(2, 5);
|
||||
if($block->meta > 7){
|
||||
@ -73,7 +69,7 @@ abstract class Crops extends Flowable{
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){
|
||||
if($this->getSide(0)->isTransparent() === true){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
|
@ -26,19 +26,21 @@ use pocketmine\level\Level;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Dandelion extends Flowable{
|
||||
|
||||
protected $id = self::DANDELION;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::DANDELION, 0, "Dandelion");
|
||||
$this->hardness = 0;
|
||||
|
||||
}
|
||||
|
||||
public function getBoundingBox(){
|
||||
return null;
|
||||
public function getName(){
|
||||
return "Dandelion";
|
||||
}
|
||||
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||
if($down->getId() === 2 or $down->getId() === 3 or $down->getId() === 60){
|
||||
$this->getLevel()->setBlock($block, $this, true, true);
|
||||
|
||||
return true;
|
||||
@ -49,7 +51,7 @@ class Dandelion extends Flowable{
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){
|
||||
if($this->getSide(0)->isTransparent() === true){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
|
@ -24,8 +24,15 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class DarkOakWoodStairs extends Stair{
|
||||
|
||||
protected $id = self::DARK_OAK_WOOD_STAIRS;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::DARK_OAK_WOOD_STAIRS, $meta, "Dark Oak Wood Stairs");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Dark Oak Wood Stairs";
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -24,21 +24,22 @@ namespace pocketmine\block;
|
||||
use pocketmine\level\Level;
|
||||
|
||||
class DeadBush extends Flowable{
|
||||
public function __construct(){
|
||||
parent::__construct(self::DEAD_BUSH, 0, "Dead Bush");
|
||||
//$this->isReplaceable = true;
|
||||
$this->hardness = 0;
|
||||
|
||||
protected $id = self::DEAD_BUSH;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getBoundingBox(){
|
||||
return null;
|
||||
public function getName(){
|
||||
return "Dead Bush";
|
||||
}
|
||||
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||
if($this->getSide(0)->isTransparent() === true){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Diamond extends Solid{
|
||||
|
||||
protected $id = self::DIAMOND_BLOCK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::DIAMOND_BLOCK, 0, "Diamond Block");
|
||||
$this->hardness = 30;
|
||||
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Diamond Block";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class DiamondOre extends Solid{
|
||||
|
||||
protected $id = self::DIAMOND_ORE;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::DIAMOND_ORE, 0, "Diamond Ore");
|
||||
$this->hardness = 15;
|
||||
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Diamond Ore";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -26,16 +26,24 @@ use pocketmine\Player;
|
||||
|
||||
class Dirt extends Solid{
|
||||
|
||||
public $isActivable = true;
|
||||
protected $hardness = 2.5;
|
||||
protected $id = self::DIRT;
|
||||
protected $meta = 0;
|
||||
protected $name = "Dirt";
|
||||
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
public function canBeActivated(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2.5;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Dirt";
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player = null){
|
||||
if($item->isHoe()){
|
||||
$item->useOn($this);
|
||||
|
@ -30,9 +30,13 @@ use pocketmine\Server;
|
||||
|
||||
|
||||
abstract class Door extends Transparent{
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isSolid = false;
|
||||
|
||||
public function canBeActivated(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isSolid(){
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getFullDamage(){
|
||||
@ -201,7 +205,7 @@ abstract class Door extends Transparent{
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||
if($this->getSide(0)->getId() === self::AIR){ //Replace with common break method
|
||||
$this->getLevel()->setBlock($this, new Air(), false);
|
||||
if($this->getSide(1) instanceof Door){
|
||||
$this->getLevel()->setBlock($this->getSide(1), new Air(), false);
|
||||
@ -218,7 +222,7 @@ abstract class Door extends Transparent{
|
||||
if($face === 1){
|
||||
$blockUp = $this->getSide(1);
|
||||
$blockDown = $this->getSide(0);
|
||||
if($blockUp->isReplaceable === false or $blockDown->isTransparent === true){
|
||||
if($blockUp->canBeReplaced() === false or $blockDown->isTransparent() === true){
|
||||
return false;
|
||||
}
|
||||
$direction = $player instanceof Player ? $player->getDirection() : 0;
|
||||
@ -231,7 +235,7 @@ abstract class Door extends Transparent{
|
||||
$next = $this->getSide($face[(($direction + 2) % 4)]);
|
||||
$next2 = $this->getSide($face[$direction]);
|
||||
$metaUp = 0x08;
|
||||
if($next->getID() === $this->id or ($next2->isTransparent === false and $next->isTransparent === true)){ //Door hinge
|
||||
if($next->getId() === $this->id or ($next2->isTransparent() === false and $next->isTransparent() === true)){ //Door hinge
|
||||
$metaUp |= 0x01;
|
||||
}
|
||||
|
||||
@ -247,12 +251,12 @@ abstract class Door extends Transparent{
|
||||
public function onBreak(Item $item){
|
||||
if(($this->meta & 0x08) === 0x08){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === $this->id){
|
||||
if($down->getId() === $this->id){
|
||||
$this->getLevel()->setBlock($down, new Air(), true);
|
||||
}
|
||||
}else{
|
||||
$up = $this->getSide(1);
|
||||
if($up->getID() === $this->id){
|
||||
if($up->getId() === $this->id){
|
||||
$this->getLevel()->setBlock($up, new Air(), true);
|
||||
}
|
||||
}
|
||||
@ -264,12 +268,12 @@ abstract class Door extends Transparent{
|
||||
public function onActivate(Item $item, Player $player = null){
|
||||
if(($this->meta & 0x08) === 0x08){ //Top
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === $this->id){
|
||||
if($down->getId() === $this->id){
|
||||
$meta = $down->getDamage() ^ 0x04;
|
||||
$this->getLevel()->setBlock($down, Block::get($this->id, $meta), true);
|
||||
$players = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4);
|
||||
if($player instanceof Player){
|
||||
unset($players[$player->getID()]);
|
||||
unset($players[$player->getId()]);
|
||||
}
|
||||
$pk = new LevelEventPacket();
|
||||
$pk->x = $this->x;
|
||||
@ -288,7 +292,7 @@ abstract class Door extends Transparent{
|
||||
$this->getLevel()->setBlock($this, $this, true);
|
||||
$players = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4);
|
||||
if($player instanceof Player){
|
||||
unset($players[$player->getID()]);
|
||||
unset($players[$player->getId()]);
|
||||
}
|
||||
$pk = new LevelEventPacket();
|
||||
$pk->x = $this->x;
|
||||
|
70
src/pocketmine/block/DoublePlant.php
Normal file
70
src/pocketmine/block/DoublePlant.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\Level;
|
||||
|
||||
class DoublePlant extends Flowable{
|
||||
|
||||
protected $id = self::DOUBLE_PLANT;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function canBeReplaced(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
0 => "Sunflower",
|
||||
1 => "Lilac",
|
||||
2 => "Double Tallgrass",
|
||||
3 => "Large Fern",
|
||||
4 => "Rose Bush",
|
||||
5 => "Peony"
|
||||
];
|
||||
return $names[$this->meta & 0x07];
|
||||
}
|
||||
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent() === true){ //Replace with common break method
|
||||
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
//TODO
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class DoubleSlab extends Solid{
|
||||
|
||||
protected $id = self::DOUBLE_SLAB;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::DOUBLE_SLAB, $meta, "Double Slab");
|
||||
$names = [
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
0 => "Stone",
|
||||
1 => "Sandstone",
|
||||
2 => "Wooden",
|
||||
@ -36,8 +46,7 @@ class DoubleSlab extends Solid{
|
||||
6 => "Quartz",
|
||||
7 => "",
|
||||
];
|
||||
$this->name = "Double " . $names[$this->meta & 0x07] . " Slab";
|
||||
$this->hardness = 30;
|
||||
return "Double " . $names[$this->meta & 0x07] . " Slab";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -24,18 +24,29 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class DoubleWoodSlab extends Solid{
|
||||
|
||||
protected $id = self::DOUBLE_WOOD_SLAB;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::DOUBLE_WOOD_SLAB, $meta, "Double Wooden Slab");
|
||||
$names = [
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
0 => "Oak",
|
||||
1 => "Spruce",
|
||||
2 => "Birch",
|
||||
3 => "Jungle",
|
||||
4 => "Acacia",
|
||||
5 => "Dark Oak",
|
||||
6 => "",
|
||||
7 => ""
|
||||
];
|
||||
$this->name = "Double " . $names[$this->meta & 0x07] . " Wooden Slab";
|
||||
$this->hardness = 15;
|
||||
return "Double " . $names[$this->meta & 0x07] . " Wooden Slab";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Emerald extends Solid{
|
||||
|
||||
protected $id = self::EMERALD_BLOCK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::EMERALD_BLOCK, 0, "Emerald Block");
|
||||
$this->hardness = 30;
|
||||
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Emerald Block";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class EmeraldOre extends Solid{
|
||||
|
||||
protected $id = self::EMERALD_ORE;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::EMERALD_ORE, 0, "Emerald Ore");
|
||||
$this->hardness = 15;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Emerald Ore";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -21,12 +21,31 @@
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
|
||||
class EndPortal extends Solid{
|
||||
class EndPortalFrame extends Solid{
|
||||
|
||||
protected $id = self::END_PORTAL_FRAME;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::END_PORTAL, $meta, "End Portal");
|
||||
$this->hardness = 18000000;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getLightLevel(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "End Portal Frame";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 18000000;
|
||||
}
|
||||
|
||||
public function isBreakable(Item $item){
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox(){
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class EndStone extends Solid{
|
||||
|
||||
protected $id = self::END_STONE;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::END_STONE, 0, "End Stone");
|
||||
$this->hardness = 45;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "End Stone";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 45;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -34,8 +34,6 @@ use pocketmine\Player;
|
||||
|
||||
abstract class Fallable extends Solid{
|
||||
|
||||
public $hasPhysics = true;
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$ret = $this->getLevel()->setBlock($this, $this, true, true);
|
||||
|
||||
@ -43,9 +41,9 @@ abstract class Fallable extends Solid{
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($this->hasPhysics === true and $type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === self::AIR or ($down instanceof Liquid)){
|
||||
if($down->getId() === self::AIR or ($down instanceof Liquid)){
|
||||
$fall = Entity::createEntity("FallingSand", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new Compound("", [
|
||||
"Pos" => new Enum("Pos", [
|
||||
new Double("", $this->x + 0.5),
|
||||
@ -61,7 +59,7 @@ abstract class Fallable extends Solid{
|
||||
new Float("", 0),
|
||||
new Float("", 0)
|
||||
]),
|
||||
"TileID" => new Int("TileID", $this->getID()),
|
||||
"TileID" => new Int("TileID", $this->getId()),
|
||||
"Data" => new Byte("Data", $this->getDamage()),
|
||||
]));
|
||||
|
||||
|
@ -25,13 +25,22 @@ use pocketmine\item\Item;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
|
||||
class Farmland extends Solid{
|
||||
|
||||
protected $id = self::FARMLAND;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::FARMLAND, $meta, "Farmland");
|
||||
$this->hardness = 3;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Farmland";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 3;
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox(){
|
||||
|
||||
return new AxisAlignedBB(
|
||||
$this->x,
|
||||
$this->y,
|
||||
|
@ -24,10 +24,30 @@ namespace pocketmine\block;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
|
||||
class Fence extends Transparent{
|
||||
public function __construct(){
|
||||
parent::__construct(self::FENCE, 0, "Oak Fence");
|
||||
$this->isFullBlock = false;
|
||||
$this->hardness = 15;
|
||||
|
||||
protected $id = self::FENCE;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
0 => "Oak Fence",
|
||||
1 => "Spruce Fence",
|
||||
2 => "Birch Fence",
|
||||
3 => "Jungle Fence",
|
||||
4 => "Acacia Fence",
|
||||
5 => "Dark Oak Fence",
|
||||
"",
|
||||
""
|
||||
];
|
||||
return $names[$this->meta & 0x07];
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox(){
|
||||
@ -37,7 +57,7 @@ class Fence extends Transparent{
|
||||
$flag2 = $this->canConnect($this->getSide(4));
|
||||
$flag3 = $this->canConnect($this->getSide(5));
|
||||
|
||||
$f = $flag2 ? 0 : 0.375;
|
||||
$f = $flag2 ? 0 : 0.375;
|
||||
$f1 = $flag3 ? 1 : 0.625;
|
||||
$f2 = $flag ? 0 : 0.375;
|
||||
$f3 = $flag1 ? 1 : 0.625;
|
||||
@ -53,7 +73,7 @@ class Fence extends Transparent{
|
||||
}
|
||||
|
||||
public function canConnect(Block $block){
|
||||
return (!($block instanceof Fence) and !($block instanceof FenceGate)) ? $block->isSolid : true;
|
||||
return (!($block instanceof Fence) and !($block instanceof FenceGate)) ? $block->isSolid() : true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -26,15 +26,23 @@ use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\Player;
|
||||
|
||||
class FenceGate extends Transparent{
|
||||
|
||||
protected $id = self::FENCE_GATE;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::FENCE_GATE, $meta, "Oak Fence Gate");
|
||||
$this->isActivable = true;
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
$this->hardness = 15;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Oak Fence Gate";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function canBeActivated(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -93,11 +101,6 @@ class FenceGate extends Transparent{
|
||||
3 => 2,
|
||||
];
|
||||
$this->meta = ($faces[$player instanceof Player ? $player->getDirection() : 0] & 0x03) | ((~$this->meta) & 0x04);
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
$this->getLevel()->setBlock($this, $this, true);
|
||||
|
||||
return true;
|
||||
|
@ -23,14 +23,10 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class FenceGateAcacia extends FenceGate{
|
||||
public function __construct($meta = 0){
|
||||
Transparent::__construct(self::FENCE_GATE_ACACIA, $meta, "Acacia Fence Gate");
|
||||
$this->isActivable = true;
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
$this->hardness = 15;
|
||||
|
||||
protected $id = self::FENCE_GATE_ACACIA;
|
||||
|
||||
public function getName(){
|
||||
return "Acacia Fence Gate";
|
||||
}
|
||||
}
|
@ -23,14 +23,10 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class FenceGateBirch extends FenceGate{
|
||||
public function __construct($meta = 0){
|
||||
Transparent::__construct(self::FENCE_GATE_BIRCH, $meta, "Birch Fence Gate");
|
||||
$this->isActivable = true;
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
$this->hardness = 15;
|
||||
|
||||
protected $id = self::FENCE_GATE_BIRCH;
|
||||
|
||||
public function getName(){
|
||||
return "Birch Fence Gate";
|
||||
}
|
||||
}
|
@ -23,14 +23,10 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class FenceGateDarkOak extends FenceGate{
|
||||
public function __construct($meta = 0){
|
||||
Transparent::__construct(self::FENCE_GATE_DARK_OAK, $meta, "Dark Oak Fence Gate");
|
||||
$this->isActivable = true;
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
$this->hardness = 15;
|
||||
|
||||
protected $id = self::FENCE_GATE_DARK_OAK;
|
||||
|
||||
public function getName(){
|
||||
return "Dark Oak Fence Gate";
|
||||
}
|
||||
}
|
@ -23,14 +23,10 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class FenceGateJungle extends FenceGate{
|
||||
public function __construct($meta = 0){
|
||||
Transparent::__construct(self::FENCE_GATE_JUNGLE, $meta, "Jungle Fence Gate");
|
||||
$this->isActivable = true;
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
$this->hardness = 15;
|
||||
|
||||
protected $id = self::FENCE_GATE_JUNGLE;
|
||||
|
||||
public function getName(){
|
||||
return "Jungle Fence Gate";
|
||||
}
|
||||
}
|
@ -23,14 +23,10 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class FenceGateSpruce extends FenceGate{
|
||||
public function __construct($meta = 0){
|
||||
Transparent::__construct(self::FENCE_GATE_SPRUCE, $meta, "Spruce Fence Gate");
|
||||
$this->isActivable = true;
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
}else{
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
$this->hardness = 15;
|
||||
|
||||
protected $id = self::FENCE_GATE_SPRUCE;
|
||||
|
||||
public function getName(){
|
||||
return "Spruce Fence Gate";
|
||||
}
|
||||
}
|
@ -2,11 +2,11 @@
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -15,7 +15,7 @@
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@ -25,28 +25,49 @@ use pocketmine\entity\Entity;
|
||||
use pocketmine\event\entity\EntityCombustByBlockEvent;
|
||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\inventory\InventoryHolder;
|
||||
use pocketmine\inventory\PlayerInventory;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\Server;
|
||||
|
||||
class Fire extends Flowable{
|
||||
|
||||
public $hasEntityCollision = true;
|
||||
protected $id = self::FIRE;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::FIRE, $meta, "Fire");
|
||||
$this->isReplaceable = true;
|
||||
$this->breakable = false;
|
||||
$this->isFullBlock = true;
|
||||
$this->hardness = 0;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getBoundingBox(){
|
||||
return null;
|
||||
public function hasEntityCollision(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Fire Block";
|
||||
}
|
||||
|
||||
public function getLightLevel(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function isBreakable(Item $item){
|
||||
return false;
|
||||
}
|
||||
|
||||
public function canBeReplaced(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
|
||||
$damage = [EntityDamageEvent::MODIFIER_BASE => 1];
|
||||
if($entity instanceof InventoryHolder){
|
||||
$inventory = $entity->getInventory();
|
||||
if($inventory instanceof PlayerInventory){
|
||||
$damage[EntityDamageEvent::MODIFIER_ARMOR] = $inventory->getArmorPoints();
|
||||
}
|
||||
}
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, $damage);
|
||||
$entity->attack($ev->getFinalDamage(), $ev);
|
||||
|
||||
$ev = new EntityCombustByBlockEvent($this, $entity, 8);
|
||||
@ -64,7 +85,7 @@ class Fire extends Flowable{
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
for($s = 0; $s <= 5; ++$s){
|
||||
$side = $this->getSide($s);
|
||||
if($side->getID() !== self::AIR and !($side instanceof Liquid)){
|
||||
if($side->getId() !== self::AIR and !($side instanceof Liquid)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -72,7 +93,7 @@ class Fire extends Flowable{
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||
if($this->getSide(0)->getID() !== self::NETHERRACK){
|
||||
if($this->getSide(0)->getId() !== self::NETHERRACK){
|
||||
$this->getLevel()->setBlock($this, new Air(), true);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
@ -82,4 +103,4 @@ class Fire extends Flowable{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,19 @@ namespace pocketmine\block;
|
||||
|
||||
abstract class Flowable extends Transparent{
|
||||
|
||||
public $isFlowable = true;
|
||||
public $isFullBlock = false;
|
||||
public $isSolid = false;
|
||||
public function canBeFlowedInto(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isSolid(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getBoundingBox(){
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -23,10 +23,10 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class Furnace extends BurningFurnace{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct($meta);
|
||||
$this->id = self::FURNACE;
|
||||
$this->name = "Furnace";
|
||||
$this->isActivable = true;
|
||||
|
||||
protected $id = self::FURNACE;
|
||||
|
||||
public function getName(){
|
||||
return "Furnace";
|
||||
}
|
||||
}
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Glass extends Transparent{
|
||||
|
||||
protected $id = self::GLASS;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::GLASS, 0, "Glass");
|
||||
$this->hardness = 1.5;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Glass";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 1.5;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -22,9 +22,25 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class GlassPane extends Thin{
|
||||
|
||||
protected $id = self::GLASS_PANE;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::GLASS_PANE, 0, "Glass Pane");
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Glass Pane";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 1.5;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
return [];
|
||||
}
|
||||
}
|
@ -23,8 +23,19 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class GlowingObsidian extends Solid{
|
||||
|
||||
protected $id = self::GLOWING_OBSIDIAN;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::GLOWING_OBSIDIAN, $meta, "Glowing Obsidian");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Glowing Obsidian";
|
||||
}
|
||||
|
||||
public function getLightLevel(){
|
||||
return 12;
|
||||
}
|
||||
|
||||
}
|
@ -25,9 +25,23 @@ use pocketmine\item\Item;
|
||||
use pocketmine\level\Level;
|
||||
|
||||
class GlowingRedstoneOre extends Solid{
|
||||
|
||||
protected $id = self::GLOWING_REDSTONE_ORE;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");
|
||||
$this->hardness = 15;
|
||||
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Glowing Redstone Ore";
|
||||
}
|
||||
|
||||
public function getLightLevel(){
|
||||
return 9;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
|
@ -24,9 +24,23 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Glowstone extends Transparent{
|
||||
|
||||
protected $id = self::GLOWSTONE_BLOCK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::GLOWSTONE_BLOCK, 0, "Glowstone");
|
||||
$this->hardness = 1.5;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Glowstone";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 1.5;
|
||||
}
|
||||
|
||||
public function getLightLevel(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Gold extends Solid{
|
||||
|
||||
protected $id = self::GOLD_BLOCK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::GOLD_BLOCK, 0, "Gold Block");
|
||||
$this->hardness = 30;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Gold Block";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class GoldOre extends Solid{
|
||||
|
||||
protected $id = self::GOLD_ORE;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::GOLD_ORE, 0, "Gold Ore");
|
||||
$this->hardness = 15;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Gold Ore";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -32,16 +32,24 @@ use pocketmine\utils\Random;
|
||||
|
||||
class Grass extends Solid{
|
||||
|
||||
public $isActivable = true;
|
||||
protected $hardness = 3;
|
||||
protected $id = self::GRASS;
|
||||
protected $meta = 0;
|
||||
protected $name = "Grass";
|
||||
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
public function canBeActivated(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Grass";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
return [
|
||||
[Item::DIRT, 0, 1],
|
||||
@ -55,7 +63,7 @@ class Grass extends Solid{
|
||||
$y = mt_rand($this->y - 2, $this->y + 2);
|
||||
$z = mt_rand($this->z - 1, $this->z + 1);
|
||||
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||
if($block->getID() === Block::DIRT){
|
||||
if($block->getId() === Block::DIRT){
|
||||
if($block->getSide(1) instanceof Transparent){
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Grass()));
|
||||
if(!$ev->isCancelled()){
|
||||
@ -67,7 +75,7 @@ class Grass extends Solid{
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player = null){
|
||||
if($item->getID() === Item::DYE and $item->getDamage() === 0x0F){
|
||||
if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){
|
||||
$item->count--;
|
||||
TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
|
||||
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Gravel extends Fallable{
|
||||
|
||||
protected $id = self::GRAVEL;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::GRAVEL, 0, "Gravel");
|
||||
$this->hardness = 3;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Gravel";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class HardenedClay extends Solid{
|
||||
|
||||
protected $id = self::HARDENED_CLAY;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::HARDENED_CLAY, 0, "Hardened Clay");
|
||||
$this->hardness = 30;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Hardened Clay";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -25,9 +25,19 @@ use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
|
||||
class HayBale extends Solid{
|
||||
|
||||
protected $id = self::HAY_BALE;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::HAY_BALE, $meta, "Hay Bale");
|
||||
$this->hardness = 10;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Hay Bale";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 10;
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Ice extends Transparent{
|
||||
|
||||
protected $id = self::ICE;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::ICE, 0, "Ice");
|
||||
$this->hardness = 2.5;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Ice";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2.5;
|
||||
}
|
||||
|
||||
public function onBreak(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Iron extends Solid{
|
||||
|
||||
protected $id = self::IRON_BLOCK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::IRON_BLOCK, 0, "Iron Block");
|
||||
$this->hardness = 30;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Iron Block";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -21,10 +21,49 @@
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class IronBars extends Thin{
|
||||
|
||||
protected $id = self::IRON_BARS;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::IRON_BARS, 0, "Iron Bars");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public function getName(){
|
||||
return "Iron Bars";
|
||||
}
|
||||
public function getHardness(){
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.95;
|
||||
case 4:
|
||||
return 1.25;
|
||||
case 3:
|
||||
return 1.9;
|
||||
case 2:
|
||||
return 0.65;
|
||||
case 1:
|
||||
return 3.75;
|
||||
default:
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return [
|
||||
[Item::IRON_BARS, 0, 1],
|
||||
];
|
||||
}else{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class IronDoor extends Door{
|
||||
|
||||
protected $id = self::IRON_DOOR_BLOCK;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::IRON_DOOR_BLOCK, $meta, "Iron Door Block");
|
||||
//$this->isActivable = true;
|
||||
$this->hardness = 25;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Iron Door Block";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 25;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class IronOre extends Solid{
|
||||
|
||||
protected $id = self::IRON_ORE;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::IRON_ORE, 0, "Iron Ore");
|
||||
$this->hardness = 15;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Iron Ore";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -24,8 +24,15 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class JungleWoodStairs extends Stair{
|
||||
|
||||
protected $id = self::JUNGLE_WOOD_STAIRS;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::JUNGLE_WOOD_STAIRS, $meta, "Jungle Wood Stairs");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Jungle Wood Stairs";
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -29,17 +29,30 @@ use pocketmine\Player;
|
||||
|
||||
class Ladder extends Transparent{
|
||||
|
||||
public $hasEntityCollision = true;
|
||||
protected $id = self::LADDER;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::LADDER, $meta, "Ladder");
|
||||
$this->isSolid = false;
|
||||
$this->isFullBlock = false;
|
||||
$this->hardness = 2;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Ladder";
|
||||
}
|
||||
|
||||
public function hasEntityCollision(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isSolid(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$entity->fallDistance = 0;
|
||||
$entity->resetFallDistance();
|
||||
$entity->onGround = true;
|
||||
}
|
||||
|
||||
@ -90,7 +103,7 @@ class Ladder extends Transparent{
|
||||
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
if($target->isTransparent === false){
|
||||
if($target->isTransparent() === false){
|
||||
$faces = [
|
||||
2 => 2,
|
||||
3 => 3,
|
||||
@ -110,7 +123,7 @@ class Ladder extends Transparent{
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
/*if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||
/*if($this->getSide(0)->getId() === self::AIR){ //Replace with common break method
|
||||
Server::getInstance()->api->entity->drop($this, Item::get(LADDER, 0, 1));
|
||||
$this->getLevel()->setBlock($this, new Air(), true, true, true);
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Lapis extends Solid{
|
||||
|
||||
protected $id = self::LAPIS_BLOCK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::LAPIS_BLOCK, 0, "Lapis Block");
|
||||
$this->hardness = 15;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Lapis Block";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class LapisOre extends Solid{
|
||||
|
||||
protected $id = self::LAPIS_ORE;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::LAPIS_ORE, 0, "Lapis Ore");
|
||||
$this->hardness = 15;
|
||||
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Lapis Ore";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -15,7 +15,7 @@
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@ -25,20 +25,42 @@ use pocketmine\entity\Entity;
|
||||
use pocketmine\event\entity\EntityCombustByBlockEvent;
|
||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\inventory\InventoryHolder;
|
||||
use pocketmine\inventory\PlayerInventory;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
|
||||
class Lava extends Liquid{
|
||||
|
||||
protected $id = self::LAVA;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::LAVA, $meta, "Lava");
|
||||
$this->hardness = 0;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getLightLevel(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Lava";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$entity->fallDistance *= 0.5;
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4);
|
||||
$damage = [EntityDamageEvent::MODIFIER_BASE => 1];
|
||||
if($entity instanceof InventoryHolder){
|
||||
$inventory = $entity->getInventory();
|
||||
if($inventory instanceof PlayerInventory){
|
||||
$damage[EntityDamageEvent::MODIFIER_ARMOR] = $inventory->getArmorPoints();
|
||||
}
|
||||
}
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, $damage);
|
||||
$entity->attack($ev->getFinalDamage(), $ev);
|
||||
|
||||
$ev = new EntityCombustByBlockEvent($this, $entity, 15);
|
||||
|
@ -35,16 +35,24 @@ class Leaves extends Transparent{
|
||||
const ACACIA = 0;
|
||||
const DARK_OAK = 1;
|
||||
|
||||
protected $id = self::LEAVES;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::LEAVES, $meta, "Leaves");
|
||||
$names = [
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
self::OAK => "Oak Leaves",
|
||||
self::SPRUCE => "Spruce Leaves",
|
||||
self::BIRCH => "Birch Leaves",
|
||||
self::JUNGLE => "Jungle Leaves",
|
||||
];
|
||||
$this->name = $names[$this->meta & 0x03];
|
||||
$this->hardness = 1;
|
||||
return $names[$this->meta & 0x03];
|
||||
}
|
||||
|
||||
private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){
|
||||
@ -53,11 +61,11 @@ class Leaves extends Transparent{
|
||||
if(isset($visited[$index])){
|
||||
return false;
|
||||
}
|
||||
if($pos->getID() === self::WOOD){
|
||||
if($pos->getId() === self::WOOD){
|
||||
return true;
|
||||
}elseif($pos->getID() === self::LEAVES and $distance < 3){
|
||||
}elseif($pos->getId() === self::LEAVES and $distance < 3){
|
||||
$visited[$index] = true;
|
||||
$down = $pos->getSide(0)->getID();
|
||||
$down = $pos->getSide(0)->getId();
|
||||
if($down === Item::WOOD){
|
||||
return true;
|
||||
}
|
||||
|
@ -29,14 +29,18 @@ use pocketmine\Server;
|
||||
|
||||
class Leaves2 extends Leaves{
|
||||
|
||||
protected $id = self::LEAVES2;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
Transparent::__construct(self::LEAVES, $meta, "Leaves");
|
||||
$names = [
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
self::ACACIA => "Acacia Leaves",
|
||||
self::DARK_OAK => "Dark Oak Leaves",
|
||||
];
|
||||
$this->name = $names[$this->meta & 0x03];
|
||||
$this->hardness = 1;
|
||||
return $names[$this->meta & 0x01];
|
||||
}
|
||||
|
||||
private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){
|
||||
@ -45,11 +49,11 @@ class Leaves2 extends Leaves{
|
||||
if(isset($visited[$index])){
|
||||
return false;
|
||||
}
|
||||
if($pos->getID() === self::WOOD2){
|
||||
if($pos->getId() === self::WOOD2){
|
||||
return true;
|
||||
}elseif($pos->getID() === self::LEAVES2 and $distance < 3){
|
||||
}elseif($pos->getId() === self::LEAVES2 and $distance < 3){
|
||||
$visited[$index] = true;
|
||||
$down = $pos->getSide(0)->getID();
|
||||
$down = $pos->getSide(0)->getId();
|
||||
if($down === Item::WOOD2){
|
||||
return true;
|
||||
}
|
||||
|
@ -28,13 +28,25 @@ use pocketmine\level\Level;
|
||||
use pocketmine\math\Vector3;
|
||||
|
||||
abstract class Liquid extends Transparent{
|
||||
public $hasEntityCollision = true;
|
||||
|
||||
public $isLiquid = true;
|
||||
public $breakable = false;
|
||||
public $isReplaceable = true;
|
||||
public $isSolid = false;
|
||||
public $isFullBlock = true;
|
||||
/** @var Vector3 */
|
||||
private $temporalVector = null;
|
||||
|
||||
public function hasEntityCollision(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isBreakable(Item $item){
|
||||
return false;
|
||||
}
|
||||
|
||||
public function canBeReplaced(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isSolid(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public $adjacentSources = 0;
|
||||
public $isOptimalFlowDirection = [0, 0, 0, 0];
|
||||
@ -54,7 +66,7 @@ abstract class Liquid extends Transparent{
|
||||
$pos = $this->getLevel()->getBlock($pos);
|
||||
}
|
||||
|
||||
if($pos->getID() !== $this->getID()){
|
||||
if($pos->getId() !== $this->getId()){
|
||||
return -1;
|
||||
}else{
|
||||
return $pos->getDamage();
|
||||
@ -66,7 +78,7 @@ abstract class Liquid extends Transparent{
|
||||
$pos = $this->getLevel()->getBlock($pos);
|
||||
}
|
||||
|
||||
if($pos->getID() !== $this->getID()){
|
||||
if($pos->getId() !== $this->getId()){
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -82,6 +94,10 @@ abstract class Liquid extends Transparent{
|
||||
public function getFlowVector(){
|
||||
$vector = new Vector3(0, 0, 0);
|
||||
|
||||
if($this->temporalVector === null){
|
||||
$this->temporalVector = new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
$decay = $this->getEffectiveFlowDecay($this);
|
||||
|
||||
for($j = 0; $j < 4; ++$j){
|
||||
@ -99,46 +115,50 @@ abstract class Liquid extends Transparent{
|
||||
}elseif($j === 3){
|
||||
++$z;
|
||||
}
|
||||
$sideBlock = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||
$sideBlock = $this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $z));
|
||||
$blockDecay = $this->getEffectiveFlowDecay($sideBlock);
|
||||
|
||||
if($blockDecay < 0){
|
||||
if(!$sideBlock->isFlowable){
|
||||
if(!$sideBlock->canBeFlowedInto()){
|
||||
continue;
|
||||
}
|
||||
|
||||
$blockDecay = $this->getEffectiveFlowDecay($sideBlock->getSide(0));
|
||||
$blockDecay = $this->getEffectiveFlowDecay($this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y - 1, $z)));
|
||||
|
||||
if($blockDecay >= 0){
|
||||
$realDecay = $blockDecay - ($decay - 8);
|
||||
$vector = $vector->add(($sideBlock->x - $this->x) * $realDecay, ($sideBlock->y - $this->y) * $realDecay, ($sideBlock->z - $this->z) * $realDecay);
|
||||
$vector->x += ($sideBlock->x - $this->x) * $realDecay;
|
||||
$vector->y += ($sideBlock->y - $this->y) * $realDecay;
|
||||
$vector->z += ($sideBlock->z - $this->z) * $realDecay;
|
||||
}
|
||||
|
||||
continue;
|
||||
}else{
|
||||
$realDecay = $blockDecay - $decay;
|
||||
$vector = $vector->add(($sideBlock->x - $this->x) * $realDecay, ($sideBlock->y - $this->y) * $realDecay, ($sideBlock->z - $this->z) * $realDecay);
|
||||
$vector->x += ($sideBlock->x - $this->x) * $realDecay;
|
||||
$vector->y += ($sideBlock->y - $this->y) * $realDecay;
|
||||
$vector->z += ($sideBlock->z - $this->z) * $realDecay;
|
||||
}
|
||||
}
|
||||
|
||||
if($this->getDamage() >= 8){
|
||||
$falling = false;
|
||||
|
||||
if(!$this->getLevel()->getBlock($this->add(0, 0, -1))->isFlowable){
|
||||
if(!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z - 1))->canBeFlowedInto()){
|
||||
$falling = true;
|
||||
}elseif(!$this->getLevel()->getBlock($this->add(0, 0, 1))->isFlowable){
|
||||
}elseif(!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z + 1))->canBeFlowedInto()){
|
||||
$falling = true;
|
||||
}elseif(!$this->getLevel()->getBlock($this->add(-1, 0, 0))->isFlowable){
|
||||
}elseif(!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x - 1, $this->y, $this->z))->canBeFlowedInto()){
|
||||
$falling = true;
|
||||
}elseif(!$this->getLevel()->getBlock($this->add(1, 0, 0))->isFlowable){
|
||||
}elseif(!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x + 1, $this->y, $this->z))->canBeFlowedInto()){
|
||||
$falling = true;
|
||||
}elseif(!$this->getLevel()->getBlock($this->add(0, 1, -1))->isFlowable){
|
||||
}elseif(!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x, $this->y + 1, $this->z - 1))->canBeFlowedInto()){
|
||||
$falling = true;
|
||||
}elseif(!$this->getLevel()->getBlock($this->add(0, 1, 1))->isFlowable){
|
||||
}elseif(!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x, $this->y + 1, $this->z + 1))->canBeFlowedInto()){
|
||||
$falling = true;
|
||||
}elseif(!$this->getLevel()->getBlock($this->add(-1, 1, 0))->isFlowable){
|
||||
}elseif(!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x - 1, $this->y + 1, $this->z))->canBeFlowedInto()){
|
||||
$falling = true;
|
||||
}elseif(!$this->getLevel()->getBlock($this->add(1, 1, 0))->isFlowable){
|
||||
}elseif(!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x + 1, $this->y + 1, $this->z))->canBeFlowedInto()){
|
||||
$falling = true;
|
||||
}
|
||||
|
||||
@ -172,6 +192,10 @@ abstract class Liquid extends Transparent{
|
||||
$this->checkForHarden();
|
||||
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
|
||||
}elseif($type === Level::BLOCK_UPDATE_SCHEDULED){
|
||||
if($this->temporalVector === null){
|
||||
$this->temporalVector = new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
$decay = $this->getFlowDecay($this);
|
||||
$multiplier = $this instanceof Lava ? 2 : 1;
|
||||
|
||||
@ -180,10 +204,10 @@ abstract class Liquid extends Transparent{
|
||||
if($decay > 0){
|
||||
$smallestFlowDecay = -100;
|
||||
$this->adjacentSources = 0;
|
||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(4), $smallestFlowDecay);
|
||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(5), $smallestFlowDecay);
|
||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(2), $smallestFlowDecay);
|
||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->getSide(3), $smallestFlowDecay);
|
||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z - 1)), $smallestFlowDecay);
|
||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z + 1)), $smallestFlowDecay);
|
||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlock($this->temporalVector->setComponents($this->x - 1, $this->y, $this->z)), $smallestFlowDecay);
|
||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlock($this->temporalVector->setComponents($this->x + 1, $this->y, $this->z)), $smallestFlowDecay);
|
||||
|
||||
$k = $smallestFlowDecay + $multiplier;
|
||||
|
||||
@ -191,7 +215,7 @@ abstract class Liquid extends Transparent{
|
||||
$k = -1;
|
||||
}
|
||||
|
||||
if(($topFlowDecay = $this->getFlowDecay($this->getSide(1))) >= 0){
|
||||
if(($topFlowDecay = $this->getFlowDecay($this->level->getBlock($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y + 1, $this->z))))) >= 0){
|
||||
if($topFlowDecay >= 8){
|
||||
$k = $topFlowDecay;
|
||||
}else{
|
||||
@ -200,8 +224,8 @@ abstract class Liquid extends Transparent{
|
||||
}
|
||||
|
||||
if($this->adjacentSources >= 2 and $this instanceof Water){
|
||||
$bottomBlock = $this->getSide(0);
|
||||
if($bottomBlock->isSolid){
|
||||
$bottomBlock = $this->level->getBlock($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y - 1, $this->z)));
|
||||
if($bottomBlock->isSolid()){
|
||||
$k = 0;
|
||||
}elseif($bottomBlock instanceof Water and $bottomBlock->getDamage() === 0){
|
||||
$k = 0;
|
||||
@ -216,7 +240,7 @@ abstract class Liquid extends Transparent{
|
||||
if($k !== $decay){
|
||||
$decay = $k;
|
||||
if($decay < 0){
|
||||
$this->getLevel()->setBlock($this, Block::get(Item::AIR), true);
|
||||
$this->getLevel()->setBlock($this, new Air(), true);
|
||||
}else{
|
||||
$this->getLevel()->setBlock($this, Block::get($this->id, $decay), true);
|
||||
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
|
||||
@ -229,9 +253,9 @@ abstract class Liquid extends Transparent{
|
||||
//$this->updateFlow();
|
||||
}
|
||||
|
||||
$bottomBlock = $this->getSide(0);
|
||||
$bottomBlock = $this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y - 1, $this->z));
|
||||
|
||||
if($bottomBlock->isFlowable or $bottomBlock instanceof Liquid){
|
||||
if($bottomBlock->canBeFlowedInto() or $bottomBlock instanceof Liquid){
|
||||
if($this instanceof Lava and $bottomBlock instanceof Water){
|
||||
$this->getLevel()->setBlock($bottomBlock, Block::get(Item::STONE), true);
|
||||
return;
|
||||
@ -244,7 +268,7 @@ abstract class Liquid extends Transparent{
|
||||
$this->getLevel()->setBlock($bottomBlock, Block::get($this->id, $decay + 8), true);
|
||||
$this->getLevel()->scheduleUpdate($bottomBlock, $this->tickRate());
|
||||
}
|
||||
}elseif($decay >= 0 and ($decay === 0 or !$bottomBlock->isFlowable)){
|
||||
}elseif($decay >= 0 and ($decay === 0 or !$bottomBlock->canBeFlowedInto())){
|
||||
$flags = $this->getOptimalFlowDirections();
|
||||
|
||||
$l = $decay + $multiplier;
|
||||
@ -259,19 +283,19 @@ abstract class Liquid extends Transparent{
|
||||
}
|
||||
|
||||
if($flags[0]){
|
||||
$this->flowIntoBlock($this->getSide(4), $l);
|
||||
$this->flowIntoBlock($this->level->getBlock($this->temporalVector->setComponents($this->x - 1, $this->y, $this->z)), $l);
|
||||
}
|
||||
|
||||
if($flags[1]){
|
||||
$this->flowIntoBlock($this->getSide(5), $l);
|
||||
$this->flowIntoBlock($this->level->getBlock($this->temporalVector->setComponents($this->x + 1, $this->y, $this->z)), $l);
|
||||
}
|
||||
|
||||
if($flags[2]){
|
||||
$this->flowIntoBlock($this->getSide(2), $l);
|
||||
$this->flowIntoBlock($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z - 1)), $l);
|
||||
}
|
||||
|
||||
if($flags[3]){
|
||||
$this->flowIntoBlock($this->getSide(3), $l);
|
||||
$this->flowIntoBlock($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z + 1)), $l);
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,8 +305,8 @@ abstract class Liquid extends Transparent{
|
||||
}
|
||||
|
||||
private function flowIntoBlock(Block $block, $newFlowDecay){
|
||||
if($block->isFlowable){
|
||||
if($block->getID() > 0){
|
||||
if($block->canBeFlowedInto()){
|
||||
if($block->getId() > 0){
|
||||
$this->getLevel()->useBreakOn($block);
|
||||
}
|
||||
|
||||
@ -314,13 +338,13 @@ abstract class Liquid extends Transparent{
|
||||
}elseif($j === 3){
|
||||
++$z;
|
||||
}
|
||||
$blockSide = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||
$blockSide = $this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $z));
|
||||
|
||||
if(!$blockSide->isFlowable and !($blockSide instanceof Liquid)){
|
||||
if(!$blockSide->canBeFlowedInto() and !($blockSide instanceof Liquid)){
|
||||
continue;
|
||||
}elseif($blockSide instanceof Liquid and $blockSide->getDamage() === 0){
|
||||
continue;
|
||||
}elseif($blockSide->getSide(0)->isFlowable){
|
||||
}elseif($this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y - 1, $z))->canBeFlowedInto()){
|
||||
return $accumulatedCost;
|
||||
}
|
||||
|
||||
@ -340,6 +364,10 @@ abstract class Liquid extends Transparent{
|
||||
}
|
||||
|
||||
private function getOptimalFlowDirections(){
|
||||
if($this->temporalVector === null){
|
||||
$this->temporalVector = new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
for($j = 0; $j < 4; ++$j){
|
||||
$this->flowCost[$j] = 1000;
|
||||
|
||||
@ -356,13 +384,13 @@ abstract class Liquid extends Transparent{
|
||||
}elseif($j === 3){
|
||||
++$z;
|
||||
}
|
||||
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||
$block = $this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $z));
|
||||
|
||||
if(!$block->isFlowable and !($block instanceof Liquid)){
|
||||
if(!$block->canBeFlowedInto() and !($block instanceof Liquid)){
|
||||
continue;
|
||||
}elseif($block instanceof Liquid and $block->getDamage() === 0){
|
||||
continue;
|
||||
}elseif($block->getSide(0)->isFlowable){
|
||||
}elseif($this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y - 1, $z))->canBeFlowedInto()){
|
||||
$this->flowCost[$j] = 0;
|
||||
}else{
|
||||
$this->flowCost[$j] = $this->calculateFlowCost($block, 1, $j);
|
||||
|
@ -25,9 +25,23 @@ use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
|
||||
class LitPumpkin extends Solid{
|
||||
public function __construct(){
|
||||
parent::__construct(self::LIT_PUMPKIN, "Jack o'Lantern");
|
||||
$this->hardness = 5;
|
||||
|
||||
protected $id = self::LIT_PUMPKIN;
|
||||
|
||||
public function getLightLevel(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Jack o'Lantern";
|
||||
}
|
||||
|
||||
public function __construct($meta = 0){
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Melon extends Transparent{
|
||||
|
||||
protected $id = self::MELON_BLOCK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::MELON_BLOCK, 0, "Melon Block");
|
||||
$this->hardness = 5;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Melon Block";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -27,13 +27,20 @@ use pocketmine\level\Level;
|
||||
use pocketmine\Server;
|
||||
|
||||
class MelonStem extends Crops{
|
||||
|
||||
protected $id = self::MELON_STEM;
|
||||
|
||||
public function getName(){
|
||||
return "Melon Stem";
|
||||
}
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::MELON_STEM, $meta, "Melon Stem");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){
|
||||
if($this->getSide(0)->isTransparent() === true){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
@ -51,13 +58,13 @@ class MelonStem extends Crops{
|
||||
}else{
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if($b->getID() === self::MELON_BLOCK){
|
||||
if($b->getId() === self::MELON_BLOCK){
|
||||
return Level::BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
$side = $this->getSide(mt_rand(2, 5));
|
||||
$d = $side->getSide(0);
|
||||
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
|
||||
if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Melon()));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->getLevel()->setBlock($side, $ev->getNewState(), true);
|
||||
|
@ -24,29 +24,39 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class MonsterSpawner extends Solid{
|
||||
public function __construct(){
|
||||
parent::__construct(self::MONSTER_SPAWNER, 0, "Monster Spawner");
|
||||
$this->hardness = 25;
|
||||
|
||||
protected $id = self::MONSTER_SPAWNER;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.95;
|
||||
case 4:
|
||||
return 1.25;
|
||||
case 3:
|
||||
return 1.9;
|
||||
case 2:
|
||||
return 0.65;
|
||||
case 1:
|
||||
return 3.75;
|
||||
default:
|
||||
return 25;
|
||||
}
|
||||
}
|
||||
public function getHardness(){
|
||||
return 25;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
return [];
|
||||
}
|
||||
public function getName(){
|
||||
return "Monster Spawner";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
switch($item->isPickaxe()){
|
||||
case 5:
|
||||
return 0.95;
|
||||
case 4:
|
||||
return 1.25;
|
||||
case 3:
|
||||
return 1.9;
|
||||
case 2:
|
||||
return 0.65;
|
||||
case 1:
|
||||
return 3.75;
|
||||
default:
|
||||
return 25;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
return [];
|
||||
}
|
||||
}
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class MossStone extends Solid{
|
||||
|
||||
protected $id = self::MOSS_STONE;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::MOSS_STONE, $meta, "Moss Stone");
|
||||
$this->hardness = 30;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Moss Stone";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -28,9 +28,19 @@ use pocketmine\math\Vector3;
|
||||
use pocketmine\Server;
|
||||
|
||||
class Mycelium extends Solid{
|
||||
|
||||
protected $id = self::MYCELIUM;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::MYCELIUM, 0, "Mycelium");
|
||||
$this->hardness = 2.5;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Mycelium";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2.5;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
@ -46,7 +56,7 @@ class Mycelium extends Solid{
|
||||
$y = mt_rand($this->y - 2, $this->y + 2);
|
||||
$z = mt_rand($this->z - 1, $this->z + 1);
|
||||
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||
if($block->getID() === Block::DIRT){
|
||||
if($block->getId() === Block::DIRT){
|
||||
if($block->getSide(1) instanceof Transparent){
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Mycelium()));
|
||||
if(!$ev->isCancelled()){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class NetherBrick extends Solid{
|
||||
|
||||
protected $id = self::NETHER_BRICKS;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::NETHER_BRICKS, 0, "Nether Bricks");
|
||||
$this->hardness = 30;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Nether Bricks";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -23,8 +23,15 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class NetherBrickStairs extends Stair{
|
||||
|
||||
protected $id = self::NETHER_BRICKS_STAIRS;
|
||||
|
||||
public function getName(){
|
||||
return "Nether Bricks Stairs";
|
||||
}
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::NETHER_BRICKS_STAIRS, $meta, "Nether Bricks Stairs");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
}
|
@ -23,9 +23,19 @@ namespace pocketmine\block;
|
||||
|
||||
|
||||
class NetherReactor extends Solid{
|
||||
|
||||
protected $id = self::NETHER_REACTOR;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::NETHER_REACTOR, $meta, "Nether Reactor");
|
||||
$this->isActivable = true;
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Nether Reactor";
|
||||
}
|
||||
|
||||
public function canBeActivated(){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Netherrack extends Solid{
|
||||
|
||||
protected $id = self::NETHERRACK;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::NETHERRACK, 0, "Netherrack");
|
||||
$this->hardness = 2;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Netherrack";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -24,9 +24,19 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Obsidian extends Solid{
|
||||
|
||||
protected $id = self::OBSIDIAN;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::OBSIDIAN, 0, "Obsidian");
|
||||
$this->hardness = 6000;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Obsidian";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 6000;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
@ -30,18 +30,28 @@ class Planks extends Solid{
|
||||
const ACACIA = 4;
|
||||
const DARK_OAK = 5;
|
||||
|
||||
protected $id = self::WOODEN_PLANKS;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::PLANKS, $meta, "Wood Planks");
|
||||
$names = [
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
self::OAK => "Oak Wood Planks",
|
||||
self::SPRUCE => "Spruce Wood Planks",
|
||||
self::BIRCH => "Birch Wood Planks",
|
||||
self::JUNGLE => "Jungle Wood Planks",
|
||||
self::ACACIA => "Acacia Wood Planks",
|
||||
self::DARK_OAK => "Jungle Wood Planks",
|
||||
"",
|
||||
""
|
||||
];
|
||||
$this->name = $names[$this->meta & 0x07];
|
||||
$this->hardness = 15;
|
||||
return $names[$this->meta & 0x07];
|
||||
}
|
||||
|
||||
}
|
@ -22,8 +22,18 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
class Podzol extends Solid{
|
||||
|
||||
protected $id = self::PODZOL;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::PODZOL, 0, "Podzol");
|
||||
$this->hardness = 2.5;
|
||||
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Podzol";
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2.5;
|
||||
}
|
||||
}
|
@ -25,20 +25,22 @@ use pocketmine\item\Item;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\Player;
|
||||
|
||||
class CyanFlower extends Flowable{
|
||||
public function __construct(){
|
||||
parent::__construct(self::POPPY, 0, "Cyan Flower");
|
||||
$this->hardness = 0;
|
||||
class Poppy extends Flowable{
|
||||
|
||||
protected $id = self::POPPY;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getBoundingBox(){
|
||||
return null;
|
||||
public function getName(){
|
||||
return "Poppy";
|
||||
}
|
||||
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||
if($down->getId() === 2 or $down->getId() === 3 or $down->getId() === 60){
|
||||
$this->getLevel()->setBlock($block, $this, true, true);
|
||||
|
||||
return true;
|
||||
@ -49,7 +51,7 @@ class CyanFlower extends Flowable{
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){
|
||||
if($this->getSide(0)->isTransparent() === true){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
@ -24,8 +24,15 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Potato extends Crops{
|
||||
|
||||
protected $id = self::POTATO_BLOCK;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::POTATO_BLOCK, $meta, "Potato Block");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Potato Block";
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -25,9 +25,19 @@ use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Pumpkin extends Solid{
|
||||
|
||||
protected $id = self::PUMPKIN;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(self::PUMPKIN, "Pumpkin");
|
||||
$this->hardness = 5;
|
||||
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Pumpkin";
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
|
@ -27,13 +27,20 @@ use pocketmine\level\Level;
|
||||
use pocketmine\Server;
|
||||
|
||||
class PumpkinStem extends Crops{
|
||||
|
||||
protected $id = self::PUMPKIN_STEM;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::PUMPKIN_STEM, $meta, "Pumpkin Stem");
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Pumpkin Stem";
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){
|
||||
if($this->getSide(0)->isTransparent() === true){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
@ -51,13 +58,13 @@ class PumpkinStem extends Crops{
|
||||
}else{
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if($b->getID() === self::PUMPKIN){
|
||||
if($b->getId() === self::PUMPKIN){
|
||||
return Level::BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
$side = $this->getSide(mt_rand(2, 5));
|
||||
$d = $side->getSide(0);
|
||||
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
|
||||
if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Pumpkin()));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->getLevel()->setBlock($side, $ev->getNewState(), true);
|
||||
|
@ -24,15 +24,21 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
|
||||
class Quartz extends Solid{
|
||||
|
||||
protected $id = self::QUARTZ_BLOCK;
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(self::QUARTZ_BLOCK, $meta, "Quartz Block");
|
||||
$names = [
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
0 => "Quartz Block",
|
||||
1 => "Chiseled Quartz Block",
|
||||
2 => "Quartz Pillar",
|
||||
3 => "Quartz Pillar",
|
||||
];
|
||||
$this->name = $names[$this->meta & 0x03];
|
||||
return $names[$this->meta & 0x03];
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user