diff --git a/src/pocketmine/Collectable.php b/src/pocketmine/Collectable.php new file mode 100644 index 000000000..c05a1aed3 --- /dev/null +++ b/src/pocketmine/Collectable.php @@ -0,0 +1,35 @@ +isGarbage; + } + + public function setGarbage(){ + $this->isGarbage = true; + } +} diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 1bd21903b..72f7648c3 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -69,7 +69,6 @@ use pocketmine\event\TranslationContainer; use pocketmine\inventory\BaseTransaction; use pocketmine\inventory\BigShapedRecipe; use pocketmine\inventory\BigShapelessRecipe; -use pocketmine\inventory\CraftingTransactionGroup; use pocketmine\inventory\FurnaceInventory; use pocketmine\inventory\Inventory; use pocketmine\inventory\InventoryHolder; @@ -114,6 +113,7 @@ use pocketmine\network\protocol\Info as ProtocolInfo; use pocketmine\network\protocol\PlayerActionPacket; use pocketmine\network\protocol\PlayStatusPacket; use pocketmine\network\protocol\RespawnPacket; +use pocketmine\network\protocol\SetPlayerGameTypePacket; use pocketmine\network\protocol\TextPacket; use pocketmine\network\protocol\MovePlayerPacket; @@ -565,14 +565,14 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade public function setDisplayName($name){ $this->displayName = $name; if($this->spawned){ - $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $this->isSkinSlim(), $this->getSkinData()); + $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $this->getSkinName(), $this->getSkinData()); } } - public function setSkin($str, $isSlim = false){ - parent::setSkin($str, $isSlim); + public function setSkin($str, $skinName){ + parent::setSkin($str, $skinName); if($this->spawned){ - $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $isSlim, $str); + $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $skinName, $str); } } @@ -707,7 +707,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } unset($this->loadQueue[$index]); - $this->level->requestChunk($X, $Z, $this, LevelProvider::ORDER_ZXY); + $this->level->requestChunk($X, $Z, $this); } if($this->chunkLoadCount >= $this->spawnThreshold and $this->spawned === false and $this->teleportPosition === null){ @@ -1076,7 +1076,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; } - $this->gamemode = $gm; $this->allowFlight = $this->isCreative(); @@ -1089,19 +1088,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->namedtag->playerGameType = new IntTag("playerGameType", $this->gamemode); - $spawnPosition = $this->getSpawn(); - - $pk = new StartGamePacket(); - $pk->seed = -1; - $pk->x = $this->x; - $pk->y = $this->y; - $pk->z = $this->z; - $pk->spawnX = (int) $spawnPosition->x; - $pk->spawnY = (int) $spawnPosition->y; - $pk->spawnZ = (int) $spawnPosition->z; - $pk->generator = 1; //0 old, 1 infinite, 2 flat + $pk = new SetPlayerGameTypePacket(); $pk->gamemode = $this->gamemode & 0x01; - $pk->eid = 0; $this->dataPacket($pk); $this->sendSettings(); @@ -1842,7 +1830,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade break; } - $this->setSkin($packet->skin, $packet->slim); + $this->setSkin($packet->skin, $packet->skinName); $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason")); if($ev->isCancelled()){ @@ -1865,7 +1853,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } if($this->teleportPosition !== null or ($this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert))){ - $this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch); + $this->sendPosition($this->teleportPosition === null ? $this->forceMovement : $this->teleportPosition, $packet->yaw, $packet->pitch); }else{ $packet->yaw %= 360; $packet->pitch %= 360; @@ -1974,7 +1962,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade //TODO: Implement adventure mode checks if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this)){ if(!$item->deepEquals($oldItem) or $item->getCount() !== $oldItem->getCount()){ - $this->inventory->setItemInHand($item, $this); + $this->inventory->setItemInHand($item); $this->inventory->sendHeldItem($this->hasSpawned); } break; @@ -2155,7 +2143,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $pk = new EntityEventPacket(); $pk->eid = $this->getId(); $pk->event = EntityEventPacket::USE_ITEM; - $pk; $this->dataPacket($pk); Server::broadcastPacket($this->getViewers(), $pk); @@ -2274,7 +2261,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade if($this->canInteract($vector->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 6) and $this->level->useBreakOn($vector, $item, $this)){ if($this->isSurvival()){ if(!$item->deepEquals($oldItem) or $item->getCount() !== $oldItem->getCount()){ - $this->inventory->setItemInHand($item, $this); + $this->inventory->setItemInHand($item); $this->inventory->sendHeldItem($this->hasSpawned); } } @@ -2498,12 +2485,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->heal($ev->getAmount(), $ev); --$slot->count; - $this->inventory->setItemInHand($slot, $this); + $this->inventory->setItemInHand($slot); if($slot->getId() === Item::MUSHROOM_STEW or $slot->getId() === Item::BEETROOT_SOUP){ $this->inventory->addItem(Item::get(Item::BOWL, 0, 1)); }elseif($slot->getId() === Item::RAW_FISH and $slot->getDamage() === 3){ //Pufferfish - $this->addEffect(Effect::getEffect(Effect::HUNGER)->setAmplifier(2)->setDuration(15 * 20)); - //$this->addEffect(Effect::getEffect(Effect::NAUSEA)->setAmplifier(1)->setDuration(15 * 20)); + //$this->addEffect(Effect::getEffect(Effect::HUNGER)->setAmplifier(2)->setDuration(15 * 20)); + $this->addEffect(Effect::getEffect(Effect::NAUSEA)->setAmplifier(1)->setDuration(15 * 20)); $this->addEffect(Effect::getEffect(Effect::POISON)->setAmplifier(3)->setDuration(60 * 20)); } } @@ -2522,7 +2509,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade break; } - $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1), $this); + $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1)); $motion = $this->getDirectionVector()->multiply(0.4); $this->level->dropItem($this->add(0, 1.3, 0), $item, $motion, 40); @@ -2612,15 +2599,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade for($y = 0; $y < 3; ++$y){ $item = $packet->input[$y * 3 + $x]; $ingredient = $recipe->getIngredient($x, $y); - if($item->getCount() > 0 and $item->getId() > 0){ + if($item->getCount() > 0){ if($ingredient === null or !$ingredient->deepEquals($item, $ingredient->getDamage() !== null, $ingredient->getCompoundTag() !== null)){ $canCraft = false; break; } - - }elseif($ingredient !== null and $ingredient->getId() !== 0){ - $canCraft = false; - break; } } } @@ -2838,7 +2821,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } break; - case ProtocolInfo::TILE_ENTITY_DATA_PACKET: + case ProtocolInfo::BLOCK_ENTITY_DATA_PACKET: if($this->spawned === false or $this->blocked === true or !$this->isAlive()){ break; } @@ -2900,7 +2883,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, $this->getLeaveMessage())); if(!$ev->isCancelled()){ if($isAdmin){ - $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : ""); + if(!$this->isBanned()) { + $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : ""); + }else{ + $message = $reason; + } }else{ if($reason === ""){ $message = "disconnectionScreen.noReason"; @@ -3366,9 +3353,16 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return true; } + /** + * @param Vector3|Position|Location $pos + * @param float $yaw + * @param float $pitch + * + * @return bool + */ public function teleport(Vector3 $pos, $yaw = null, $pitch = null){ if(!$this->isOnline()){ - return; + return false; } $oldPos = $this->getPosition(); @@ -3389,11 +3383,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->spawnToAll(); } - $this->resetFallDistance(); $this->nextChunkOrderRun = 0; $this->newPosition = null; + return true; } + return false; } /** @@ -3540,7 +3535,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $batch = new BatchPacket(); $batch->payload = zlib_encode(Binary::writeInt(strlen($pk->getBuffer())) . $pk->getBuffer(), ZLIB_ENCODING_DEFLATE, Server::getInstance()->networkCompressionLevel); - $batch; $batch->encode(); $batch->isEncoded = true; return $batch; diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 3507373f6..4802b1cee 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -75,8 +75,8 @@ namespace pocketmine { const VERSION = "1.6dev"; const API_VERSION = "2.0.0"; const CODENAME = "[REDACTED]"; - const MINECRAFT_VERSION = "v0.12.1 alpha"; - const MINECRAFT_VERSION_NETWORK = "0.12.1"; + const MINECRAFT_VERSION = "v0.13.1 alpha"; + const MINECRAFT_VERSION_NETWORK = "0.13.1"; /* * Startup code. Do not look at it, it may harm you. @@ -170,11 +170,13 @@ namespace pocketmine { * This is here so that people don't come to us complaining and fill up the issue tracker when they put * an incorrect timezone abbreviation in php.ini apparently. */ - $default_timezone = date_default_timezone_get(); - if(strpos($default_timezone, "/") === false){ - $default_timezone = timezone_name_from_abbr($default_timezone); + $timezone = ini_get("date.timezone"); + if(strpos($timezone, "/") === false){ + $default_timezone = timezone_name_from_abbr($timezone); ini_set("date.timezone", $default_timezone); date_default_timezone_set($default_timezone); + } else { + date_default_timezone_set($timezone); } } @@ -394,8 +396,8 @@ namespace pocketmine { if(substr_count($pthreads_version, ".") < 2){ $pthreads_version = "0.$pthreads_version"; } - if(version_compare($pthreads_version, "3.0.7") < 0){ - $logger->critical("pthreads >= 3.0.7 is required, while you have $pthreads_version."); + if(version_compare($pthreads_version, "3.1.5") < 0){ + $logger->critical("pthreads >= 3.1.5 is required, while you have $pthreads_version."); ++$errors; } diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 658eb01df..f997e19dd 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2175,7 +2175,7 @@ class Server{ public function addOnlinePlayer(Player $player){ $this->playerList[$player->getRawUniqueId()] = $player; - $this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->isSkinSlim(), $player->getSkinData()); + $this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinName(), $player->getSkinData()); } public function removeOnlinePlayer(Player $player){ @@ -2189,10 +2189,10 @@ class Server{ } } - public function updatePlayerListData(UUID $uuid, $entityId, $name, $isSlim, $skinData, array $players = null){ + public function updatePlayerListData(UUID $uuid, $entityId, $name, $skinName, $skinData, array $players = null){ $pk = new PlayerListPacket(); $pk->type = PlayerListPacket::TYPE_ADD; - $pk->entries[] = [$uuid, $entityId, $name, $isSlim, $skinData]; + $pk->entries[] = [$uuid, $entityId, $name, $skinName, $skinData]; Server::broadcastPacket($players === null ? $this->playerList : $players, $pk); } @@ -2207,7 +2207,7 @@ class Server{ $pk = new PlayerListPacket(); $pk->type = PlayerListPacket::TYPE_ADD; foreach($this->playerList as $player){ - $pk->entries[] = [$player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->isSkinSlim(), $player->getSkinData()]; + $pk->entries[] = [$player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinName(), $player->getSkinData()]; } $p->dataPacket($pk); diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 4c3114bd4..73c2e6c0f 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -71,7 +71,7 @@ class Anvil extends Fallable{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [$this->id, 0, 1], //TODO break level ]; diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index d94a751f7..fe0e7e3ca 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -181,13 +181,13 @@ class Block extends Position implements Metadatable{ const LILY_PAD = 111; const NETHER_BRICKS = 112; const NETHER_BRICK_BLOCK = 112; - + const NETHER_BRICK_FENCE = 113; const NETHER_BRICKS_STAIRS = 114; const ENCHANTING_TABLE = 116; const ENCHANT_TABLE = 116; const ENCHANTMENT_TABLE = 116; - + const BREWING_STAND = 117; const END_PORTAL_FRAME = 120; const END_STONE = 121; @@ -205,11 +205,12 @@ class Block extends Position implements Metadatable{ const COBBLE_WALL = 139; const STONE_WALL = 139; const COBBLESTONE_WALL = 139; - + const FLOWER_POT_BLOCK = 140; const CARROT_BLOCK = 141; const POTATO_BLOCK = 142; const ANVIL = 145; + const TRAPPED_CHEST = 146; const REDSTONE_BLOCK = 152; @@ -236,11 +237,12 @@ class Block extends Position implements Metadatable{ const DARK_OAK_WOOD_STAIRS = 164; const DARK_OAK_WOODEN_STAIRS = 164; + const IRON_TRAPDOOR = 167; const HAY_BALE = 170; const CARPET = 171; const HARDENED_CLAY = 172; const COAL_BLOCK = 173; - + const PACKED_ICE = 174; const DOUBLE_PLANT = 175; const FENCE_GATE_SPRUCE = 183; @@ -255,7 +257,6 @@ class Block extends Position implements Metadatable{ const BEETROOT_BLOCK = 244; const STONECUTTER = 245; const GLOWING_OBSIDIAN = 246; - const NETHER_REACTOR = 247; /** @var \SplFixedArray */ public static $list = null; @@ -387,11 +388,11 @@ class Block extends Position implements Metadatable{ self::$list[self::MYCELIUM] = Mycelium::class; self::$list[self::WATER_LILY] = WaterLily::class; self::$list[self::NETHER_BRICKS] = NetherBrick::class; - + self::$list[self::NETHER_BRICK_FENCE] = NetherBrickFence::class; self::$list[self::NETHER_BRICKS_STAIRS] = NetherBrickStairs::class; self::$list[self::ENCHANTING_TABLE] = EnchantingTable::class; - + self::$list[self::BREWING_STAND] = BrewingStand::class; self::$list[self::END_PORTAL_FRAME] = EndPortalFrame::class; self::$list[self::END_STONE] = EndStone::class; self::$list[self::SANDSTONE_STAIRS] = SandstoneStairs::class; @@ -402,11 +403,11 @@ class Block extends Position implements Metadatable{ 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::FLOWER_POT_BLOCK] = FlowerPot::class; self::$list[self::CARROT_BLOCK] = Carrot::class; self::$list[self::POTATO_BLOCK] = Potato::class; self::$list[self::ANVIL] = Anvil::class; - + self::$list[self::TRAPPED_CHEST] = TrappedChest::class; self::$list[self::REDSTONE_BLOCK] = Redstone::class; self::$list[self::QUARTZ_BLOCK] = Quartz::class; @@ -420,11 +421,12 @@ class Block extends Position implements Metadatable{ self::$list[self::ACACIA_WOOD_STAIRS] = AcaciaWoodStairs::class; self::$list[self::DARK_OAK_WOOD_STAIRS] = DarkOakWoodStairs::class; + self::$list[self::IRON_TRAPDOOR] = IronTrapdoor::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::PACKED_ICE] = PackedIce::class; self::$list[self::DOUBLE_PLANT] = DoublePlant::class; self::$list[self::FENCE_GATE_SPRUCE] = FenceGateSpruce::class; @@ -439,7 +441,6 @@ class Block extends Position implements Metadatable{ 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){ diff --git a/src/pocketmine/block/BrewingStand.php b/src/pocketmine/block/BrewingStand.php new file mode 100644 index 000000000..e0e7aaa9a --- /dev/null +++ b/src/pocketmine/block/BrewingStand.php @@ -0,0 +1,46 @@ +isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::BRICKS_BLOCK, 0, 1], ]; diff --git a/src/pocketmine/block/BurningFurnace.php b/src/pocketmine/block/BurningFurnace.php index 4b2638378..84de41121 100644 --- a/src/pocketmine/block/BurningFurnace.php +++ b/src/pocketmine/block/BurningFurnace.php @@ -135,7 +135,7 @@ class BurningFurnace extends Solid{ public function getDrops(Item $item){ $drops = []; - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ $drops[] = [Item::FURNACE, 0, 1]; } diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 7f0187f51..d95b64a7c 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -96,16 +96,18 @@ class Cake extends Transparent{ $ev = new EntityRegainHealthEvent($player, 3, EntityRegainHealthEvent::CAUSE_EATING); $player->heal($ev->getAmount(), $ev); - if($this->meta >= 0x06){ - $this->getLevel()->setBlock($this, new Air(), true); - }else{ - $this->getLevel()->setBlock($this, $this, true); + if(!$ev->isCancelled()){ + if($this->meta >= 0x06){ + $this->getLevel()->setBlock($this, new Air(), true); + }else{ + $this->getLevel()->setBlock($this, $this, true); + } + + return true; } - - return true; } return false; } -} \ No newline at end of file +} diff --git a/src/pocketmine/block/Coal.php b/src/pocketmine/block/Coal.php index 75e4fb0d4..494534dcf 100644 --- a/src/pocketmine/block/Coal.php +++ b/src/pocketmine/block/Coal.php @@ -45,7 +45,7 @@ class Coal extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::COAL_BLOCK, 0, 1], ]; diff --git a/src/pocketmine/block/CoalOre.php b/src/pocketmine/block/CoalOre.php index 964ed7647..6c1a78e76 100644 --- a/src/pocketmine/block/CoalOre.php +++ b/src/pocketmine/block/CoalOre.php @@ -45,7 +45,7 @@ class CoalOre extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::COAL, 0, 1], ]; diff --git a/src/pocketmine/block/Cobblestone.php b/src/pocketmine/block/Cobblestone.php index 0a41aa186..5954edbba 100644 --- a/src/pocketmine/block/Cobblestone.php +++ b/src/pocketmine/block/Cobblestone.php @@ -45,7 +45,7 @@ class Cobblestone extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::COBBLESTONE, 0, 1], ]; diff --git a/src/pocketmine/block/Diamond.php b/src/pocketmine/block/Diamond.php index cbe924c95..1fd175dca 100644 --- a/src/pocketmine/block/Diamond.php +++ b/src/pocketmine/block/Diamond.php @@ -45,7 +45,7 @@ class Diamond extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 4){ + if($item->isPickaxe() >= Tool::TIER_IRON){ return [ [Item::DIAMOND_BLOCK, 0, 1], ]; diff --git a/src/pocketmine/block/DiamondOre.php b/src/pocketmine/block/DiamondOre.php index e9b9466db..c05abb384 100644 --- a/src/pocketmine/block/DiamondOre.php +++ b/src/pocketmine/block/DiamondOre.php @@ -45,7 +45,7 @@ class DiamondOre extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 4){ + if($item->isPickaxe() >= Tool::TIER_IRON){ return [ [Item::DIAMOND, 0, 1], ]; diff --git a/src/pocketmine/block/DoubleSlab.php b/src/pocketmine/block/DoubleSlab.php index 295856128..e8b58511a 100644 --- a/src/pocketmine/block/DoubleSlab.php +++ b/src/pocketmine/block/DoubleSlab.php @@ -49,13 +49,13 @@ class DoubleSlab extends Solid{ 4 => "Brick", 5 => "Stone Brick", 6 => "Quartz", - 7 => "", + 7 => "Nether Brick", ]; return "DoubleTag " . $names[$this->meta & 0x07] . " Slab"; } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::SLAB, $this->meta & 0x07, 2], ]; diff --git a/src/pocketmine/block/Emerald.php b/src/pocketmine/block/Emerald.php index b5db557e0..2f24e34c5 100644 --- a/src/pocketmine/block/Emerald.php +++ b/src/pocketmine/block/Emerald.php @@ -45,7 +45,7 @@ class Emerald extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 4){ + if($item->isPickaxe() >= Tool::TIER_IRON){ return [ [Item::EMERALD_BLOCK, 0, 1], ]; diff --git a/src/pocketmine/block/EmeraldOre.php b/src/pocketmine/block/EmeraldOre.php index 54971f3b4..90fac45c3 100644 --- a/src/pocketmine/block/EmeraldOre.php +++ b/src/pocketmine/block/EmeraldOre.php @@ -45,7 +45,7 @@ class EmeraldOre extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 4){ + if($item->isPickaxe() >= Tool::TIER_IRON){ return [ [Item::EMERALD, 0, 1], ]; diff --git a/src/pocketmine/block/EnchantingTable.php b/src/pocketmine/block/EnchantingTable.php index f6c4e1d9d..59539906b 100644 --- a/src/pocketmine/block/EnchantingTable.php +++ b/src/pocketmine/block/EnchantingTable.php @@ -97,7 +97,7 @@ class EnchantingTable extends Transparent{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [$this->id, 0, 1], ]; diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index 2262e1490..510ea39f7 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -26,7 +26,13 @@ use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; class Fence extends Transparent{ - + const FENCE_OAK = 0; + const FENCE_SPRUCE = 1; + const FENCE_BIRCH = 2; + const FENCE_JUNGLE = 3; + const FENCE_ACACIA = 4; + const FENCE_DARKOAK = 5; + protected $id = self::FENCE; public function __construct($meta = 0){ @@ -38,18 +44,18 @@ class Fence extends Transparent{ } public function getToolType(){ - return Tool::TYPE_PICKAXE; + return Tool::TYPE_AXE; } public function getName(){ static $names = [ - 0 => "Oak Fence", - 1 => "Spruce Fence", - 2 => "Birch Fence", - 3 => "Jungle Fence", - 4 => "Acacia Fence", - 5 => "Dark Oak Fence", + self::FENCE_OAK => "Oak Fence", + self::FENCE_SPRUCE => "Spruce Fence", + self::FENCE_BIRCH => "Birch Fence", + self::FENCE_JUNGLE => "Jungle Fence", + self::FENCE_ACACIA => "Acacia Fence", + self::FENCE_DARKOAK => "Dark Oak Fence", "", "" ]; diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 7c0e0f8ea..4ffef72f7 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -23,6 +23,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; +use pocketmine\level\sound\DoorSound; use pocketmine\math\AxisAlignedBB; use pocketmine\Player; diff --git a/src/pocketmine/block/NetherReactor.php b/src/pocketmine/block/FlowerPot.php similarity index 84% rename from src/pocketmine/block/NetherReactor.php rename to src/pocketmine/block/FlowerPot.php index 47e49582b..5451efdfc 100644 --- a/src/pocketmine/block/NetherReactor.php +++ b/src/pocketmine/block/FlowerPot.php @@ -21,21 +21,18 @@ namespace pocketmine\block; +use pocketmine\item\Item; -class NetherReactor extends Solid{ +class FlowerPot extends Transparent{ - protected $id = self::NETHER_REACTOR; + protected $id = self::FLOWER_POT_BLOCK; public function __construct($meta = 0){ $this->meta = $meta; } public function getName(){ - return "Nether Reactor"; - } - - public function canBeActivated(){ - return true; + return "Flower Pot Block"; } } \ No newline at end of file diff --git a/src/pocketmine/block/GlowingRedstoneOre.php b/src/pocketmine/block/GlowingRedstoneOre.php index a1675fc02..095241607 100644 --- a/src/pocketmine/block/GlowingRedstoneOre.php +++ b/src/pocketmine/block/GlowingRedstoneOre.php @@ -60,7 +60,7 @@ class GlowingRedstoneOre extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 4){ + if($item->isPickaxe() >= Tool::TIER_IRON){ return [ [Item::REDSTONE_DUST, 0, mt_rand(4, 5)], ]; diff --git a/src/pocketmine/block/Gold.php b/src/pocketmine/block/Gold.php index cb9421124..62b942f53 100644 --- a/src/pocketmine/block/Gold.php +++ b/src/pocketmine/block/Gold.php @@ -45,7 +45,7 @@ class Gold extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 4){ + if($item->isPickaxe() >= Tool::TIER_IRON){ return [ [Item::GOLD_BLOCK, 0, 1], ]; diff --git a/src/pocketmine/block/GoldOre.php b/src/pocketmine/block/GoldOre.php index 5c87c16d4..c56cff977 100644 --- a/src/pocketmine/block/GoldOre.php +++ b/src/pocketmine/block/GoldOre.php @@ -45,7 +45,7 @@ class GoldOre extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 4){ + if($item->isPickaxe() >= Tool::TIER_IRON){ return [ [Item::GOLD_ORE, 0, 1], ]; diff --git a/src/pocketmine/block/Iron.php b/src/pocketmine/block/Iron.php index 66a2c28ee..2ffc4cd6a 100644 --- a/src/pocketmine/block/Iron.php +++ b/src/pocketmine/block/Iron.php @@ -45,7 +45,7 @@ class Iron extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 3){ + if($item->isPickaxe() >= Tool::TIER_STONE){ return [ [Item::IRON_BLOCK, 0, 1], ]; diff --git a/src/pocketmine/block/IronBars.php b/src/pocketmine/block/IronBars.php index bebe0f3a2..b5e70e873 100644 --- a/src/pocketmine/block/IronBars.php +++ b/src/pocketmine/block/IronBars.php @@ -45,7 +45,7 @@ class IronBars extends Thin{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::IRON_BARS, 0, 1], ]; diff --git a/src/pocketmine/block/IronDoor.php b/src/pocketmine/block/IronDoor.php index 447b723f9..70195b9a9 100644 --- a/src/pocketmine/block/IronDoor.php +++ b/src/pocketmine/block/IronDoor.php @@ -45,7 +45,7 @@ class IronDoor extends Door{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::IRON_DOOR, 0, 1], ]; diff --git a/src/pocketmine/block/IronOre.php b/src/pocketmine/block/IronOre.php index 01e8be86d..cda415136 100644 --- a/src/pocketmine/block/IronOre.php +++ b/src/pocketmine/block/IronOre.php @@ -45,7 +45,7 @@ class IronOre extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 3){ + if($item->isPickaxe() >= Tool::TIER_STONE){ return [ [Item::IRON_ORE, 0, 1], ]; diff --git a/src/pocketmine/block/IronTrapdoor.php b/src/pocketmine/block/IronTrapdoor.php new file mode 100644 index 000000000..b23d2a225 --- /dev/null +++ b/src/pocketmine/block/IronTrapdoor.php @@ -0,0 +1,156 @@ +meta = $meta; + } + + public function getName(){ + return "Iron Trapdoor"; + } + + public function getHardness(){ + return 5; + } + + public function canBeActivated(){ + return true; + } + + protected function recalculateBoundingBox(){ + + $damage = $this->getDamage(); + + $f = 0.1875; + + if(($damage & 0x08) > 0){ + $bb = new AxisAlignedBB( + $this->x, + $this->y + 1 - $f, + $this->z, + $this->x + 1, + $this->y + 1, + $this->z + 1 + ); + }else{ + $bb = new AxisAlignedBB( + $this->x, + $this->y, + $this->z, + $this->x + 1, + $this->y + $f, + $this->z + 1 + ); + } + + if(($damage & 0x04) > 0){ + if(($damage & 0x03) === 0){ + $bb->setBounds( + $this->x, + $this->y, + $this->z + 1 - $f, + $this->x + 1, + $this->y + 1, + $this->z + 1 + ); + }elseif(($damage & 0x03) === 1){ + $bb->setBounds( + $this->x, + $this->y, + $this->z, + $this->x + 1, + $this->y + 1, + $this->z + $f + ); + } + if(($damage & 0x03) === 2){ + $bb->setBounds( + $this->x + 1 - $f, + $this->y, + $this->z, + $this->x + 1, + $this->y + 1, + $this->z + 1 + ); + } + if(($damage & 0x03) === 3){ + $bb->setBounds( + $this->x, + $this->y, + $this->z, + $this->x + $f, + $this->y + 1, + $this->z + 1 + ); + } + } + + return $bb; + } + + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + if(($target->isTransparent() === false or $target->getId() === self::SLAB) and $face !== 0 and $face !== 1){ + $faces = [ + 2 => 0, + 3 => 1, + 4 => 2, + 5 => 3, + ]; + $this->meta = $faces[$face] & 0x03; + if($fy > 0.5){ + $this->meta |= 0x08; + } + $this->getLevel()->setBlock($block, $this, true, true); + + return true; + } + + return false; + } + + public function getDrops(Item $item){ + return [ + [$this->id, 0, 1], + ]; + } + + public function onActivate(Item $item, Player $player = null){ + $this->meta ^= 0x04; + $this->getLevel()->setBlock($this, $this, true); + $this->level->addSound(new DoorSound($this)); + return true; + } + + public function getToolType(){ + return Tool::TYPE_PICKAXE; + } +} \ No newline at end of file diff --git a/src/pocketmine/block/Lapis.php b/src/pocketmine/block/Lapis.php index aa0b9212f..5cc8a2537 100644 --- a/src/pocketmine/block/Lapis.php +++ b/src/pocketmine/block/Lapis.php @@ -45,7 +45,7 @@ class Lapis extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 3){ + if($item->isPickaxe() >= Tool::TIER_STONE){ return [ [Item::LAPIS_BLOCK, 0, 1], ]; diff --git a/src/pocketmine/block/LapisOre.php b/src/pocketmine/block/LapisOre.php index 44d6e9eeb..68ca5626e 100644 --- a/src/pocketmine/block/LapisOre.php +++ b/src/pocketmine/block/LapisOre.php @@ -45,7 +45,7 @@ class LapisOre extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 3){ + if($item->isPickaxe() >= Tool::TIER_STONE){ return [ [Item::DYE, 4, mt_rand(4, 8)], ]; diff --git a/src/pocketmine/block/MossStone.php b/src/pocketmine/block/MossStone.php index 5700d5928..6476028f2 100644 --- a/src/pocketmine/block/MossStone.php +++ b/src/pocketmine/block/MossStone.php @@ -45,7 +45,7 @@ class MossStone extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::MOSS_STONE, $this->meta, 1], ]; diff --git a/src/pocketmine/block/NetherBrick.php b/src/pocketmine/block/NetherBrick.php index 937713b80..12400a516 100644 --- a/src/pocketmine/block/NetherBrick.php +++ b/src/pocketmine/block/NetherBrick.php @@ -45,7 +45,7 @@ class NetherBrick extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::NETHER_BRICKS, 0, 1], ]; diff --git a/src/pocketmine/block/NetherBrickFence.php b/src/pocketmine/block/NetherBrickFence.php new file mode 100644 index 000000000..62a182375 --- /dev/null +++ b/src/pocketmine/block/NetherBrickFence.php @@ -0,0 +1,71 @@ +meta = $meta; + } + + public function getBreakTime(Item $item){ + if ($item instanceof Air){ + //Breaking by hand + return 10; + } + else{ + // Other breaktimes are equal to woodfences. + return parent::getBreakTime($item); + } + } + + public function getHardness(){ + return 2; + } + + public function getToolType(){ + return Tool::TYPE_PICKAXE; + } + + public function getName(){ + return "Nether Brick Fence"; + } + + public function canConnect(Block $block){ + //TODO: activate comments when the NetherBrickFenceGate class has been created. + return ($block instanceof NetherBrickFence /* or $block instanceof NetherBrickFenceGate */) ? true : $block->isSolid() and !$block->isTransparent(); + } + + public function getDrops(Item $item){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ + return [ + [$this->id, $this->meta, 1], + ]; + }else{ + return []; + } + } +} diff --git a/src/pocketmine/block/Netherrack.php b/src/pocketmine/block/Netherrack.php index 8d3d5135a..7496ad14d 100644 --- a/src/pocketmine/block/Netherrack.php +++ b/src/pocketmine/block/Netherrack.php @@ -45,7 +45,7 @@ class Netherrack extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::NETHERRACK, 0, 1], ]; diff --git a/src/pocketmine/block/Obsidian.php b/src/pocketmine/block/Obsidian.php index cc93e4379..f483c58b9 100644 --- a/src/pocketmine/block/Obsidian.php +++ b/src/pocketmine/block/Obsidian.php @@ -45,7 +45,7 @@ class Obsidian extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 5){ + if($item->isPickaxe() >= Tool::TIER_DIAMOND){ return [ [Item::OBSIDIAN, 0, 1], ]; diff --git a/src/pocketmine/block/PackedIce.php b/src/pocketmine/block/PackedIce.php new file mode 100644 index 000000000..8d9e30a9d --- /dev/null +++ b/src/pocketmine/block/PackedIce.php @@ -0,0 +1,47 @@ + "Quartz Block", - 1 => "Chiseled Quartz Block", - 2 => "Quartz Pillar", - 3 => "Quartz Pillar", + self::QUARTZ_NORMAL => "Quartz Block", + self::QUARTZ_CHISELED => "Chiseled Quartz Block", + self::QUARTZ_PILLAR => "Quartz Pillar", + self::QUARTZ_PILLAR2 => "Quartz Pillar", ]; return $names[$this->meta & 0x03]; } @@ -51,7 +56,7 @@ class Quartz extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::QUARTZ_BLOCK, $this->meta & 0x03, 1], ]; diff --git a/src/pocketmine/block/Redstone.php b/src/pocketmine/block/Redstone.php index c2707e016..41cd19d54 100644 --- a/src/pocketmine/block/Redstone.php +++ b/src/pocketmine/block/Redstone.php @@ -45,7 +45,7 @@ class Redstone extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::REDSTONE_BLOCK, 0, 1], ]; diff --git a/src/pocketmine/block/RedstoneOre.php b/src/pocketmine/block/RedstoneOre.php index 6b31c4090..2fb6df907 100644 --- a/src/pocketmine/block/RedstoneOre.php +++ b/src/pocketmine/block/RedstoneOre.php @@ -58,7 +58,7 @@ class RedstoneOre extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 2){ + if($item->isPickaxe() >= Tool::TIER_GOLD){ return [ [Item::REDSTONE_DUST, 0, mt_rand(4, 5)], ]; diff --git a/src/pocketmine/block/Sandstone.php b/src/pocketmine/block/Sandstone.php index a94a32ae3..60bca024a 100644 --- a/src/pocketmine/block/Sandstone.php +++ b/src/pocketmine/block/Sandstone.php @@ -26,6 +26,10 @@ use pocketmine\item\Tool; class Sandstone extends Solid{ + const NORMAL = 0; + const CHISELED = 1; + const SMOOTH = 2; + protected $id = self::SANDSTONE; public function __construct($meta = 0){ @@ -38,9 +42,9 @@ class Sandstone extends Solid{ public function getName(){ static $names = [ - 0 => "Sandstone", - 1 => "Chiseled Sandstone", - 2 => "Smooth Sandstone", + self::NORMAL => "Sandstone", + self::CHISELED => "Chiseled Sandstone", + self::SMOOTH => "Smooth Sandstone", 3 => "", ]; return $names[$this->meta & 0x03]; @@ -51,7 +55,7 @@ class Sandstone extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::SANDSTONE, $this->meta & 0x03, 1], ]; diff --git a/src/pocketmine/block/SignPost.php b/src/pocketmine/block/SignPost.php index c151f0731..5ae519979 100644 --- a/src/pocketmine/block/SignPost.php +++ b/src/pocketmine/block/SignPost.php @@ -88,7 +88,7 @@ class SignPost extends Transparent{ } public function onBreak(Item $item){ - $this->getLevel()->setBlock($this, new Air(), true, true, true); + $this->getLevel()->setBlock($this, new Air(), true, true); return true; } diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index 303d8fbd0..0bf6ae950 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -27,6 +27,14 @@ use pocketmine\math\AxisAlignedBB; use pocketmine\Player; class Slab extends Transparent{ + const STONE = 0; + const SANDSTONE = 1; + const WOODEN = 2; + const COBBLESTONE = 3; + const BRICK = 4; + const STONE_BRICK = 5; + const QUARTZ = 6; + const NETHER_BRICK = 7; protected $id = self::SLAB; @@ -40,14 +48,14 @@ class Slab extends Transparent{ public function getName(){ static $names = [ - 0 => "Stone", - 1 => "Sandstone", - 2 => "Wooden", - 3 => "Cobblestone", - 4 => "Brick", - 5 => "Stone Brick", - 6 => "Quartz", - 7 => "", + self::STONE => "Stone", + self::SANDSTONE => "Sandstone", + self::WOODEN => "Wooden", + self::COBBLESTONE => "Cobblestone", + self::BRICK => "Brick", + self::STONE_BRICK => "Stone Brick", + self::QUARTZ => "Quartz", + self::NETHER_BRICK => "Nether Brick", ]; return (($this->meta & 0x08) > 0 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab"; } @@ -125,7 +133,7 @@ class Slab extends Transparent{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [$this->id, $this->meta & 0x07, 1], ]; diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index bb02a76d1..8e5b30f8a 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -22,6 +22,7 @@ namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\item\Tool; use pocketmine\math\AxisAlignedBB; use pocketmine\Player; @@ -143,7 +144,7 @@ abstract class Stair extends Transparent{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [$this->getId(), 0, 1], ]; @@ -151,4 +152,4 @@ abstract class Stair extends Transparent{ return []; } } -} \ No newline at end of file +} diff --git a/src/pocketmine/block/Stone.php b/src/pocketmine/block/Stone.php index 3b9eadd12..055731d7c 100644 --- a/src/pocketmine/block/Stone.php +++ b/src/pocketmine/block/Stone.php @@ -37,7 +37,6 @@ class Stone extends Solid{ public function __construct($meta = 0){ $this->meta = $meta; - } public function getHardness(){ diff --git a/src/pocketmine/block/StoneBricks.php b/src/pocketmine/block/StoneBricks.php index ecb17ed5e..461a39e4e 100644 --- a/src/pocketmine/block/StoneBricks.php +++ b/src/pocketmine/block/StoneBricks.php @@ -25,6 +25,10 @@ use pocketmine\item\Item; use pocketmine\item\Tool; class StoneBricks extends Solid{ + const NORMAL = 0; + const MOSSY = 1; + const CRACKED = 2; + const CHISELED = 3; protected $id = self::STONE_BRICKS; @@ -42,16 +46,16 @@ class StoneBricks extends Solid{ public function getName(){ static $names = [ - 0 => "Stone Bricks", - 1 => "Mossy Stone Bricks", - 2 => "Cracked Stone Bricks", - 3 => "Chiseled Stone Bricks", + self::NORMAL => "Stone Bricks", + self::MOSSY => "Mossy Stone Bricks", + self::CRACKED => "Cracked Stone Bricks", + self::CHISELED => "Chiseled Stone Bricks", ]; return $names[$this->meta & 0x03]; } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::STONE_BRICKS, $this->meta & 0x03, 1], ]; diff --git a/src/pocketmine/block/StoneWall.php b/src/pocketmine/block/StoneWall.php index 953c182c0..cf689b694 100644 --- a/src/pocketmine/block/StoneWall.php +++ b/src/pocketmine/block/StoneWall.php @@ -27,6 +27,8 @@ use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; class StoneWall extends Transparent{ + const NONE_MOSSY_WALL = 0; + const MOSSY_WALL = 1; protected $id = self::STONE_WALL; diff --git a/src/pocketmine/block/Stonecutter.php b/src/pocketmine/block/Stonecutter.php index 3dc127c46..918011e3f 100644 --- a/src/pocketmine/block/Stonecutter.php +++ b/src/pocketmine/block/Stonecutter.php @@ -55,7 +55,7 @@ class Stonecutter extends Solid{ } public function getDrops(Item $item){ - if($item->isPickaxe() >= 1){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ [Item::STONECUTTER, 0, 1], ]; diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 434b3264b..370cef37d 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -24,6 +24,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\math\AxisAlignedBB; +use pocketmine\level\sound\DoorSound; use pocketmine\Player; class Trapdoor extends Transparent{ diff --git a/src/pocketmine/block/TrappedChest.php b/src/pocketmine/block/TrappedChest.php new file mode 100644 index 000000000..3e189c252 --- /dev/null +++ b/src/pocketmine/block/TrappedChest.php @@ -0,0 +1,181 @@ +meta = $meta; + } + + public function canBeActivated(){ + return true; + } + + public function getHardness(){ + return 2.5; + } + + public function getName(){ + return "Trapped Chest"; + } + + public function getToolType(){ + return Tool::TYPE_AXE; + } + + protected function recalculateBoundingBox(){ + return new AxisAlignedBB( + $this->x + 0.0625, + $this->y, + $this->z + 0.0625, + $this->x + 0.9375, + $this->y + 0.9475, + $this->z + 0.9375 + ); + } + + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + $faces = [ + 0 => 4, + 1 => 2, + 2 => 5, + 3 => 3, + ]; + + $chest = null; + $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0]; + + for($side = 2; $side <= 5; ++$side){ + if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){ + continue; + }elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){ + continue; + } + $c = $this->getSide($side); + if($c instanceof Chest and $c->getDamage() === $this->meta){ + $tile = $this->getLevel()->getTile($c); + if($tile instanceof TileChest and !$tile->isPaired()){ + $chest = $tile; + break; + } + } + } + + $this->getLevel()->setBlock($block, $this, true, true); + $nbt = new CompoundTag("", [ + new Enum("Items", []), + new StringTag("id", Tile::CHEST), + new IntTag("x", $this->x), + new IntTag("y", $this->y), + new IntTag("z", $this->z) + ]); + $nbt->Items->setTagType(NBT::TAG_Compound); + + if($item->hasCustomName()){ + $nbt->CustomName = new StringTag("CustomName", $item->getCustomName()); + } + + if($item->hasCustomBlockData()){ + foreach($item->getCustomBlockData() as $key => $v){ + $nbt->{$key} = $v; + } + } + + $tile = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); + + if($chest instanceof TileChest and $tile instanceof TileChest){ + $chest->pairWith($tile); + $tile->pairWith($chest); + } + + return true; + } + + public function onBreak(Item $item){ + $t = $this->getLevel()->getTile($this); + if($t instanceof TileChest){ + $t->unpair(); + } + $this->getLevel()->setBlock($this, new Air(), true, true); + + return true; + } + + public function onActivate(Item $item, Player $player = null){ + if($player instanceof Player){ + $top = $this->getSide(1); + if($top->isTransparent() !== true){ + return true; + } + + $t = $this->getLevel()->getTile($this); + $chest = null; + if($t instanceof TileChest){ + $chest = $t; + }else{ + $nbt = new CompoundTag("", [ + new Enum("Items", []), + new StringTag("id", Tile::CHEST), + new IntTag("x", $this->x), + new IntTag("y", $this->y), + new IntTag("z", $this->z) + ]); + $nbt->Items->setTagType(NBT::TAG_Compound); + $chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); + } + + if(isset($chest->namedtag->Lock) and $chest->namedtag->Lock instanceof String){ + if($chest->namedtag->Lock->getValue() !== $item->getCustomName()){ + return true; + } + } + + if($player->isCreative()){ + return true; + } + $player->addWindow($chest->getInventory()); + } + + return true; + } + + public function getDrops(Item $item){ + return [ + [$this->id, 0, 1], + ]; + } +} diff --git a/src/pocketmine/block/WallSign.php b/src/pocketmine/block/WallSign.php index 1a09123fa..66064a8bc 100644 --- a/src/pocketmine/block/WallSign.php +++ b/src/pocketmine/block/WallSign.php @@ -22,6 +22,8 @@ namespace pocketmine\block; +use pocketmine\level\Level; + class WallSign extends SignPost{ protected $id = self::WALL_SIGN; @@ -31,6 +33,20 @@ class WallSign extends SignPost{ } public function onUpdate($type){ + $faces = [ + 2 => 3, + 3 => 2, + 4 => 5, + 5 => 4, + ]; + if($type === Level::BLOCK_UPDATE_NORMAL){ + if(isset($faces[$this->meta])) { + if ($this->getSide($faces[$this->meta])->getId() === self::AIR) { + $this->getLevel()->useBreakOn($this); + } + return Level::BLOCK_UPDATE_NORMAL; + } + } return false; } } \ No newline at end of file diff --git a/src/pocketmine/command/defaults/BanListCommand.php b/src/pocketmine/command/defaults/BanListCommand.php index 251a096d3..6fe8ba7b5 100644 --- a/src/pocketmine/command/defaults/BanListCommand.php +++ b/src/pocketmine/command/defaults/BanListCommand.php @@ -64,9 +64,9 @@ class BanListCommand extends VanillaCommand{ } if($args[0] === "ips"){ - $sender->sendMessage("commands.banlist.ips", [count($list)]); + $sender->sendMessage(new TranslationContainer("commands.banlist.ips", [count($list)])); }else{ - $sender->sendMessage("commands.banlist.players", [count($list)]); + $sender->sendMessage(new TranslationContainer("commands.banlist.players", [count($list)])); } $sender->sendMessage(substr($message, 0, -2)); diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index b02595962..170e8f0d6 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -57,15 +57,15 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ public $height = 1.8; public $eyeHeight = 1.62; + protected $skinName; protected $skin; - protected $isSlim = false; public function getSkinData(){ return $this->skin; } - public function isSkinSlim(){ - return $this->isSlim; + public function getSkinName(){ + return $this->skinName; } /** @@ -84,11 +84,11 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ /** * @param string $str - * @param bool $isSlim + * @param string $skinName */ - public function setSkin($str, $isSlim = false){ + public function setSkin($str, $skinName){ $this->skin = $str; - $this->isSlim = (bool) $isSlim; + $this->skinName = $skinName; } public function getInventory(){ @@ -112,7 +112,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ } if(isset($this->namedtag->Skin) and $this->namedtag->Skin instanceof CompoundTag){ - $this->setSkin($this->namedtag->Skin["Data"], $this->namedtag->Skin["Slim"] > 0); + $this->setSkin($this->namedtag->Skin["Data"], $this->namedtag->Skin["Name"]); } $this->uuid = UUID::fromData($this->getId(), $this->getSkinData(), $this->getNameTag()); @@ -195,7 +195,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if(strlen($this->getSkinData()) > 0){ $this->namedtag->Skin = new CompoundTag("Skin", [ "Data" => new StringTag("Data", $this->getSkinData()), - "Slim" => new ByteTag("Slim", $this->isSkinSlim() ? 1 : 0) + "Name" => new StringTag("Name", $this->getSkinName()) ]); } } @@ -210,7 +210,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if(!($this instanceof Player)){ - $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getName(), $this->isSlim, $this->skin, [$player]); + $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getName(), $this->skinName, $this->skin, [$player]); } $pk = new AddPlayerPacket(); diff --git a/src/pocketmine/event/player/PlayerQuitEvent.php b/src/pocketmine/event/player/PlayerQuitEvent.php index b8c4f63f4..37efeb4da 100644 --- a/src/pocketmine/event/player/PlayerQuitEvent.php +++ b/src/pocketmine/event/player/PlayerQuitEvent.php @@ -36,7 +36,7 @@ class PlayerQuitEvent extends PlayerEvent{ public function __construct(Player $player, $quitMessage, $autoSave = true){ $this->player = $player; $this->quitMessage = $quitMessage; - $this->autoSave = true; + $this->autoSave = $autoSave; } public function setQuitMessage($quitMessage){ @@ -55,4 +55,4 @@ class PlayerQuitEvent extends PlayerEvent{ $this->autoSave = (bool) $value; } -} \ No newline at end of file +} diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 12cd43882..dee23dd9c 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -385,7 +385,7 @@ abstract class BaseInventory implements Inventory{ } public function setMaxStackSize($size){ - $this->setMaxStackSize($size); + $this->maxStackSize = (int) $size; } public function open(Player $who){ diff --git a/src/pocketmine/inventory/ChestInventory.php b/src/pocketmine/inventory/ChestInventory.php index bfa764d43..20cf04fe1 100644 --- a/src/pocketmine/inventory/ChestInventory.php +++ b/src/pocketmine/inventory/ChestInventory.php @@ -23,7 +23,7 @@ namespace pocketmine\inventory; use pocketmine\level\Level; use pocketmine\network\Network; -use pocketmine\network\protocol\TileEventPacket; +use pocketmine\network\protocol\BlockEventPacket; use pocketmine\Player; use pocketmine\tile\Chest; @@ -44,7 +44,7 @@ class ChestInventory extends ContainerInventory{ parent::onOpen($who); if(count($this->getViewers()) === 1){ - $pk = new TileEventPacket(); + $pk = new BlockEventPacket(); $pk->x = $this->getHolder()->getX(); $pk->y = $this->getHolder()->getY(); $pk->z = $this->getHolder()->getZ(); @@ -58,7 +58,7 @@ class ChestInventory extends ContainerInventory{ public function onClose(Player $who){ if(count($this->getViewers()) === 1){ - $pk = new TileEventPacket(); + $pk = new BlockEventPacket(); $pk->x = $this->getHolder()->getX(); $pk->y = $this->getHolder()->getY(); $pk->z = $this->getHolder()->getZ(); @@ -70,4 +70,4 @@ class ChestInventory extends ContainerInventory{ } parent::onClose($who); } -} \ No newline at end of file +} diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index 381cbaeee..aac0d350d 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -21,8 +21,15 @@ namespace pocketmine\inventory; + use pocketmine\block\Planks; +use pocketmine\block\Quartz; +use pocketmine\block\Sandstone; +use pocketmine\block\Slab; +use pocketmine\block\Fence; use pocketmine\block\Stone; +use pocketmine\block\StoneBricks; +use pocketmine\block\StoneWall; use pocketmine\block\Wood; use pocketmine\block\Wood2; use pocketmine\item\Item; @@ -110,56 +117,245 @@ class CraftingManager{ "XX" ))->setIngredient("X", Item::get(Item::STRING, 0, 4))); - $this->registerRecipe((new ShapelessRecipe(Item::get(Item::TORCH, 0, 4)))->addIngredient(Item::get(Item::COAL, 0, 1))->addIngredient(Item::get(Item::STICK, 0, 1))); - $this->registerRecipe((new ShapelessRecipe(Item::get(Item::TORCH, 0, 4)))->addIngredient(Item::get(Item::COAL, 1, 1))->addIngredient(Item::get(Item::STICK, 0, 1))); - $this->registerRecipe((new ShapelessRecipe(Item::get(Item::SUGAR, 0, 1)))->addIngredient(Item::get(Item::SUGARCANE, 0, 1))); + $this->registerRecipe((new ShapedRecipe(Item::get(Item::TORCH, 0, 4), + "C ", + "S" + ))->setIngredient("C", Item::get(Item::COAL,0,1))->setIngredient("S", Item::get(Item::STICK,0,1))); + $this->registerRecipe((new ShapedRecipe(Item::get(Item::TORCH, 0, 4), + "C ", + "S" + ))->setIngredient("C", Item::get(Item::COAL, 1, 1))->setIngredient("S", Item::get(Item::STICK, 0, 1))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::BED, 0, 1)))->addIngredient(Item::get(Item::WOOL, null, 3))->addIngredient(Item::get(Item::WOODEN_PLANK, null, 3))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::CHEST, 0, 1)))->addIngredient(Item::get(Item::WOODEN_PLANK, null, 8))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE, 0, 3)))->addIngredient(Item::get(Item::STICK, 0, 2))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::OAK, 4))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE, Planks::SPRUCE, 3)))->addIngredient(Item::get(Item::STICK, 0, 2))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::SPRUCE, 4))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE, Planks::BIRCH, 3)))->addIngredient(Item::get(Item::STICK, 0, 2))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::BIRCH, 4))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE, Planks::JUNGLE, 3)))->addIngredient(Item::get(Item::STICK, 0, 2))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::JUNGLE, 4))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE, Planks::ACACIA, 3)))->addIngredient(Item::get(Item::STICK, 0, 2))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::ACACIA, 4))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE, Planks::DARK_OAK, 3)))->addIngredient(Item::get(Item::STICK, 0, 2))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::DARK_OAK, 4))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE_GATE, 0, 1)))->addIngredient(Item::get(Item::STICK, 0, 4))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::OAK, 2))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE_GATE_SPRUCE, 0, 1)))->addIngredient(Item::get(Item::STICK, 0, 4))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::SPRUCE, 2))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE_GATE_BIRCH, 0, 1)))->addIngredient(Item::get(Item::STICK, 0, 4))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::BIRCH, 2))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE_GATE_JUNGLE, 0, 1)))->addIngredient(Item::get(Item::STICK, 0, 4))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::JUNGLE, 2))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE_GATE_DARK_OAK, 0, 1)))->addIngredient(Item::get(Item::STICK, 0, 4))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::DARK_OAK, 2))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FENCE_GATE_ACACIA, 0, 1)))->addIngredient(Item::get(Item::STICK, 0, 4))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::ACACIA, 2))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::FURNACE, 0, 1)))->addIngredient(Item::get(Item::COBBLESTONE, 0, 8))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::GLASS_PANE, 0, 16)))->addIngredient(Item::get(Item::GLASS, 0, 6))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::LADDER, 0, 2)))->addIngredient(Item::get(Item::STICK, 0, 7))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::NETHER_REACTOR, 0, 1)))->addIngredient(Item::get(Item::DIAMOND, 0, 3))->addIngredient(Item::get(Item::IRON_INGOT, 0, 6))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::TRAPDOOR, 0, 2)))->addIngredient(Item::get(Item::WOODEN_PLANK, null, 6))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::WOODEN_DOOR, 0, 1)))->addIngredient(Item::get(Item::WOODEN_PLANK, null, 6))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::WOODEN_STAIRS, 0, 4)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::OAK, 6))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::WOOD_SLAB, Planks::OAK, 6)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::OAK, 3))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::SPRUCE_WOOD_STAIRS, 0, 4)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::SPRUCE, 6))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::WOOD_SLAB, Planks::SPRUCE, 6)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::SPRUCE, 3))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::BIRCH_WOOD_STAIRS, 0, 4)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::BIRCH, 6))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::WOOD_SLAB, Planks::BIRCH, 6)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::BIRCH, 3))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::JUNGLE_WOOD_STAIRS, 0, 4)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::JUNGLE, 6))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::WOOD_SLAB, Planks::JUNGLE, 6)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::JUNGLE, 3))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::ACACIA_WOOD_STAIRS, 0, 4)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::ACACIA, 6))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::WOOD_SLAB, Planks::ACACIA, 6)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::ACACIA, 3))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::DARK_OAK_WOOD_STAIRS, 0, 4)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::DARK_OAK, 6))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::WOOD_SLAB, Planks::DARK_OAK, 6)))->addIngredient(Item::get(Item::WOODEN_PLANK, Planks::DARK_OAK, 3))); + $this->registerRecipe((new ShapedRecipe(Item::get(Item::SUGAR, 0, 1), + "S" + ))->setIngredient("S", Item::get(Item::SUGARCANE, 0, 1))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::BUCKET, 0, 1)))->addIngredient(Item::get(Item::IRON_INGOT, 0, 3))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::CLOCK, 0, 1)))->addIngredient(Item::get(Item::GOLD_INGOT, 0, 4))->addIngredient(Item::get(Item::REDSTONE_DUST, 0, 1))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::COMPASS, 0, 1)))->addIngredient(Item::get(Item::IRON_INGOT, 0, 4))->addIngredient(Item::get(Item::REDSTONE_DUST, 0, 1))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::TNT, 0, 1)))->addIngredient(Item::get(Item::GUNPOWDER, 0, 5))->addIngredient(Item::get(Item::SAND, null, 4))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::BOWL, 0, 4)))->addIngredient(Item::get(Item::WOODEN_PLANKS, null, 3))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::MINECART, 0, 1)))->addIngredient(Item::get(Item::IRON_INGOT, 0, 5))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::BOOK, 0, 1)))->addIngredient(Item::get(Item::PAPER, 0, 3))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::BOOKSHELF, 0, 1)))->addIngredient(Item::get(Item::WOODEN_PLANK, null, 6))->addIngredient(Item::get(Item::BOOK, 0, 3))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::PAINTING, 0, 1)))->addIngredient(Item::get(Item::STICK, 0, 8))->addIngredient(Item::get(Item::WOOL, null, 1))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::PAPER, 0, 1)))->addIngredient(Item::get(Item::SUGARCANE, 0, 3))); - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::SIGN, 0, 3)))->addIngredient(Item::get(Item::STICK, 0, 1))->addIngredient(Item::get(Item::WOODEN_PLANKS, null, 6))); //TODO: check if it gives one sign or three - $this->registerRecipe((new BigShapelessRecipe(Item::get(Item::IRON_BARS, 0, 16)))->addIngredient(Item::get(Item::IRON_INGOT, 0, 6))); + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::BED, 0, 1), + "WWW", + "PPP" + ))->setIngredient("W", Item::get(Item::WOOL, null, 3))->setIngredient("P", Item::get(Item::WOODEN_PLANK, null, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::CHEST, 0, 1), + "PPP", + "P P", + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, null, 8))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE, 0, 3), + "PSP", + "PSP" + ))->setIngredient("S", Item::get(Item::STICK, 0, 2))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::OAK, 4))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE, Planks::SPRUCE, 3), + "PSP", + "PSP" + ))->setIngredient("S", Item::get(Item::STICK, 0, 2))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::SPRUCE, 4))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE, Planks::BIRCH, 3), + "PSP", + "PSP" + ))->setIngredient("S", Item::get(Item::STICK, 0, 2))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::BIRCH, 4))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE, Planks::JUNGLE, 3), + "PSP", + "PSP" + ))->setIngredient("S", Item::get(Item::STICK, 0, 2))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::JUNGLE, 4))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE, Planks::ACACIA, 3), + "PSP", + "PSP" + ))->setIngredient("S", Item::get(Item::STICK, 0, 2))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::ACACIA, 4))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE, Planks::DARK_OAK, 3), + "PSP", + "PSP" + ))->setIngredient("S", Item::get(Item::STICK, 0, 2))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::DARK_OAK, 4))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE_GATE, 0, 1), + "SPS", + "SPS" + ))->setIngredient("S", Item::get(Item::STICK, 0, 4))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::OAK, 2))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE_GATE_SPRUCE, 0, 1), + "SPS", + "SPS" + ))->setIngredient("S", Item::get(Item::STICK, 0, 4))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::SPRUCE, 2))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE_GATE_BIRCH, 0, 1), + "SPS", + "SPS" + ))->setIngredient("S", Item::get(Item::STICK, 0, 4))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::BIRCH, 2))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE_GATE_JUNGLE, 0, 1), + "SPS", + "SPS" + ))->setIngredient("S", Item::get(Item::STICK, 0, 4))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::JUNGLE, 2))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE_GATE_DARK_OAK, 0, 1), + "SPS", + "SPS" + ))->setIngredient("S", Item::get(Item::STICK, 0, 4))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::DARK_OAK, 2))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FENCE_GATE_ACACIA, 0, 1), + "SPS", + "SPS" + ))->setIngredient("S", Item::get(Item::STICK, 0, 4))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::ACACIA, 2))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::FURNACE, 0, 1), + "CCC", + "C C", + "CCC" + ))->setIngredient("C", Item::get(Item::COBBLESTONE, 0, 8))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::GLASS_PANE, 0, 16), + "GGG", + "GGG" + ))->setIngredient("G", Item::get(Item::GLASS, 0, 6))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::LADDER, 0, 2), + "S S", + "SSS", + "S S" + ))->setIngredient("S", Item::get(Item::STICK, 0, 7))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::TRAPDOOR, 0, 2), + "PPP", + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, null, 6))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::WOODEN_DOOR, 0, 1), + "PP", + "PP", + "PP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, null, 6))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::WOODEN_STAIRS, 0, 4), + " P", + " PP", + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::OAK, 6))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::WOOD_SLAB, Planks::OAK, 6), + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::OAK, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::SPRUCE_WOOD_STAIRS, 0, 4), + " P", + " PP", + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::SPRUCE, 6))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::WOOD_SLAB, Planks::SPRUCE, 6), + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::SPRUCE, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::BIRCH_WOOD_STAIRS, 0, 4), + " P", + " PP", + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::BIRCH, 6))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::WOOD_SLAB, Planks::BIRCH, 6), + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::BIRCH, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::JUNGLE_WOOD_STAIRS, 0, 4), + "P", + "PP", + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::JUNGLE, 6))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::WOOD_SLAB, Planks::JUNGLE, 6), + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::JUNGLE, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::ACACIA_WOOD_STAIRS, 0, 4), + " P", + " PP", + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::ACACIA, 6))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::WOOD_SLAB, Planks::ACACIA, 6), + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::ACACIA, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::DARK_OAK_WOOD_STAIRS, 0, 4), + " P", + " PP", + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::DARK_OAK, 6))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::WOOD_SLAB, Planks::DARK_OAK, 6), + "PPP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, Planks::DARK_OAK, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::BUCKET, 0, 1), + "I I", + " I" + ))->setIngredient("I", Item::get(Item::IRON_INGOT, 0, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::CLOCK, 0, 1), + " G", + "GR", + " G" + ))->setIngredient("G", Item::get(Item::GOLD_INGOT, 0, 4))->setIngredient("R", Item::get(Item::REDSTONE_DUST, 0, 1))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::COMPASS, 0, 1), + " I ", + "IRI", + " I" + ))->setIngredient("I", Item::get(Item::IRON_INGOT, 0, 4))->setIngredient("R", Item::get(Item::REDSTONE_DUST, 0, 1))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::TNT, 0, 1), + "GSG", + "SGS", + "GSG" + ))->setIngredient("G", Item::get(Item::GUNPOWDER, 0, 5))->setIngredient("S", Item::get(Item::SAND, null, 4))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::BOWL, 0, 4), + "P P", + " P" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANKS, null, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::MINECART, 0, 1), + "I I", + "III" + ))->setIngredient("I", Item::get(Item::IRON_INGOT, 0, 5))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::BOOK, 0, 1), + "P P", + " P " + ))->setIngredient("P", Item::get(Item::PAPER, 0, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::BOOKSHELF, 0, 1), + "PBP", + "PBP", + "PBP" + ))->setIngredient("P", Item::get(Item::WOODEN_PLANK, null, 6))->setIngredient("B", Item::get(Item::BOOK, 0, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::PAINTING, 0, 1), + "SSS", + "SWS", + "SSS" + ))->setIngredient("S", Item::get(Item::STICK, 0, 8))->setIngredient("W", Item::get(Item::WOOL, null, 1))); + + $this->registerRecipe((new ShapedRecipe(Item::get(Item::PAPER, 0, 3), + "SS", + "S" + ))->setIngredient("S", Item::get(Item::SUGARCANE, 0, 3))); + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::SIGN, 0, 3), + "PPP", + "PPP", + " S" + ))->setIngredient("S", Item::get(Item::STICK, 0, 1))->setIngredient("P", Item::get(Item::WOODEN_PLANKS, null, 6))); //TODO: check if it gives one sign or three + + $this->registerRecipe((new BigShapedRecipe(Item::get(Item::IRON_BARS, 0, 16), + "III", + "III", + "III" + ))->setIngredient("I", Item::get(Item::IRON_INGOT, 0, 9))); } protected function registerFurnace(){ @@ -185,38 +381,142 @@ class CraftingManager{ $this->registerRecipe(new FurnaceRecipe(Item::get(Item::HARDENED_CLAY, 0, 1), Item::get(Item::CLAY_BLOCK, 0, 1))); } - protected function registerStonecutter(){ - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::QUARTZ_BLOCK, 0, 1)))->addIngredient(Item::get(Item::QUARTZ, 0, 4))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::BRICK_STAIRS, 0, 4)))->addIngredient(Item::get(Item::BRICKS_BLOCK, 0, 6))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::BRICKS_BLOCK, 0, 1)))->addIngredient(Item::get(Item::BRICK, 0, 4))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::SLAB, 4, 6)))->addIngredient(Item::get(Item::BRICKS_BLOCK, 0, 3))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::QUARTZ_BLOCK, 1, 1)))->addIngredient(Item::get(Item::SLAB, 6, 2))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::SLAB, 3, 6)))->addIngredient(Item::get(Item::COBBLESTONE, 0, 3))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::COBBLESTONE_WALL, 0, 6)))->addIngredient(Item::get(Item::COBBLESTONE, 0, 6))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::COBBLESTONE_WALL, 1, 6)))->addIngredient(Item::get(Item::MOSS_STONE, 0, 6))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::NETHER_BRICKS, 0, 1)))->addIngredient(Item::get(Item::NETHER_BRICK, 0, 4))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::NETHER_BRICKS_STAIRS, 0, 4)))->addIngredient(Item::get(Item::NETHER_BRICKS, 0, 6))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::QUARTZ_BLOCK, 2, 2)))->addIngredient(Item::get(Item::QUARTZ_BLOCK, 0, 2))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::SLAB, 6, 6)))->addIngredient(Item::get(Item::QUARTZ_BLOCK, 0, 3))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::SANDSTONE_STAIRS, 0, 4)))->addIngredient(Item::get(Item::SANDSTONE, 0, 6))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::SANDSTONE, 0, 1)))->addIngredient(Item::get(Item::SAND, 0, 4))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::SANDSTONE, 2, 4)))->addIngredient(Item::get(Item::SANDSTONE, 0, 4))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::SANDSTONE, 1, 1)))->addIngredient(Item::get(Item::SLAB, 1, 2))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::SLAB, 1, 6)))->addIngredient(Item::get(Item::SANDSTONE, 0, 3))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::STONE_BRICK_STAIRS, 0, 4)))->addIngredient(Item::get(Item::STONE_BRICK, null, 6))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::STONE_BRICK, 0, 4)))->addIngredient(Item::get(Item::STONE, null, 4))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::STONE_BRICK, 3, 1)))->addIngredient(Item::get(Item::SLAB, 5, 2))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::STONE_BRICK, 1, 1)))->addIngredient(Item::get(Item::STONE_BRICK, 0, 1))->addIngredient(Item::get(Item::VINES, 0, 1))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::SLAB, 5, 6)))->addIngredient(Item::get(Item::STONE_BRICK, null, 3))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::SLAB, 0, 6)))->addIngredient(Item::get(Item::STONE, null, 3))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::COBBLESTONE_STAIRS, 0, 4)))->addIngredient(Item::get(Item::COBBLESTONE, 0, 6))); + protected function registerStonecutter(){ + $shapes = [ + "slab" => [ + " ", + "XXX", + " " + ], + "stairs" => [ + "X ", + "XX ", + "XXX" + ], + "wall/fence" => [ + "XXX", + "XXX", + " " + ], + "blockrecipe1" => [ + "XX", + "XX" + ], + "blockrecipe2X1" => [ + " ", + " X ", + " X " + ], + "blockrecipe2X2" => [ + "AB", + "BA" + ], + "blockrecipe1X2" => [ + " ", + "AB" + ] + ]; - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::STONE, Stone::POLISHED_GRANITE, 4)))->addIngredient(Item::get(Item::STONE, Stone::GRANITE, 4))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::STONE, Stone::POLISHED_DIORITE, 4)))->addIngredient(Item::get(Item::STONE, Stone::DIORITE, 4))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::STONE, Stone::POLISHED_ANDESITE, 4)))->addIngredient(Item::get(Item::STONE, Stone::ANDESITE, 4))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::STONE, Stone::GRANITE, 1)))->addIngredient(Item::get(Item::STONE, Stone::DIORITE, 1))->addIngredient(Item::get(Item::QUARTZ, 0, 1))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::STONE, Stone::DIORITE, 2)))->addIngredient(Item::get(Item::COBBLESTONE, 0, 2))->addIngredient(Item::get(Item::QUARTZ, 0, 2))); - $this->registerRecipe((new StonecutterShapelessRecipe(Item::get(Item::STONE, Stone::ANDESITE, 2)))->addIngredient(Item::get(Item::COBBLESTONE, 0, 1))->addIngredient(Item::get(Item::STONE, Stone::DIORITE, 1))); + $buildRecipes = []; + + // Single ingedient stone cutter recipes: + $RESULT_ITEMID = 0; $RESULT_META = 1; $INGREDIENT_ITEMID = 2; $INGREDIENT_META = 3; $RECIPE_SHAPE = 4;$RESULT_AMOUNT = 5; + $recipes = [ + //RESULT_ITEM_ID RESULT_META INGREDIENT_ITEMID INGREDIENT_META RECIPE_SHAPE RESULT_AMOUNT + [Item::SLAB, Slab::STONE, Item::STONE, Stone::NORMAL, "slab", 6], + [Item::SLAB, Slab::COBBLESTONE, Item::COBBLESTONE, 0, "slab", 6], + [Item::SLAB, Slab::SANDSTONE, Item::SANDSTONE, 0, "slab", 6], + [Item::SLAB, Slab::BRICK, Item::BRICK, 0, "slab", 6], + [Item::SLAB, Slab::STONE_BRICK, Item::STONE_BRICK, StoneBricks::NORMAL,"slab", 6], + [Item::SLAB, Slab::NETHER_BRICK, Item::NETHER_BRICK_BLOCK, 0, "slab", 6], + [Item::SLAB, Slab::QUARTZ, Item::QUARTZ_BLOCK, 0, "slab", 6], + [Item::COBBLESTONE_STAIRS, 0, Item::COBBLESTONE, 0, "stairs", 4], + [Item::SANDSTONE_STAIRS, 0, Item::SANDSTONE, 0, "stairs", 4], + [Item::STONE_BRICK_STAIRS, 0, Item::STONE_BRICK, StoneBricks::NORMAL,"stairs", 4], + [Item::BRICK_STAIRS, 0, Item::BRICKS_BLOCK, 0, "stairs", 4], + [Item::NETHER_BRICKS_STAIRS,0, Item::NETHER_BRICK_BLOCK, 0, "stairs", 4], + [Item::COBBLESTONE_WALL, StoneWall::NONE_MOSSY_WALL, Item::COBBLESTONE, 0, "wall/fence", 6], + [Item::COBBLESTONE_WALL, StoneWall::MOSSY_WALL, Item::MOSSY_STONE, 0, "wall/fence", 6], + [Item::NETHER_BRICK_FENCE, 0, Item::NETHER_BRICK_BLOCK, 0, "wall/fence", 6], + [Item::NETHER_BRICKS, 0, Item::NETHER_BRICK, 0, "blockrecipe1", 1], + [Item::SANDSTONE, SandStone::NORMAL, Item::SAND, 0, "blockrecipe1", 1], + [Item::SANDSTONE, Sandstone::CHISELED, Item::SANDSTONE, SandStone::NORMAL, "blockrecipe1", 4], + [Item::STONE_BRICK, StoneBricks::NORMAL, Item::STONE, Stone::NORMAL, "blockrecipe1", 4], + [Item::STONE_BRICK, StoneBricks::NORMAL, Item::STONE, Stone::POLISHED_GRANITE,"blockrecipe1", 4], + [Item::STONE_BRICK, StoneBricks::NORMAL, Item::STONE, Stone::POLISHED_DIORITE,"blockrecipe1", 4], + [Item::STONE_BRICK, StoneBricks::NORMAL, Item::STONE, Stone::POLISHED_ANDESITE,"blockrecipe1",4], + [Item::STONE, Stone::POLISHED_GRANITE, Item::STONE, Stone::GRANITE, "blockrecipe1", 4], + [Item::STONE, Stone::POLISHED_DIORITE, Item::STONE, Stone::DIORITE, "blockrecipe1", 4], + [Item::STONE, Stone::POLISHED_ANDESITE, Item::STONE, Stone::ANDESITE, "blockrecipe1", 4], + [Item::QUARTZ_BLOCK, Quartz::QUARTZ_NORMAL, Item::QUARTZ, Stone::ANDESITE, "blockrecipe1", 4], + [Item::QUARTZ_BLOCK, Quartz::QUARTZ_CHISELED, Item::SLAB, Slab::QUARTZ, "blockrecipe2X1", 1], + [Item::SANDSTONE, SandStone::CHISELED, Item::SLAB, Slab::SANDSTONE, "blockrecipe2X1", 1], + [Item::STONE_BRICK, StoneBricks::CHISELED, Item::SLAB, Slab::STONE_BRICK, "blockrecipe2X1", 1], + ]; + foreach ($recipes as $recipe){ + $buildRecipes[] = $this->createOneIngedientRecipe($shapes[$recipe[$RECIPE_SHAPE]], $recipe[$RESULT_ITEMID], $recipe[$RESULT_META], $recipe[$RESULT_AMOUNT], $recipe[$INGREDIENT_ITEMID], $recipe[$INGREDIENT_META], "X", "Stonecutter"); + } + + // Multi-ingredient stone recipes: + $buildRecipes[] = ((new StonecutterShapedRecipe(Item::get(Item::STONE, Stone::GRANITE, 1), + ...$shapes["blockrecipe1X2"] + ))->setIngredient("A", Item::get(Item::STONE, Stone::DIORITE, 1))->setIngredient("B", Item::get(Item::QUARTZ, Quartz::QUARTZ_NORMAL, 1))); + $buildRecipes[] = ((new StonecutterShapedRecipe(Item::get(Item::STONE, Stone::DIORITE, 2), + ...$shapes["blockrecipe2X2"] + ))->setIngredient("A", Item::get(Item::COBBLESTONE, 0, 2))->setIngredient("B", Item::get(Item::QUARTZ, 0, 2))); + $buildRecipes[] = ((new StonecutterShapedRecipe(Item::get(Item::STONE, Stone::ANDESITE, 2), + ...$shapes["blockrecipe1X2"] + ))->setIngredient("A", Item::get(Item::COBBLESTONE, 0, 1))->setIngredient("B", Item::get(Item::STONE, Stone::DIORITE, 1))); + $buildRecipes[] = ((new StonecutterShapedRecipe(Item::get(Item::STONE_BRICK, StoneBricks::MOSSY, 1), + ...$shapes["blockrecipe1X2"] + ))->setIngredient("A", Item::get(Item::STONE_BRICK, StoneBricks::NORMAL, 1))->setIngredient("B", Item::get(Item::VINES, 0, 1))); + + $this->sortAndAddRecipesArray($buildRecipes); + } + + private function sortAndAddRecipesArray(&$recipes){ + // Sort the recipes based on the result item name with the bubblesort algoritm. + for ($i = 0; $i < count($recipes); ++$i){ + $current = $recipes[$i]; + $result = $current->getResult(); + for ($j = count($recipes)-1; $j > $i; --$j) + { + if ($this->sort($result, $recipes[$j]->getResult())>0){ + $swap = $current; + $current = $recipes[$j]; + $recipes[$j] = $swap; + $result = $current->getResult(); + } + } + $this->registerRecipe($current); + } + } + + private function createOneIngedientRecipe($recipeshape, $resultitem, $resultitemmeta, $resultitemamound, $ingedienttype, $ingredientmeta, $ingredientname, $inventoryType = ""){ + $ingredientamount = 0; + $height = 0; + // count how many of the ingredient are in the recipe and check height for big or small recipe. + foreach ($recipeshape as $line){ + $height += 1; + $width = strlen($line); + $ingredientamount += substr_count($line, $ingredientname); + } + $recipe = null; + if ($height < 3){ + // Process small recipe + $fullClassName = "pocketmine\\inventory\\".$inventoryType."ShapedRecipe";// $ShapeClass."ShapedRecipe"; + $recipe = ((new $fullClassName(Item::get($resultitem, $resultitemmeta, $resultitemamound), + ...$recipeshape + ))->setIngredient($ingredientname, Item::get($ingedienttype, $ingredientmeta, $ingredientamount))); + } + else{ + // Process big recipe + $fullClassName = "pocketmine\\inventory\\".$inventoryType."BigShapedRecipe"; + $recipe = ((new $fullClassName(Item::get($resultitem, $resultitemmeta, $resultitemamound), + ...$recipeshape + ))->setIngredient($ingredientname, Item::get($ingedienttype, $ingredientmeta, $ingredientamount))); + } + return $recipe; } protected function registerFood(){ diff --git a/src/pocketmine/inventory/DoubleChestInventory.php b/src/pocketmine/inventory/DoubleChestInventory.php index 9cfd9ad93..34b0b7bf8 100644 --- a/src/pocketmine/inventory/DoubleChestInventory.php +++ b/src/pocketmine/inventory/DoubleChestInventory.php @@ -24,7 +24,7 @@ namespace pocketmine\inventory; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\network\Network; -use pocketmine\network\protocol\TileEventPacket; +use pocketmine\network\protocol\BlockEventPacket; use pocketmine\Player; use pocketmine\tile\Chest; @@ -99,7 +99,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ parent::onOpen($who); if(count($this->getViewers()) === 1){ - $pk = new TileEventPacket(); + $pk = new BlockEventPacket(); $pk->x = $this->right->getHolder()->getX(); $pk->y = $this->right->getHolder()->getY(); $pk->z = $this->right->getHolder()->getZ(); @@ -113,7 +113,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ public function onClose(Player $who){ if(count($this->getViewers()) === 1){ - $pk = new TileEventPacket(); + $pk = new BlockEventPacket(); $pk->x = $this->right->getHolder()->getX(); $pk->y = $this->right->getHolder()->getY(); $pk->z = $this->right->getHolder()->getZ(); @@ -139,4 +139,4 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ public function getRightSide(){ return $this->right; } -} \ No newline at end of file +} diff --git a/src/pocketmine/inventory/StonecutterShapelessRecipe.php b/src/pocketmine/inventory/StonecutterBigShapedRecipe.php similarity index 92% rename from src/pocketmine/inventory/StonecutterShapelessRecipe.php rename to src/pocketmine/inventory/StonecutterBigShapedRecipe.php index e29e34c86..a1cb800a3 100644 --- a/src/pocketmine/inventory/StonecutterShapelessRecipe.php +++ b/src/pocketmine/inventory/StonecutterBigShapedRecipe.php @@ -21,6 +21,6 @@ namespace pocketmine\inventory; -class StonecutterShapelessRecipe extends ShapelessRecipe{ +class StonecutterBigShapedRecipe extends ShapedRecipe{ } \ No newline at end of file diff --git a/src/pocketmine/inventory/StonecutterShapedRecipe.php b/src/pocketmine/inventory/StonecutterShapedRecipe.php new file mode 100644 index 000000000..6fd1d7c61 --- /dev/null +++ b/src/pocketmine/inventory/StonecutterShapedRecipe.php @@ -0,0 +1,26 @@ +block = Block::get(Item::FLOWER_POT_BLOCK); + parent::__construct(self::FLOWER_POT, 0, $count, "Flower Pot"); + } +} \ No newline at end of file diff --git a/src/pocketmine/item/GlowstoneDust.php b/src/pocketmine/item/GlowstoneDust.php new file mode 100644 index 000000000..67e10f06a --- /dev/null +++ b/src/pocketmine/item/GlowstoneDust.php @@ -0,0 +1,30 @@ +name = $this->block->getName(); } } - + public function setCompoundTag($tags){ if($tags instanceof CompoundTag){ $this->setNamedTag($tags); @@ -953,7 +1141,7 @@ class Item{ $this->tags = $tags; $this->cachedNBT = null; } - + return $this; } @@ -1197,7 +1385,7 @@ class Item{ return null; } - + public function getNamedTag(){ if(!$this->hasCompoundTag()){ return null; diff --git a/src/pocketmine/item/Leather.php b/src/pocketmine/item/Leather.php new file mode 100644 index 000000000..56a17dcfd --- /dev/null +++ b/src/pocketmine/item/Leather.php @@ -0,0 +1,30 @@ +setOreTypes([ new object\OreType(new CoalOre(), 20, 16, 0, 128), - new object\OreType(New IronOre(), 20, 8, 0, 64), + new object\OreType(new IronOre(), 20, 8, 0, 64), new object\OreType(new RedstoneOre(), 8, 7, 0, 16), new object\OreType(new LapisOre(), 1, 6, 0, 32), new object\OreType(new GoldOre(), 2, 8, 0, 32), diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 4e8951d6c..8099bd32f 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -43,7 +43,7 @@ use pocketmine\network\protocol\DropItemPacket; use pocketmine\network\protocol\FullChunkDataPacket; use pocketmine\network\protocol\Info; use pocketmine\network\protocol\SetEntityLinkPacket; -use pocketmine\network\protocol\TileEntityDataPacket; +use pocketmine\network\protocol\BlockEntityDataPacket; use pocketmine\network\protocol\EntityEventPacket; use pocketmine\network\protocol\ExplodePacket; use pocketmine\network\protocol\HurtArmorPacket; @@ -71,9 +71,10 @@ use pocketmine\network\protocol\SetSpawnPositionPacket; use pocketmine\network\protocol\SetTimePacket; use pocketmine\network\protocol\StartGamePacket; use pocketmine\network\protocol\TakeItemEntityPacket; -use pocketmine\network\protocol\TileEventPacket; +use pocketmine\network\protocol\BlockEventPacket; use pocketmine\network\protocol\UpdateBlockPacket; use pocketmine\network\protocol\UseItemPacket; +use pocketmine\network\protocol\SetPlayerGameTypePacket; use pocketmine\network\protocol\PlayerListPacket; use pocketmine\Player; use pocketmine\Server; @@ -302,7 +303,7 @@ class Network{ $this->registerPacket(ProtocolInfo::ADD_PAINTING_PACKET, AddPaintingPacket::class); $this->registerPacket(ProtocolInfo::EXPLODE_PACKET, ExplodePacket::class); $this->registerPacket(ProtocolInfo::LEVEL_EVENT_PACKET, LevelEventPacket::class); - $this->registerPacket(ProtocolInfo::TILE_EVENT_PACKET, TileEventPacket::class); + $this->registerPacket(ProtocolInfo::BLOCK_EVENT_PACKET, BlockEventPacket::class); $this->registerPacket(ProtocolInfo::ENTITY_EVENT_PACKET, EntityEventPacket::class); $this->registerPacket(ProtocolInfo::MOB_EQUIPMENT_PACKET, MobEquipmentPacket::class); $this->registerPacket(ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET, MobArmorEquipmentPacket::class); @@ -326,9 +327,10 @@ class Network{ $this->registerPacket(ProtocolInfo::CRAFTING_DATA_PACKET, CraftingDataPacket::class); $this->registerPacket(ProtocolInfo::CRAFTING_EVENT_PACKET, CraftingEventPacket::class); $this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class); - $this->registerPacket(ProtocolInfo::TILE_ENTITY_DATA_PACKET, TileEntityDataPacket::class); + $this->registerPacket(ProtocolInfo::BLOCK_ENTITY_DATA_PACKET, BlockEntityDataPacket::class); $this->registerPacket(ProtocolInfo::FULL_CHUNK_DATA_PACKET, FullChunkDataPacket::class); $this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class); + $this->registerPacket(ProtocolInfo::SET_PLAYER_GAMETYPE_PACKET, SetPlayerGameTypePacket::class); $this->registerPacket(ProtocolInfo::PLAYER_LIST_PACKET, PlayerListPacket::class); } } diff --git a/src/pocketmine/network/protocol/TileEntityDataPacket.php b/src/pocketmine/network/protocol/BlockEntityDataPacket.php similarity index 89% rename from src/pocketmine/network/protocol/TileEntityDataPacket.php rename to src/pocketmine/network/protocol/BlockEntityDataPacket.php index 65f04b738..668da2eea 100644 --- a/src/pocketmine/network/protocol/TileEntityDataPacket.php +++ b/src/pocketmine/network/protocol/BlockEntityDataPacket.php @@ -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/ - * + * * */ @@ -24,8 +24,8 @@ namespace pocketmine\network\protocol; #include -class TileEntityDataPacket extends DataPacket{ - const NETWORK_ID = Info::TILE_ENTITY_DATA_PACKET; +class BlockEntityDataPacket extends DataPacket{ + const NETWORK_ID = Info::BLOCK_ENTITY_DATA_PACKET; public $x; public $y; diff --git a/src/pocketmine/network/protocol/TileEventPacket.php b/src/pocketmine/network/protocol/BlockEventPacket.php similarity index 89% rename from src/pocketmine/network/protocol/TileEventPacket.php rename to src/pocketmine/network/protocol/BlockEventPacket.php index b46d2b5ec..1399cfc4d 100644 --- a/src/pocketmine/network/protocol/TileEventPacket.php +++ b/src/pocketmine/network/protocol/BlockEventPacket.php @@ -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/ - * + * * */ @@ -24,8 +24,8 @@ namespace pocketmine\network\protocol; #include -class TileEventPacket extends DataPacket{ - const NETWORK_ID = Info::TILE_EVENT_PACKET; +class BlockEventPacket extends DataPacket{ + const NETWORK_ID = Info::BLOCK_EVENT_PACKET; public $x; public $y; @@ -46,4 +46,4 @@ class TileEventPacket extends DataPacket{ $this->putInt($this->case2); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php index 244aba979..43c4d1c34 100644 --- a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php @@ -30,12 +30,14 @@ class ContainerSetSlotPacket extends DataPacket{ public $windowid; public $slot; + public $hotbarSlot; /** @var Item */ public $item; public function decode(){ $this->windowid = $this->getByte(); $this->slot = $this->getShort(); + $this->hotboarSlot = $this->getShort(); $this->item = $this->getSlot(); } @@ -43,6 +45,7 @@ class ContainerSetSlotPacket extends DataPacket{ $this->reset(); $this->putByte($this->windowid); $this->putShort($this->slot); + $this->putShort($this->hotbarSlot); $this->putSlot($this->item); } diff --git a/src/pocketmine/network/protocol/CraftingDataPacket.php b/src/pocketmine/network/protocol/CraftingDataPacket.php index 71dfa577c..e43f766e9 100644 --- a/src/pocketmine/network/protocol/CraftingDataPacket.php +++ b/src/pocketmine/network/protocol/CraftingDataPacket.php @@ -76,8 +76,8 @@ class CraftingDataPacket extends DataPacket{ $stream->putInt($recipe->getWidth()); $stream->putInt($recipe->getHeight()); - for($z = 0; $z < $recipe->getWidth(); ++$z){ - for($x = 0; $x < $recipe->getHeight(); ++$x){ + for($z = 0; $z < $recipe->getHeight(); ++$z){ + for($x = 0; $x < $recipe->getWidth(); ++$x){ $stream->putSlot($recipe->getIngredient($x, $z)); } } diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index e22c2dc1d..3f0bdd7d6 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -30,7 +30,7 @@ interface Info{ /** * Actual Minecraft: PE protocol version */ - const CURRENT_PROTOCOL = 34; + const CURRENT_PROTOCOL = 38; const LOGIN_PACKET = 0x8f; const PLAY_STATUS_PACKET = 0x90; @@ -52,7 +52,7 @@ interface Info{ const ADD_PAINTING_PACKET = 0xa0; const EXPLODE_PACKET = 0xa1; const LEVEL_EVENT_PACKET = 0xa2; - const TILE_EVENT_PACKET = 0xa3; + const BLOCK_EVENT_PACKET = 0xa3; const ENTITY_EVENT_PACKET = 0xa4; const MOB_EFFECT_PACKET = 0xa5; const UPDATE_ATTRIBUTES_PACKET = 0xa6; @@ -78,15 +78,15 @@ interface Info{ const CRAFTING_DATA_PACKET = 0xba; const CRAFTING_EVENT_PACKET = 0xbb; const ADVENTURE_SETTINGS_PACKET = 0xbc; - const TILE_ENTITY_DATA_PACKET = 0xbd; + const BLOCK_ENTITY_DATA_PACKET = 0xbd; //const PLAYER_INPUT_PACKET = 0xbe; const FULL_CHUNK_DATA_PACKET = 0xbf; const SET_DIFFICULTY_PACKET = 0xc0; //const CHANGE_DIMENSION_PACKET = 0xc1; - //const SET_PLAYER_GAMETYPE_PACKET = 0xc2; + const SET_PLAYER_GAMETYPE_PACKET = 0xc2; const PLAYER_LIST_PACKET = 0xc3; //const TELEMETRY_EVENT_PACKET = 0xc4; - + //const SPAWN_EXPERIENCE_ORB_PACKET = 0xc5 } diff --git a/src/pocketmine/network/protocol/LoginPacket.php b/src/pocketmine/network/protocol/LoginPacket.php index 3cc8eca94..6b8079f19 100644 --- a/src/pocketmine/network/protocol/LoginPacket.php +++ b/src/pocketmine/network/protocol/LoginPacket.php @@ -36,7 +36,7 @@ class LoginPacket extends DataPacket{ public $serverAddress; public $clientSecret; - public $slim = false; + public $skinName; public $skin = null; public function decode(){ @@ -52,7 +52,7 @@ class LoginPacket extends DataPacket{ $this->serverAddress = $this->getString(); $this->clientSecret = $this->getString(); - $this->slim = $this->getByte() > 0; + $this->skinName = $this->getString(); $this->skin = $this->getString(); } diff --git a/src/pocketmine/network/protocol/PlayerListPacket.php b/src/pocketmine/network/protocol/PlayerListPacket.php index bcb45acd6..c9f65a664 100644 --- a/src/pocketmine/network/protocol/PlayerListPacket.php +++ b/src/pocketmine/network/protocol/PlayerListPacket.php @@ -53,7 +53,7 @@ class PlayerListPacket extends DataPacket{ $this->putUUID($d[0]); $this->putLong($d[1]); $this->putString($d[2]); - $this->putByte($d[3] ? 1 : 0); + $this->putString($d[3]); $this->putString($d[4]); }else{ $this->putUUID($d[0]); diff --git a/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php b/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php new file mode 100644 index 000000000..46e0ad72e --- /dev/null +++ b/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php @@ -0,0 +1,41 @@ + + + +class SetPlayerGameTypePacket extends DataPacket{ + const NETWORK_ID = Info::SET_PLAYER_GAMETYPE_PACKET; + + public $gamemode; + + public function decode(){ + + } + + public function encode(){ + $this->reset(); + $this->putInt($this->gamemode); + } + +} diff --git a/src/pocketmine/scheduler/AsyncTask.php b/src/pocketmine/scheduler/AsyncTask.php index 6f3d85a37..0e4ea0502 100644 --- a/src/pocketmine/scheduler/AsyncTask.php +++ b/src/pocketmine/scheduler/AsyncTask.php @@ -22,13 +22,14 @@ namespace pocketmine\scheduler; use pocketmine\Server; +use pocketmine\Collectable; /** * Class used to run async tasks in other threads. * * WARNING: Do not call PocketMine-MP API methods, or save objects from/on other Threads!! */ -abstract class AsyncTask extends \Collectable{ +abstract class AsyncTask extends Collectable{ /** @var AsyncWorker $worker */ public $worker = null; diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index 706f91cc1..14d36cce3 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -25,7 +25,7 @@ use pocketmine\level\format\FullChunk; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\Network; -use pocketmine\network\protocol\TileEntityDataPacket; +use pocketmine\network\protocol\BlockEntityDataPacket; use pocketmine\Player; abstract class Spawnable extends Tile{ @@ -37,7 +37,7 @@ abstract class Spawnable extends Tile{ $nbt = new NBT(NBT::LITTLE_ENDIAN); $nbt->setData($this->getSpawnCompound()); - $pk = new TileEntityDataPacket(); + $pk = new BlockEntityDataPacket(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index 180b3a21c..059f11913 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -21,7 +21,6 @@ /** * All the Tile classes and related classes - * TODO: Add Nether Reactor tile */ namespace pocketmine\tile; diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index 0c4cd36e7..18085f03c 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -84,7 +84,7 @@ class Utils{ if(file_exists("/etc/machine-id")){ $machine .= file_get_contents("/etc/machine-id"); }else{ - @exec("ifconfig", $mac); + @exec("ifconfig 2>/dev/null", $mac); $mac = implode("\n", $mac); if(preg_match_all("#HWaddr[ \t]{1,}([0-9a-f:]{17})#", $mac, $matches)){ foreach($matches[1] as $i => $v){