mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
Added block updates, correct block placing
This commit is contained in:
parent
a4630372fa
commit
7cd29f0fcf
@ -29,202 +29,7 @@ use pocketmine\level\Position;
|
||||
class BlockAPI{
|
||||
private $server;
|
||||
private $scheduledUpdates = array();
|
||||
public static $creative = array(
|
||||
//Building
|
||||
[Item::STONE, 0],
|
||||
[Item::COBBLESTONE, 0],
|
||||
[Item::STONE_BRICKS, 0],
|
||||
[Item::STONE_BRICKS, 1],
|
||||
[Item::STONE_BRICKS, 2],
|
||||
[Item::MOSS_STONE, 0],
|
||||
[Item::WOODEN_PLANKS, 0],
|
||||
[Item::WOODEN_PLANKS, 1],
|
||||
[Item::WOODEN_PLANKS, 2],
|
||||
[Item::WOODEN_PLANKS, 3],
|
||||
[Item::BRICKS, 0],
|
||||
|
||||
[Item::DIRT, 0],
|
||||
[Item::GRASS, 0],
|
||||
[Item::CLAY_BLOCK, 0],
|
||||
[Item::SANDSTONE, 0],
|
||||
[Item::SANDSTONE, 1],
|
||||
[Item::SANDSTONE, 2],
|
||||
[Item::SAND, 0],
|
||||
[Item::GRAVEL, 0],
|
||||
[Item::TRUNK, 0],
|
||||
[Item::TRUNK, 1],
|
||||
[Item::TRUNK, 2],
|
||||
[Item::TRUNK, 3],
|
||||
[Item::NETHER_BRICKS, 0],
|
||||
[Item::NETHERRACK, 0],
|
||||
[Item::BEDROCK, 0],
|
||||
[Item::COBBLESTONE_STAIRS, 0],
|
||||
[Item::OAK_WOODEN_STAIRS, 0],
|
||||
[Item::SPRUCE_WOODEN_STAIRS, 0],
|
||||
[Item::BIRCH_WOODEN_STAIRS, 0],
|
||||
[Item::JUNGLE_WOODEN_STAIRS, 0],
|
||||
[Item::BRICK_STAIRS, 0],
|
||||
[Item::SANDSTONE_STAIRS, 0],
|
||||
[Item::STONE_BRICK_STAIRS, 0],
|
||||
[Item::NETHER_BRICKS_STAIRS, 0],
|
||||
[Item::QUARTZ_STAIRS, 0],
|
||||
[Item::SLAB, 0],
|
||||
[Item::SLAB, 1],
|
||||
[Item::WOODEN_SLAB, 0],
|
||||
[Item::WOODEN_SLAB, 1],
|
||||
[Item::WOODEN_SLAB, 2],
|
||||
[Item::WOODEN_SLAB, 3],
|
||||
[Item::SLAB, 3],
|
||||
[Item::SLAB, 4],
|
||||
[Item::SLAB, 5],
|
||||
[Item::SLAB, 6],
|
||||
[Item::QUARTZ_BLOCK, 0],
|
||||
[Item::QUARTZ_BLOCK, 1],
|
||||
[Item::QUARTZ_BLOCK, 2],
|
||||
[Item::COAL_ORE, 0],
|
||||
[Item::IRON_ORE, 0],
|
||||
[Item::GOLD_ORE, 0],
|
||||
[Item::DIAMOND_ORE, 0],
|
||||
[Item::LAPIS_ORE, 0],
|
||||
[Item::REDSTONE_ORE, 0],
|
||||
[Item::OBSIDIAN, 0],
|
||||
[Item::ICE, 0],
|
||||
[Item::SNOW_BLOCK, 0],
|
||||
|
||||
//Decoration
|
||||
[Item::COBBLESTONE_WALL, 0],
|
||||
[Item::COBBLESTONE_WALL, 1],
|
||||
[Item::GOLD_BLOCK, 0],
|
||||
[Item::IRON_BLOCK, 0],
|
||||
[Item::DIAMOND_BLOCK, 0],
|
||||
[Item::LAPIS_BLOCK, 0],
|
||||
[Item::COAL_BLOCK, 0],
|
||||
[Item::SNOW_LAYER, 0],
|
||||
[Item::GLASS, 0],
|
||||
[Item::GLOWSTONE_BLOCK, 0],
|
||||
[Item::NETHER_REACTOR, 0],
|
||||
[Item::WOOL, 0],
|
||||
[Item::WOOL, 7],
|
||||
[Item::WOOL, 6],
|
||||
[Item::WOOL, 5],
|
||||
[Item::WOOL, 4],
|
||||
[Item::WOOL, 3],
|
||||
[Item::WOOL, 2],
|
||||
[Item::WOOL, 1],
|
||||
[Item::WOOL, 15],
|
||||
[Item::WOOL, 14],
|
||||
[Item::WOOL, 13],
|
||||
[Item::WOOL, 12],
|
||||
[Item::WOOL, 11],
|
||||
[Item::WOOL, 10],
|
||||
[Item::WOOL, 9],
|
||||
[Item::WOOL, 8],
|
||||
[Item::LADDER, 0],
|
||||
[Item::SPONGE, 0],
|
||||
[Item::GLASS_PANE, 0],
|
||||
[Item::WOODEN_DOOR, 0],
|
||||
[Item::TRAPDOOR, 0],
|
||||
[Item::FENCE, 0],
|
||||
[Item::FENCE_GATE, 0],
|
||||
[Item::IRON_BARS, 0],
|
||||
[Item::BED, 0],
|
||||
[Item::BOOKSHELF, 0],
|
||||
[Item::PAINTING, 0],
|
||||
[Item::WORKBENCH, 0],
|
||||
[Item::STONECUTTER, 0],
|
||||
[Item::CHEST, 0],
|
||||
[Item::FURNACE, 0],
|
||||
[Item::DANDELION, 0],
|
||||
[Item::CYAN_FLOWER, 0],
|
||||
[Item::BROWN_MUSHROOM, 0],
|
||||
[Item::RED_MUSHROOM, 0],
|
||||
[Item::CACTUS, 0],
|
||||
[Item::MELON_BLOCK, 0],
|
||||
[Item::PUMPKIN, 0],
|
||||
[Item::LIT_PUMPKIN, 0],
|
||||
[Item::COBWEB, 0],
|
||||
[Item::HAY_BALE, 0],
|
||||
[Item::TALL_GRASS, 1],
|
||||
[Item::TALL_GRASS, 2],
|
||||
[Item::DEAD_BUSH, 0],
|
||||
[Item::SAPLING, 0],
|
||||
[Item::SAPLING, 1],
|
||||
[Item::SAPLING, 2],
|
||||
[Item::SAPLING, 3],
|
||||
[Item::LEAVES, 0],
|
||||
[Item::LEAVES, 1],
|
||||
[Item::LEAVES, 2],
|
||||
[Item::LEAVES, 3],
|
||||
[Item::CAKE, 0],
|
||||
[Item::SIGN, 0],
|
||||
[Item::CARPET, 0],
|
||||
[Item::CARPET, 7],
|
||||
[Item::CARPET, 6],
|
||||
[Item::CARPET, 5],
|
||||
[Item::CARPET, 4],
|
||||
[Item::CARPET, 3],
|
||||
[Item::CARPET, 2],
|
||||
[Item::CARPET, 1],
|
||||
[Item::CARPET, 15],
|
||||
[Item::CARPET, 14],
|
||||
[Item::CARPET, 13],
|
||||
[Item::CARPET, 12],
|
||||
[Item::CARPET, 11],
|
||||
[Item::CARPET, 10],
|
||||
[Item::CARPET, 9],
|
||||
[Item::CARPET, 8],
|
||||
|
||||
//Tools
|
||||
//[Item::RAILS, 0],
|
||||
//[Item::POWERED_RAILS, 0],
|
||||
[Item::TORCH, 0],
|
||||
[Item::BUCKET, 0],
|
||||
[Item::BUCKET, 8],
|
||||
[Item::BUCKET, 10],
|
||||
[Item::TNT, 0],
|
||||
[Item::IRON_HOE, 0],
|
||||
[Item::IRON_SWORD, 0],
|
||||
[Item::BOW, 0],
|
||||
[Item::SHEARS, 0],
|
||||
[Item::FLINT_AND_STEEL, 0],
|
||||
[Item::CLOCK, 0],
|
||||
[Item::COMPASS, 0],
|
||||
[Item::MINECART, 0],
|
||||
[Item::SPAWN_EGG, 10], //Chicken
|
||||
[Item::SPAWN_EGG, 11], //Cow
|
||||
[Item::SPAWN_EGG, 12], //Pig
|
||||
[Item::SPAWN_EGG, 13], //Sheep
|
||||
//TODO: Replace with Entity constants
|
||||
|
||||
|
||||
//Seeds
|
||||
[Item::SUGARCANE, 0],
|
||||
[Item::WHEAT, 0],
|
||||
[Item::SEEDS, 0],
|
||||
[Item::MELON_SEEDS, 0],
|
||||
[Item::PUMPKIN_SEEDS, 0],
|
||||
[Item::CARROT, 0],
|
||||
[Item::POTATO, 0],
|
||||
[Item::BEETROOT_SEEDS, 0],
|
||||
[Item::EGG, 0],
|
||||
[Item::DYE, 0],
|
||||
[Item::DYE, 7],
|
||||
[Item::DYE, 6],
|
||||
[Item::DYE, 5],
|
||||
[Item::DYE, 4],
|
||||
[Item::DYE, 3],
|
||||
[Item::DYE, 2],
|
||||
[Item::DYE, 1],
|
||||
[Item::DYE, 15],
|
||||
[Item::DYE, 14],
|
||||
[Item::DYE, 13],
|
||||
[Item::DYE, 12],
|
||||
[Item::DYE, 11],
|
||||
[Item::DYE, 10],
|
||||
[Item::DYE, 9],
|
||||
[Item::DYE, 8],
|
||||
|
||||
);
|
||||
|
||||
function __construct(){
|
||||
$this->server = Server::getInstance();
|
||||
|
@ -1,66 +0,0 @@
|
||||
<?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;
|
||||
|
||||
use pocketmine\level\Level;
|
||||
|
||||
class LevelAPI{
|
||||
private $server;
|
||||
|
||||
public function __construct(){
|
||||
$this->server = Server::getInstance();
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->api->console->register("save-all", "", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("save-on", "", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("save-off", "", array($this, "commandHandler"));
|
||||
}
|
||||
|
||||
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||
$output = "";
|
||||
switch($cmd){
|
||||
case "save-all":
|
||||
$save = $this->server->saveEnabled;
|
||||
$this->server->saveEnabled = true;
|
||||
Level::saveAll();
|
||||
$this->server->saveEnabled = $save;
|
||||
break;
|
||||
case "save-on":
|
||||
$this->server->saveEnabled = true;
|
||||
break;
|
||||
case "save-off":
|
||||
$this->server->saveEnabled = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
Level::saveAll();
|
||||
foreach(Level::getAll() as $level){
|
||||
$level->unload(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
|
||||
namespace pocketmine;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\entity\Human;
|
||||
use pocketmine\Event;
|
||||
@ -1282,14 +1283,17 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
$this->server->getPluginManager()->callEvent($ev = new event\player\PlayerPreLoginEvent($this, "Plugin reason"));
|
||||
if($ev->isCancelled()){
|
||||
$this->close($ev->getKickMessage(), "Plugin reason");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!$this->server->isWhitelisted(strtolower($this->getName()))){
|
||||
$this->close($this->username . " has left the game", "Server is white-listed");
|
||||
|
||||
return;
|
||||
}elseif($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress())){
|
||||
$this->close($this->username . " has left the game", "You are banned");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1475,7 +1479,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
|
||||
if(($this->gamemode & 0x01) === 1){ //Creative mode match
|
||||
$packet->slot = false;
|
||||
foreach(BlockAPI::$creative as $i => $d){
|
||||
foreach(Block::$creative as $i => $d){
|
||||
if($d[0] === $packet->item and $d[1] === $packet->meta){
|
||||
$packet->slot = $i;
|
||||
$item = Item::get($d[0], $d[1], 1);
|
||||
@ -1486,7 +1490,6 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
$item = $this->getSlot($packet->slot);
|
||||
}
|
||||
|
||||
|
||||
if($packet->slot === false){
|
||||
$this->sendInventorySlot($packet->slot);
|
||||
}else{
|
||||
@ -1502,6 +1505,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
array_unshift($this->hotbar, $this->slot);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1548,19 +1552,19 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
|
||||
if($blockVector->distance($this) > 10){
|
||||
|
||||
}elseif(($this->gamemode & 0x01) === 1 and isset(BlockAPI::$creative[$this->slot]) and $packet->item === BlockAPI::$creative[$this->slot][0] and $packet->meta === BlockAPI::$creative[$this->slot][1]){
|
||||
$item = Item::get(BlockAPI::$creative[$this->slot][0], BlockAPI::$creative[$this->slot][1], 1);
|
||||
}elseif(($this->gamemode & 0x01) === 1){
|
||||
$item = Item::get(Block::$creative[$this->getCurrentEquipment()][0], Block::$creative[$this->getCurrentEquipment()][1], 1);
|
||||
if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){
|
||||
break;
|
||||
}
|
||||
}elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)){
|
||||
$this->sendInventorySlot($this->slot);
|
||||
}elseif($this->getSlot($this->getCurrentEquipment())->getID() !== $packet->item or ($this->getSlot($this->getCurrentEquipment())->isTool() === false and $this->getSlot($this->getCurrentEquipment())->getMetadata() !== $packet->meta)){
|
||||
$this->sendInventorySlot($this->getCurrentEquipment());
|
||||
}else{
|
||||
$item = clone $this->getSlot($this->slot);
|
||||
$item = clone $this->getSlot($this->getCurrentEquipment());
|
||||
//TODO: Implement adventure mode checks
|
||||
if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){
|
||||
$this->setSlot($this->slot, $item);
|
||||
$this->sendInventorySlot($this->slot);
|
||||
$this->setSlot($this->getCurrentEquipment(), $item);
|
||||
$this->sendInventorySlot($this->getCurrentEquipment());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1601,7 +1605,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
switch($packet->action){
|
||||
case 5: //Shot arrow
|
||||
if($this->entity->inAction === true){
|
||||
if($this->getSlot($this->slot)->getID() === BOW){
|
||||
if($this->getSlot($this->getCurrentEquipment())->getID() === BOW){
|
||||
if($this->startAction !== false){
|
||||
$time = microtime(true) - $this->startAction;
|
||||
$d = array(
|
||||
@ -1677,15 +1681,15 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
|
||||
|
||||
if(($this->gamemode & 0x01) === 1){
|
||||
$item = Item::get(BlockAPI::$creative[$this->slot][0], BlockAPI::$creative[$this->slot][1], 1);
|
||||
$item = Item::get(Block::$creative[$this->getCurrentEquipment()][0], Block::$creative[$this->getCurrentEquipment()][1], 1);
|
||||
}else{
|
||||
$item = clone $this->getSlot($this->slot);
|
||||
$item = clone $this->getSlot($this->getCurrentEquipment());
|
||||
}
|
||||
|
||||
if(($drops = $this->level->useBreakOn($vector, $item)) !== true){
|
||||
if(($this->gamemode & 0x01) === 0){
|
||||
//TODO: drop items
|
||||
$this->setSlot($this->slot, $item);
|
||||
$this->setSlot($this->getCurrentEquipment(), $item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1764,7 +1768,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
if($target instanceof Player and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($target->player->gamemode & 0x01) === 0x01)){
|
||||
break;
|
||||
}elseif($this->server->handle("player.interact", $data) !== false){
|
||||
$slot = $this->getSlot($this->slot);
|
||||
$slot = $this->getSlot($this->getCurrentEquipment());
|
||||
switch($slot->getID()){
|
||||
case WOODEN_SWORD:
|
||||
case GOLD_SWORD:
|
||||
@ -1828,7 +1832,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
$target->harm($damage, $this->id);
|
||||
if($slot->isTool() === true and ($this->gamemode & 0x01) === 0){
|
||||
if($slot->useOn($target) and $slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$this->setSlot($this->slot, new Item(AIR, 0, 0));
|
||||
$this->setSlot($this->getCurrentEquipment(), new Item(AIR, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1896,7 +1900,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
//Item::COOKED_FISH => 5,
|
||||
//Item::RAW_FISH => 2,
|
||||
);
|
||||
$slot = $this->getSlot($this->slot);
|
||||
$slot = $this->getSlot($this->getCurrentEquipment());
|
||||
if($this->entity->getHealth() < 20 and isset($items[$slot->getID()])){
|
||||
|
||||
$pk = new EntityEventPacket;
|
||||
@ -1907,7 +1911,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
$this->entity->heal($items[$slot->getID()], "eating");
|
||||
//--$slot->count;
|
||||
if($slot->getCount() <= 0){
|
||||
$this->setSlot($this->slot, Item::get(AIR, 0, 0));
|
||||
$this->setSlot($this->getCurrentEquipment(), Item::get(AIR, 0, 0));
|
||||
}
|
||||
if($slot->getID() === Item::MUSHROOM_STEW or $slot->getID() === Item::BEETROOT_SOUP){
|
||||
$this->addItem(Item::get(BOWL, 0, 1));
|
||||
@ -1921,7 +1925,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
break;
|
||||
}
|
||||
$packet->eid = $this->id;
|
||||
$packet->item = $this->getSlot($this->slot);
|
||||
$packet->item = $this->getSlot($this->getCurrentEquipment());
|
||||
$this->craftingItems = array();
|
||||
$this->toCraft = array();
|
||||
$data = array();
|
||||
@ -1931,7 +1935,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
||||
$data["player"] = $this;
|
||||
if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){
|
||||
$this->server->api->entity->drop(new Position($this->entity->x - 0.5, $this->entity->y, $this->entity->z - 0.5, $this->level), $packet->item);
|
||||
$this->setSlot($this->slot, Item::get(AIR, 0, 0), false);
|
||||
$this->setSlot($this->getCurrentEquipment(), Item::get(AIR, 0, 0), false);
|
||||
}
|
||||
if($this->entity->inAction === true){
|
||||
$this->entity->inAction = false;
|
||||
|
@ -1523,7 +1523,7 @@ class Server{
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function checkTickUpdates(){
|
||||
private function checkTickUpdates($currentTick){
|
||||
//Update entities that need update
|
||||
if(count(Entity::$needUpdate) > 0){
|
||||
foreach(Entity::$needUpdate as $id => $entity){
|
||||
@ -1546,7 +1546,7 @@ class Server{
|
||||
|
||||
//Do level ticks
|
||||
foreach($this->getLevels() as $level){
|
||||
$level->doTick();
|
||||
$level->doTick($currentTick);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1606,15 +1606,15 @@ class Server{
|
||||
|
||||
$this->checkConsole();
|
||||
$this->scheduler->mainThreadHeartbeat($this->tickCounter);
|
||||
if(($this->tickCounter & 0b1) === 0){
|
||||
$this->checkTickUpdates();
|
||||
if(($this->tickCounter & 0b1111) === 0){
|
||||
$this->titleTick();
|
||||
if(isset($this->queryHandler) and ($this->tickCounter & 0b111111111) === 0){
|
||||
$this->queryHandler->regenerateInfo();
|
||||
}
|
||||
$this->checkTickUpdates($this->tickCounter);
|
||||
|
||||
if(($this->tickCounter & 0b1111) === 0){
|
||||
$this->titleTick();
|
||||
if(isset($this->queryHandler) and ($this->tickCounter & 0b111111111) === 0){
|
||||
$this->queryHandler->regenerateInfo();
|
||||
}
|
||||
}
|
||||
|
||||
$this->tickScheduler->doTick();
|
||||
$this->inTick = false;
|
||||
|
||||
|
@ -204,7 +204,204 @@ abstract class Block extends Position{
|
||||
const GLOWING_OBSIDIAN = 246;
|
||||
const NETHER_REACTOR = 247;
|
||||
|
||||
public static $creative = array(
|
||||
//Building
|
||||
[Item::STONE, 0],
|
||||
[Item::COBBLESTONE, 0],
|
||||
[Item::STONE_BRICKS, 0],
|
||||
[Item::STONE_BRICKS, 1],
|
||||
[Item::STONE_BRICKS, 2],
|
||||
[Item::MOSS_STONE, 0],
|
||||
[Item::WOODEN_PLANKS, 0],
|
||||
[Item::WOODEN_PLANKS, 1],
|
||||
[Item::WOODEN_PLANKS, 2],
|
||||
[Item::WOODEN_PLANKS, 3],
|
||||
[Item::BRICKS, 0],
|
||||
|
||||
[Item::DIRT, 0],
|
||||
[Item::GRASS, 0],
|
||||
[Item::CLAY_BLOCK, 0],
|
||||
[Item::SANDSTONE, 0],
|
||||
[Item::SANDSTONE, 1],
|
||||
[Item::SANDSTONE, 2],
|
||||
[Item::SAND, 0],
|
||||
[Item::GRAVEL, 0],
|
||||
[Item::TRUNK, 0],
|
||||
[Item::TRUNK, 1],
|
||||
[Item::TRUNK, 2],
|
||||
[Item::TRUNK, 3],
|
||||
[Item::NETHER_BRICKS, 0],
|
||||
[Item::NETHERRACK, 0],
|
||||
[Item::BEDROCK, 0],
|
||||
[Item::COBBLESTONE_STAIRS, 0],
|
||||
[Item::OAK_WOODEN_STAIRS, 0],
|
||||
[Item::SPRUCE_WOODEN_STAIRS, 0],
|
||||
[Item::BIRCH_WOODEN_STAIRS, 0],
|
||||
[Item::JUNGLE_WOODEN_STAIRS, 0],
|
||||
[Item::BRICK_STAIRS, 0],
|
||||
[Item::SANDSTONE_STAIRS, 0],
|
||||
[Item::STONE_BRICK_STAIRS, 0],
|
||||
[Item::NETHER_BRICKS_STAIRS, 0],
|
||||
[Item::QUARTZ_STAIRS, 0],
|
||||
[Item::SLAB, 0],
|
||||
[Item::SLAB, 1],
|
||||
[Item::WOODEN_SLAB, 0],
|
||||
[Item::WOODEN_SLAB, 1],
|
||||
[Item::WOODEN_SLAB, 2],
|
||||
[Item::WOODEN_SLAB, 3],
|
||||
[Item::SLAB, 3],
|
||||
[Item::SLAB, 4],
|
||||
[Item::SLAB, 5],
|
||||
[Item::SLAB, 6],
|
||||
[Item::QUARTZ_BLOCK, 0],
|
||||
[Item::QUARTZ_BLOCK, 1],
|
||||
[Item::QUARTZ_BLOCK, 2],
|
||||
[Item::COAL_ORE, 0],
|
||||
[Item::IRON_ORE, 0],
|
||||
[Item::GOLD_ORE, 0],
|
||||
[Item::DIAMOND_ORE, 0],
|
||||
[Item::LAPIS_ORE, 0],
|
||||
[Item::REDSTONE_ORE, 0],
|
||||
[Item::OBSIDIAN, 0],
|
||||
[Item::ICE, 0],
|
||||
[Item::SNOW_BLOCK, 0],
|
||||
|
||||
//Decoration
|
||||
[Item::COBBLESTONE_WALL, 0],
|
||||
[Item::COBBLESTONE_WALL, 1],
|
||||
[Item::GOLD_BLOCK, 0],
|
||||
[Item::IRON_BLOCK, 0],
|
||||
[Item::DIAMOND_BLOCK, 0],
|
||||
[Item::LAPIS_BLOCK, 0],
|
||||
[Item::COAL_BLOCK, 0],
|
||||
[Item::SNOW_LAYER, 0],
|
||||
[Item::GLASS, 0],
|
||||
[Item::GLOWSTONE_BLOCK, 0],
|
||||
[Item::NETHER_REACTOR, 0],
|
||||
[Item::WOOL, 0],
|
||||
[Item::WOOL, 7],
|
||||
[Item::WOOL, 6],
|
||||
[Item::WOOL, 5],
|
||||
[Item::WOOL, 4],
|
||||
[Item::WOOL, 3],
|
||||
[Item::WOOL, 2],
|
||||
[Item::WOOL, 1],
|
||||
[Item::WOOL, 15],
|
||||
[Item::WOOL, 14],
|
||||
[Item::WOOL, 13],
|
||||
[Item::WOOL, 12],
|
||||
[Item::WOOL, 11],
|
||||
[Item::WOOL, 10],
|
||||
[Item::WOOL, 9],
|
||||
[Item::WOOL, 8],
|
||||
[Item::LADDER, 0],
|
||||
[Item::SPONGE, 0],
|
||||
[Item::GLASS_PANE, 0],
|
||||
[Item::WOODEN_DOOR, 0],
|
||||
[Item::TRAPDOOR, 0],
|
||||
[Item::FENCE, 0],
|
||||
[Item::FENCE_GATE, 0],
|
||||
[Item::IRON_BARS, 0],
|
||||
[Item::BED, 0],
|
||||
[Item::BOOKSHELF, 0],
|
||||
[Item::PAINTING, 0],
|
||||
[Item::WORKBENCH, 0],
|
||||
[Item::STONECUTTER, 0],
|
||||
[Item::CHEST, 0],
|
||||
[Item::FURNACE, 0],
|
||||
[Item::DANDELION, 0],
|
||||
[Item::CYAN_FLOWER, 0],
|
||||
[Item::BROWN_MUSHROOM, 0],
|
||||
[Item::RED_MUSHROOM, 0],
|
||||
[Item::CACTUS, 0],
|
||||
[Item::MELON_BLOCK, 0],
|
||||
[Item::PUMPKIN, 0],
|
||||
[Item::LIT_PUMPKIN, 0],
|
||||
[Item::COBWEB, 0],
|
||||
[Item::HAY_BALE, 0],
|
||||
[Item::TALL_GRASS, 1],
|
||||
[Item::TALL_GRASS, 2],
|
||||
[Item::DEAD_BUSH, 0],
|
||||
[Item::SAPLING, 0],
|
||||
[Item::SAPLING, 1],
|
||||
[Item::SAPLING, 2],
|
||||
[Item::SAPLING, 3],
|
||||
[Item::LEAVES, 0],
|
||||
[Item::LEAVES, 1],
|
||||
[Item::LEAVES, 2],
|
||||
[Item::LEAVES, 3],
|
||||
[Item::CAKE, 0],
|
||||
[Item::SIGN, 0],
|
||||
[Item::CARPET, 0],
|
||||
[Item::CARPET, 7],
|
||||
[Item::CARPET, 6],
|
||||
[Item::CARPET, 5],
|
||||
[Item::CARPET, 4],
|
||||
[Item::CARPET, 3],
|
||||
[Item::CARPET, 2],
|
||||
[Item::CARPET, 1],
|
||||
[Item::CARPET, 15],
|
||||
[Item::CARPET, 14],
|
||||
[Item::CARPET, 13],
|
||||
[Item::CARPET, 12],
|
||||
[Item::CARPET, 11],
|
||||
[Item::CARPET, 10],
|
||||
[Item::CARPET, 9],
|
||||
[Item::CARPET, 8],
|
||||
|
||||
//Tools
|
||||
//[Item::RAILS, 0],
|
||||
//[Item::POWERED_RAILS, 0],
|
||||
[Item::TORCH, 0],
|
||||
[Item::BUCKET, 0],
|
||||
[Item::BUCKET, 8],
|
||||
[Item::BUCKET, 10],
|
||||
[Item::TNT, 0],
|
||||
[Item::IRON_HOE, 0],
|
||||
[Item::IRON_SWORD, 0],
|
||||
[Item::BOW, 0],
|
||||
[Item::SHEARS, 0],
|
||||
[Item::FLINT_AND_STEEL, 0],
|
||||
[Item::CLOCK, 0],
|
||||
[Item::COMPASS, 0],
|
||||
[Item::MINECART, 0],
|
||||
[Item::SPAWN_EGG, 10], //Chicken
|
||||
[Item::SPAWN_EGG, 11], //Cow
|
||||
[Item::SPAWN_EGG, 12], //Pig
|
||||
[Item::SPAWN_EGG, 13], //Sheep
|
||||
//TODO: Replace with Entity constants
|
||||
|
||||
|
||||
//Seeds
|
||||
[Item::SUGARCANE, 0],
|
||||
[Item::WHEAT, 0],
|
||||
[Item::SEEDS, 0],
|
||||
[Item::MELON_SEEDS, 0],
|
||||
[Item::PUMPKIN_SEEDS, 0],
|
||||
[Item::CARROT, 0],
|
||||
[Item::POTATO, 0],
|
||||
[Item::BEETROOT_SEEDS, 0],
|
||||
[Item::EGG, 0],
|
||||
[Item::DYE, 0],
|
||||
[Item::DYE, 7],
|
||||
[Item::DYE, 6],
|
||||
[Item::DYE, 5],
|
||||
[Item::DYE, 4],
|
||||
[Item::DYE, 3],
|
||||
[Item::DYE, 2],
|
||||
[Item::DYE, 1],
|
||||
[Item::DYE, 15],
|
||||
[Item::DYE, 14],
|
||||
[Item::DYE, 13],
|
||||
[Item::DYE, 12],
|
||||
[Item::DYE, 11],
|
||||
[Item::DYE, 10],
|
||||
[Item::DYE, 9],
|
||||
[Item::DYE, 8],
|
||||
|
||||
);
|
||||
|
||||
/** @var Block[] */
|
||||
public static $list = array();
|
||||
protected $id;
|
||||
protected $meta;
|
||||
@ -218,7 +415,6 @@ abstract class Block extends Position{
|
||||
public $isTransparent = false;
|
||||
public $isReplaceable = false;
|
||||
public $isPlaceable = true;
|
||||
public $level = false;
|
||||
public $hasPhysics = false;
|
||||
public $isLiquid = false;
|
||||
public $isFullBlock = true;
|
||||
|
@ -22,9 +22,7 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
|
||||
class Fallable extends Solid{
|
||||
|
||||
@ -35,7 +33,6 @@ class Fallable extends Solid{
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||
Server::getInstance()->api->block->blockUpdate(clone $this, Level::BLOCK_UPDATE_NORMAL);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
@ -60,11 +60,11 @@ class Generic extends Block{
|
||||
"Tile" => $this->id,
|
||||
);
|
||||
$server = Server::getInstance();
|
||||
$this->level->setBlock($this, new Air(), false, false, true);
|
||||
/*$this->level->setBlock($this, new Air(), false, false, true);
|
||||
//TODO
|
||||
//$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
|
||||
//$e->spawnToAll();
|
||||
$server->api->block->blockUpdateAround(clone $this, Level::BLOCK_UPDATE_NORMAL, 1);
|
||||
$server->api->block->blockUpdateAround(clone $this, Level::BLOCK_UPDATE_NORMAL, 1);*/
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -23,9 +23,7 @@ namespace pocketmine\command\defaults;
|
||||
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\TextFormat;
|
||||
|
||||
class SaveCommand extends VanillaCommand{
|
||||
|
||||
|
@ -23,9 +23,7 @@ namespace pocketmine\command\defaults;
|
||||
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\TextFormat;
|
||||
|
||||
class SaveOffCommand extends VanillaCommand{
|
||||
|
||||
|
@ -23,9 +23,7 @@ namespace pocketmine\command\defaults;
|
||||
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\TextFormat;
|
||||
|
||||
class SaveOnCommand extends VanillaCommand{
|
||||
|
||||
|
@ -23,7 +23,6 @@ namespace pocketmine\command\defaults;
|
||||
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\TextFormat;
|
||||
|
||||
@ -51,14 +50,17 @@ class WhitelistCommand extends VanillaCommand{
|
||||
case "reload":
|
||||
Server::getInstance()->reloadWhitelist();
|
||||
Command::broadcastCommandMessage($sender, "Reloaded white-list from file");
|
||||
|
||||
return true;
|
||||
case "on":
|
||||
Server::getInstance()->setConfigBool("white-list", true);
|
||||
Command::broadcastCommandMessage($sender, "Turned on white-listing");
|
||||
|
||||
return true;
|
||||
case "off":
|
||||
Server::getInstance()->setConfigBool("white-list", false);
|
||||
Command::broadcastCommandMessage($sender, "Turned off white-listing");
|
||||
|
||||
return true;
|
||||
case "list":
|
||||
$result = "";
|
||||
@ -66,6 +68,7 @@ class WhitelistCommand extends VanillaCommand{
|
||||
$result .= $player . ", ";
|
||||
}
|
||||
$sender->sendMessage("White-listed players: " . substr($result, 0, -2));
|
||||
|
||||
return true;
|
||||
}
|
||||
}elseif(count($args) === 2){
|
||||
@ -75,24 +78,29 @@ class WhitelistCommand extends VanillaCommand{
|
||||
switch(strtolower($args[0])){
|
||||
case "add":
|
||||
Server::getInstance()->getOfflinePlayer($args[1])->setWhitelisted(true);
|
||||
Command::broadcastCommandMessage($sender, "Added ". $args[1] . " to white-list");
|
||||
Command::broadcastCommandMessage($sender, "Added " . $args[1] . " to white-list");
|
||||
|
||||
return true;
|
||||
case "remove":
|
||||
Server::getInstance()->getOfflinePlayer($args[1])->setWhitelisted(false);
|
||||
Command::broadcastCommandMessage($sender, "Removed ". $args[1] . " from white-list");
|
||||
Command::broadcastCommandMessage($sender, "Removed " . $args[1] . " from white-list");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$sender->sendMessage(TextFormat::RED . "Usage:\n" . $this->usageMessage);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function badPerm(CommandSender $sender, $perm){
|
||||
if(!$sender->hasPermission("pocketmine.command.whitelist.$perm")){
|
||||
$sender->sendMessage(TextFormat::RED . "You do not have permission to perform this action.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -34,12 +34,12 @@ use pocketmine\level\Position;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Vector3 as Vector3;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\Network;
|
||||
use pocketmine\network\protocol\MoveEntityPacket_PosRot;
|
||||
use pocketmine\network\protocol\MovePlayerPacket;
|
||||
use pocketmine\network\protocol\RemoveEntityPacket;
|
||||
use pocketmine\network\protocol\SetEntityMotionPacket;
|
||||
use pocketmine\network\protocol\SetTimePacket;
|
||||
use pocketmine\Network;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\pmf\LevelFormat;
|
||||
use pocketmine\Server;
|
||||
|
@ -29,13 +29,13 @@ use pocketmine\nbt\tag\Byte;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Enum;
|
||||
use pocketmine\nbt\tag\Short;
|
||||
use pocketmine\Network;
|
||||
use pocketmine\network\protocol\AddPlayerPacket;
|
||||
use pocketmine\network\protocol\ContainerSetContentPacket;
|
||||
use pocketmine\network\protocol\PlayerArmorEquipmentPacket;
|
||||
use pocketmine\network\protocol\PlayerEquipmentPacket;
|
||||
use pocketmine\network\protocol\RemovePlayerPacket;
|
||||
use pocketmine\network\protocol\SetEntityMotionPacket;
|
||||
use pocketmine\Network;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
|
||||
@ -173,20 +173,36 @@ class Human extends Creature implements ProjectileSource, InventorySource{
|
||||
$this->hotbar[$equipmentSlot] = $inventorySlot;
|
||||
if($equipmentSlot === $this->slot){
|
||||
foreach($this->hasSpawned as $p){
|
||||
$this->sendEquipmentSlot($p);
|
||||
$this->sendCurrentEquipmentSlot($p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getEquipmentSlot($equipmentSlot){
|
||||
if(isset($this->hotbar[$equipmentSlot])){
|
||||
return $this->hotbar[$equipmentSlot];
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function setCurrentEquipmentSlot($slot){
|
||||
if(isset($this->hotbar[$slot])){
|
||||
$this->slot = (int) $slot;
|
||||
foreach($this->hasSpawned as $p){
|
||||
$this->sendEquipmentSlot($p);
|
||||
$this->sendCurrentEquipmentSlot($p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getCurrentEquipmentSlot(){
|
||||
return $this->slot;
|
||||
}
|
||||
|
||||
public function getCurrentEquipment(){
|
||||
return $this->hotbar[$this->slot];
|
||||
}
|
||||
|
||||
public function sendCurrentEquipmentSlot(Player $player){
|
||||
$pk = new PlayerEquipmentPacket;
|
||||
$pk->eid = $this->id;
|
||||
|
@ -21,8 +21,8 @@
|
||||
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\Event;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\Event;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
|
||||
|
@ -21,8 +21,8 @@
|
||||
|
||||
namespace pocketmine\event\server;
|
||||
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\event;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\network\protocol\DataPacket;
|
||||
use pocketmine\Player;
|
||||
|
||||
|
@ -21,8 +21,8 @@
|
||||
|
||||
namespace pocketmine\event\server;
|
||||
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\event;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\network\protocol\DataPacket;
|
||||
use pocketmine\Player;
|
||||
|
||||
|
@ -21,8 +21,8 @@
|
||||
|
||||
namespace pocketmine\event\tile;
|
||||
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\Event;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\tile\Tile;
|
||||
|
||||
|
@ -35,7 +35,7 @@ class FlintSteel extends Tool{
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if(($player->gamemode & 0x01) === 0 and $this->useOn($block) and $this->getMetadata() >= $this->getMaxDurability()){
|
||||
$player->setSlot($player->slot, new Item(Item::AIR, 0, 0));
|
||||
$player->setSlot($player->getCurrentEquipment(), new Item(Item::AIR, 0, 0));
|
||||
}
|
||||
|
||||
if($block->getID() === self::AIR and ($target instanceof Solid)){
|
||||
|
@ -210,23 +210,23 @@ class Item{
|
||||
|
||||
//Normal Item IDs
|
||||
|
||||
const IRON_SHOVEL = 256;//
|
||||
const IRON_PICKAXE = 257;//
|
||||
const IRON_AXE = 258;//
|
||||
const FLINT_STEEL = 259;//
|
||||
const FLINT_AND_STEEL = 259;//
|
||||
const APPLE = 260;//
|
||||
const IRON_SHOVEL = 256; //
|
||||
const IRON_PICKAXE = 257; //
|
||||
const IRON_AXE = 258; //
|
||||
const FLINT_STEEL = 259; //
|
||||
const FLINT_AND_STEEL = 259; //
|
||||
const APPLE = 260; //
|
||||
const BOW = 261;
|
||||
const ARROW = 262;
|
||||
const COAL = 263;//
|
||||
const DIAMOND = 264;//
|
||||
const IRON_INGOT = 265;//
|
||||
const GOLD_INGOT = 266;//
|
||||
const COAL = 263; //
|
||||
const DIAMOND = 264; //
|
||||
const IRON_INGOT = 265; //
|
||||
const GOLD_INGOT = 266; //
|
||||
const IRON_SWORD = 267;
|
||||
const WOODEN_SWORD = 268;//
|
||||
const WOODEN_SHOVEL = 269;//
|
||||
const WOODEN_PICKAXE = 270;//
|
||||
const WOODEN_AXE = 271;//
|
||||
const WOODEN_SWORD = 268; //
|
||||
const WOODEN_SHOVEL = 269; //
|
||||
const WOODEN_PICKAXE = 270; //
|
||||
const WOODEN_AXE = 271; //
|
||||
const STONE_SWORD = 272;
|
||||
const STONE_SHOVEL = 273;
|
||||
const STONE_PICKAXE = 274;
|
||||
@ -235,9 +235,9 @@ class Item{
|
||||
const DIAMOND_SHOVEL = 277;
|
||||
const DIAMOND_PICKAXE = 278;
|
||||
const DIAMOND_AXE = 279;
|
||||
const STICK = 280;//
|
||||
const STICK = 280; //
|
||||
const STICKS = 280;
|
||||
const BOWL = 281;//
|
||||
const BOWL = 281; //
|
||||
const MUSHROOM_STEW = 282;
|
||||
const GOLD_SWORD = 283;
|
||||
const GOLD_SHOVEL = 284;
|
||||
@ -248,11 +248,11 @@ class Item{
|
||||
const GOLDEN_PICKAXE = 285;
|
||||
const GOLDEN_AXE = 286;
|
||||
const STRING = 287;
|
||||
const FEATHER = 288;//
|
||||
const FEATHER = 288; //
|
||||
const GUNPOWDER = 289;
|
||||
const WOODEN_HOE = 290;
|
||||
const STONE_HOE = 291;
|
||||
const IRON_HOE = 292;//
|
||||
const IRON_HOE = 292; //
|
||||
const DIAMOND_HOE = 293;
|
||||
const GOLD_HOE = 294;
|
||||
const GOLDEN_HOE = 294;
|
||||
|
@ -172,6 +172,7 @@ abstract class Tool extends Item{
|
||||
|
||||
public function isTool(){
|
||||
return false;
|
||||
|
||||
return ($this->id === self::FLINT_STEEL or $this->id === self::SHEARS or $this->id === self::BOW or $this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false);
|
||||
}
|
||||
}
|
@ -50,6 +50,7 @@ use pocketmine\tile\Sign;
|
||||
use pocketmine\tile\Tile;
|
||||
use pocketmine\utils\Cache;
|
||||
use pocketmine\utils\Random;
|
||||
use pocketmine\utils\ReversePriorityQueue;
|
||||
|
||||
/**
|
||||
* Main Level handling class, includes all the methods used on them.
|
||||
@ -94,6 +95,9 @@ class Level{
|
||||
/** @var Generator */
|
||||
private $generator;
|
||||
|
||||
/** @var ReversePriorityQueue */
|
||||
private $updateQueue;
|
||||
|
||||
private $autoSave = true;
|
||||
|
||||
/**
|
||||
@ -103,6 +107,8 @@ class Level{
|
||||
*/
|
||||
public function __construct(Server $server, LevelFormat $level, $name){
|
||||
$this->server = $server;
|
||||
$this->updateQueue = new ReversePriorityQueue();
|
||||
$this->updateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
|
||||
$this->level = $level;
|
||||
$this->level->level = $this;
|
||||
$this->startTime = $this->time = (int) $this->level->getData("time");
|
||||
@ -257,14 +263,16 @@ class Level{
|
||||
* WARNING: Do not use this, it's only for internal use.
|
||||
* Changes to this function won't be recorded on the version.
|
||||
*
|
||||
* @param int $currentTick
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function doTick(){
|
||||
public function doTick($currentTick){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(($this->server->getTick() % 200) === 0){
|
||||
if(($currentTick % 200) === 0){
|
||||
$this->checkTime();
|
||||
}
|
||||
|
||||
@ -307,6 +315,11 @@ class Level{
|
||||
$Z = null;
|
||||
|
||||
//Do chunk updates
|
||||
while($this->updateQueue->count() > 0 and $this->updateQueue->current()["priority"] <= $currentTick){
|
||||
$block = $this->getBlockRaw($this->updateQueue->extract()["data"]);
|
||||
$block->onUpdate(self::BLOCK_UPDATE_SCHEDULED);
|
||||
}
|
||||
|
||||
foreach($this->usedChunks as $index => $p){
|
||||
LevelFormat::getXZ($index, $X, $Z);
|
||||
for($Y = 0; $Y < 8; ++$Y){
|
||||
@ -315,8 +328,7 @@ class Level{
|
||||
$block = $this->getBlockRaw(new Vector3(($X << 4) + mt_rand(0, 15), ($Y << 4) + mt_rand(0, 15), ($Z << 4) + mt_rand(0, 15)));
|
||||
if($block instanceof Block){
|
||||
if($block->onUpdate(self::BLOCK_UPDATE_RANDOM) === self::BLOCK_UPDATE_NORMAL){
|
||||
//TODO
|
||||
//$this->server->api->block->blockUpdateAround($block);
|
||||
$this->updateAround($block, self::BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -444,6 +456,28 @@ class Level{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Vector3 $pos
|
||||
* @param int $type
|
||||
*/
|
||||
public function updateAround(Vector3 $pos, $type = self::BLOCK_UPDATE_NORMAL){
|
||||
$block = $this->getBlockRaw($pos);
|
||||
$block->getSide(0)->onUpdate($type);
|
||||
$block->getSide(1)->onUpdate($type);
|
||||
$block->getSide(2)->onUpdate($type);
|
||||
$block->getSide(3)->onUpdate($type);
|
||||
$block->getSide(4)->onUpdate($type);
|
||||
$block->getSide(5)->onUpdate($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Vector3 $pos
|
||||
* @param int $delay
|
||||
*/
|
||||
public function scheduleUpdate(Vector3 $pos, $delay){
|
||||
$this->updateQueue->insert($pos, (int) $delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Vector3 $pos
|
||||
*
|
||||
@ -559,8 +593,8 @@ class Level{
|
||||
}
|
||||
|
||||
if($update === true){
|
||||
//TODO
|
||||
//$this->server->api->block->blockUpdateAround($pos, self::BLOCK_UPDATE_NORMAL, 1);
|
||||
$this->updateAround($pos, self::BLOCK_UPDATE_NORMAL);
|
||||
$block->onUpdate(self::BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
if($tiles === true){
|
||||
if(($t = $this->getTile($pos)) instanceof Tile){
|
||||
@ -664,10 +698,11 @@ class Level{
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
if(!$ev->isCancelled()){
|
||||
$target->onUpdate(self::BLOCK_UPDATE_TOUCH);
|
||||
if($target->isActivable === true and $target->onActivate($item, $player) === true){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($target->isActivable === true and $target->onActivate($item, $player) === true){
|
||||
}elseif($target->isActivable === true and $target->onActivate($item, $player) === true){
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -711,7 +746,9 @@ class Level{
|
||||
if($ev->isCancelled()){
|
||||
return false;
|
||||
}
|
||||
}elseif($hand->place($item, $block, $target, $face, $fx, $fy, $fz, $player) === false){
|
||||
}
|
||||
|
||||
if($hand->place($item, $block, $target, $face, $fx, $fy, $fz, $player) === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1154,18 +1191,8 @@ class Level{
|
||||
* Sets the seed for the level
|
||||
*
|
||||
* @param int $seed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setSeed($seed){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
$this->level->setData("seed", (int) $seed);
|
||||
}
|
||||
|
||||
public function scheduleBlockUpdate(Position $pos, $delay, $type = self::BLOCK_UPDATE_SCHEDULED){
|
||||
//TODO
|
||||
//return $this->server->api->block->scheduleBlockUpdate($pos, $delay, $type);
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,12 @@
|
||||
namespace pocketmine\scheduler;
|
||||
|
||||
use pocketmine\plugin\Plugin;
|
||||
use pocketmine\utils\ReversePriorityQueue;
|
||||
|
||||
class ServerScheduler{
|
||||
|
||||
/**
|
||||
* @var \SplPriorityQueue<Task>
|
||||
* @var ReversePriorityQueue<Task>
|
||||
*/
|
||||
protected $queue;
|
||||
|
||||
@ -45,7 +46,7 @@ class ServerScheduler{
|
||||
protected $currentTick = 0;
|
||||
|
||||
public function __construct(){
|
||||
$this->queue = new TaskQueue();
|
||||
$this->queue = new ReversePriorityQueue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,10 +26,10 @@ use pocketmine\item\Item;
|
||||
use pocketmine\nbt\tag\Byte;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Short;
|
||||
use pocketmine\Network;
|
||||
use pocketmine\network\protocol\ContainerOpenPacket;
|
||||
use pocketmine\network\protocol\ContainerSetContentPacket;
|
||||
use pocketmine\network\protocol\TileEventPacket;
|
||||
use pocketmine\Network;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
|
||||
|
@ -19,9 +19,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\scheduler;
|
||||
namespace pocketmine\utils;
|
||||
|
||||
class TaskQueue extends \SplPriorityQueue{
|
||||
class ReversePriorityQueue extends \SplPriorityQueue{
|
||||
|
||||
public function compare($priority1, $priority2){
|
||||
return (int) -($priority1 - $priority2);
|
Loading…
x
Reference in New Issue
Block a user