Merge branch 'master' into 0.10

This commit is contained in:
Shoghi Cervantes
2014-10-30 23:20:59 +01:00
253 changed files with 2410 additions and 1218 deletions

View File

@ -126,11 +126,12 @@ abstract class BaseInventory implements Inventory{
return false;
}elseif($item->getID() === 0 or $item->getCount() <= 0){
$this->clear($index, $source);
return true;
}
$holder = $this->getHolder();
if($holder instanceof Entity){
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($holder, $this->getItem($index), $item, $index));
Server::getInstance()->getPluginManager()->callEvent($ev = EntityInventoryChangeEvent::createEvent($holder, $this->getItem($index), $item, $index));
if($ev->isCancelled()){
$this->sendContents($this->getViewers());
@ -297,7 +298,7 @@ abstract class BaseInventory implements Inventory{
$old = $this->slots[$index];
$holder = $this->getHolder();
if($holder instanceof Entity){
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($holder, $old, $item, $index));
Server::getInstance()->getPluginManager()->callEvent($ev = EntityInventoryChangeEvent::createEvent($holder, $old, $item, $index));
if($ev->isCancelled()){
$this->sendContents($this->getViewers());
@ -349,7 +350,7 @@ abstract class BaseInventory implements Inventory{
}
public function open(Player $who){
$who->getServer()->getPluginManager()->callEvent($ev = new InventoryOpenEvent($this, $who));
$who->getServer()->getPluginManager()->callEvent($ev = InventoryOpenEvent::createEvent($this, $who));
if($ev->isCancelled()){
return false;
}
@ -383,7 +384,7 @@ abstract class BaseInventory implements Inventory{
$target = [$target];
}
$pk = new ContainerSetContentPacket();
$pk = ContainerSetContentPacket::getFromPool();
$pk->slots = [];
for($i = 0; $i < $this->getSize(); ++$i){
$pk->slots[$i] = $this->getItem($i);
@ -408,7 +409,7 @@ abstract class BaseInventory implements Inventory{
$target = [$target];
}
$pk = new ContainerSetSlotPacket;
$pk = ContainerSetSlotPacket::getFromPool();
$pk->slot = $index;
$pk->item = clone $this->getItem($index);
@ -426,4 +427,4 @@ abstract class BaseInventory implements Inventory{
return $this->type;
}
}
}

View File

@ -43,7 +43,7 @@ class ChestInventory extends ContainerInventory{
parent::onOpen($who);
if(count($this->getViewers()) === 1){
$pk = new TileEventPacket;
$pk = TileEventPacket::getFromPool();
$pk->x = $this->getHolder()->getX();
$pk->y = $this->getHolder()->getY();
$pk->z = $this->getHolder()->getZ();
@ -57,7 +57,7 @@ class ChestInventory extends ContainerInventory{
public function onClose(Player $who){
if(count($this->getViewers()) === 1){
$pk = new TileEventPacket;
$pk = TileEventPacket::getFromPool();
$pk->x = $this->getHolder()->getX();
$pk->y = $this->getHolder()->getY();
$pk->z = $this->getHolder()->getZ();

View File

@ -29,14 +29,15 @@ use pocketmine\Player;
abstract class ContainerInventory extends BaseInventory{
public function onOpen(Player $who){
parent::onOpen($who);
$pk = new ContainerOpenPacket;
$pk = ContainerOpenPacket::getFromPool();
$pk->windowid = $who->getWindowId($this);
$pk->type = $this->getType()->getNetworkType();
$pk->slots = $this->getSize();
if($this->holder instanceof Vector3){
$pk->x = $this->holder->getX();
$pk->y = $this->holder->getY();
$pk->z = $this->holder->getZ();
$holder = $this->getHolder();
if($holder instanceof Vector3){
$pk->x = $holder->getX();
$pk->y = $holder->getY();
$pk->z = $holder->getZ();
}else{
$pk->x = $pk->y = $pk->z = 0;
}
@ -47,7 +48,7 @@ abstract class ContainerInventory extends BaseInventory{
}
public function onClose(Player $who){
$pk = new ContainerClosePacket;
$pk = ContainerClosePacket::getFromPool();
$pk->windowid = $who->getWindowId($this);
$who->dataPacket($pk);
parent::onClose($who);

View File

@ -41,7 +41,7 @@ class CraftingInventory extends BaseInventory{
*/
public function __construct(InventoryHolder $holder, Inventory $resultInventory, InventoryType $inventoryType){
if($inventoryType->getDefaultTitle() !== "Crafting"){
throw new \Exception("Invalid Inventory type, expected CRAFTING or WORKBENCH");
throw new \InvalidStateException("Invalid Inventory type, expected CRAFTING or WORKBENCH");
}
$this->resultInventory = $resultInventory;
parent::__construct($holder, $inventoryType);

View File

@ -57,7 +57,7 @@ class CraftingManager{
$this->registerRecipe((new ShapelessRecipe(Item::get(Item::LIT_PUMPKIN, 0, 1)))->addIngredient(Item::get(Item::PUMPKIN, 0, 1))->addIngredient(Item::get(Item::TORCH, 0, 1)));
$this->registerRecipe((new ShapelessRecipe(Item::get(Item::SNOW_BLOCK, 0, 1)))->addIngredient(Item::get(Item::SNOWBALL, 0, 1)));
$this->registerRecipe((new ShapelessRecipe(Item::get(Item::STICK, 0, 4)))->addIngredient(Item::get(Item::WOODEN_PLANK, null, 2)));
$this->registerRecipe((new ShapelessRecipe(Item::get(Item::STONECUTTER, 0, 1)))->addIngredient(Item::get(Item::COBBLESTONE, 0, 1)));
$this->registerRecipe((new ShapelessRecipe(Item::get(Item::STONECUTTER, 0, 1)))->addIngredient(Item::get(Item::COBBLESTONE, 0, 4)));
$this->registerRecipe((new ShapelessRecipe(Item::get(Item::WOODEN_PLANK, Planks::OAK, 4)))->addIngredient(Item::get(Item::WOOD, Wood::OAK, 1)));
$this->registerRecipe((new ShapelessRecipe(Item::get(Item::WOODEN_PLANK, Planks::SPRUCE, 4)))->addIngredient(Item::get(Item::WOOD, Wood::SPRUCE, 1)));
$this->registerRecipe((new ShapelessRecipe(Item::get(Item::WOODEN_PLANK, Planks::BIRCH, 4)))->addIngredient(Item::get(Item::WOOD, Wood::BIRCH, 1)));
@ -87,7 +87,7 @@ class CraftingManager{
$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, 2)));
$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)));
@ -106,7 +106,7 @@ class CraftingManager{
$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))); //TODO: check if TNT can be crafted with red sand
$this->registerRecipe((new BigShapelessRecipe(Item::get(Item::BOWL, 0, 1)))->addIngredient(Item::get(Item::WOODEN_PLANKS, null, 3)));
$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)));

View File

@ -92,7 +92,7 @@ class CraftingTransactionGroup extends SimpleTransactionGroup{
return false;
}
Server::getInstance()->getPluginManager()->callEvent($ev = new CraftItemEvent($this, $this->getMatchingRecipe()));
Server::getInstance()->getPluginManager()->callEvent($ev = CraftItemEvent::createEvent($this, $this->getMatchingRecipe()));
if($ev->isCancelled()){
foreach($this->inventories as $inventory){
$inventory->sendContents($inventory->getViewers());

View File

@ -22,6 +22,10 @@
namespace pocketmine\inventory;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\network\protocol\TileEventPacket;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\tile\Chest;
class DoubleChestInventory extends ChestInventory implements InventoryHolder{
@ -83,6 +87,37 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
}
}
public function onOpen(Player $who){
parent::onOpen($who);
if(count($this->getViewers()) === 1){
$pk = TileEventPacket::getFromPool();
$pk->x = $this->right->getHolder()->getX();
$pk->y = $this->right->getHolder()->getY();
$pk->z = $this->right->getHolder()->getZ();
$pk->case1 = 1;
$pk->case2 = 2;
if(($level = $this->right->getHolder()->getLevel()) instanceof Level){
Server::broadcastPacket($level->getUsingChunk($this->right->getHolder()->getX() >> 4, $this->right->getHolder()->getZ() >> 4), $pk);
}
}
}
public function onClose(Player $who){
if(count($this->getViewers()) === 1){
$pk = TileEventPacket::getFromPool();
$pk->x = $this->right->getHolder()->getX();
$pk->y = $this->right->getHolder()->getY();
$pk->z = $this->right->getHolder()->getZ();
$pk->case1 = 1;
$pk->case2 = 0;
if(($level = $this->right->getHolder()->getLevel()) instanceof Level){
Server::broadcastPacket($level->getUsingChunk($this->right->getHolder()->getX() >> 4, $this->right->getHolder()->getZ() >> 4), $pk);
}
}
parent::onClose($who);
}
/**
* @return ChestInventory
*/

View File

@ -66,7 +66,7 @@ class PlayerInventory extends BaseInventory{
$this->itemInHandIndex = $index;
$item = $this->getItemInHand();
$pk = new PlayerEquipmentPacket;
$pk = PlayerEquipmentPacket::getFromPool();
$pk->eid = $this->getHolder()->getID();
$pk->item = $item->getID();
$pk->meta = $item->getDamage();
@ -103,7 +103,7 @@ class PlayerInventory extends BaseInventory{
if($slot >= -1 and $slot < $this->getSize()){
$item = $this->getItem($slot);
if($this->getHolder() instanceof Player){
Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerItemHeldEvent($this->getHolder(), $item, $slot, $this->itemInHandIndex));
Server::getInstance()->getPluginManager()->callEvent($ev = PlayerItemHeldEvent::createEvent($this->getHolder(), $item, $slot, $this->itemInHandIndex));
if($ev->isCancelled()){
$this->sendHeldItem($this->getHolder());
@ -126,7 +126,7 @@ class PlayerInventory extends BaseInventory{
$item = $this->getItemInHand();
$pk = new PlayerEquipmentPacket;
$pk = PlayerEquipmentPacket::getFromPool();
$pk->eid = $this->getHolder()->getID();
$pk->item = $item->getID();
$pk->meta = $item->getDamage();
@ -166,35 +166,35 @@ class PlayerInventory extends BaseInventory{
}
public function getHelmet(){
return $this->getItem($this->getSize() + 3);
}
public function getChestplate(){
return $this->getItem($this->getSize() + 2);
}
public function getLeggings(){
return $this->getItem($this->getSize() + 1);
}
public function getBoots(){
return $this->getItem($this->getSize());
}
public function getChestplate(){
return $this->getItem($this->getSize() + 1);
}
public function getLeggings(){
return $this->getItem($this->getSize() + 2);
}
public function getBoots(){
return $this->getItem($this->getSize() + 3);
}
public function setHelmet(Item $helmet){
return $this->setItem($this->getSize() + 3, $helmet);
return $this->setItem($this->getSize(), $helmet);
}
public function setChestplate(Item $chestplate){
return $this->setItem($this->getSize() + 2, $chestplate);
return $this->setItem($this->getSize() + 1, $chestplate);
}
public function setLeggings(Item $leggings){
return $this->setItem($this->getSize() + 1, $leggings);
return $this->setItem($this->getSize() + 2, $leggings);
}
public function setBoots(Item $boots){
return $this->setItem($this->getSize(), $boots);
return $this->setItem($this->getSize() + 3, $boots);
}
public function setItem($index, Item $item, $source = null){
@ -203,7 +203,7 @@ class PlayerInventory extends BaseInventory{
}
if($index >= $this->getSize()){ //Armor change
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $this->getItem($index), $item, $index));
Server::getInstance()->getPluginManager()->callEvent($ev = EntityArmorChangeEvent::createEvent($this->getHolder(), $this->getItem($index), $item, $index));
if($ev->isCancelled() and $this->getHolder() instanceof Player){
$this->sendArmorContents($this->getViewers());
$this->sendContents($this->getViewers());
@ -229,7 +229,7 @@ class PlayerInventory extends BaseInventory{
$item = Item::get(Item::AIR, null, 0);
$old = $this->slots[$index];
if($index >= $this->getSize() and $index < $this->size){ //Armor change
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $old, $item, $index));
Server::getInstance()->getPluginManager()->callEvent($ev = EntityArmorChangeEvent::createEvent($this->getHolder(), $old, $item, $index));
if($ev->isCancelled()){
$this->sendArmorContents($this->getViewers());
$this->sendContents($this->getViewers());
@ -286,7 +286,7 @@ class PlayerInventory extends BaseInventory{
}
}
$pk = new PlayerArmorEquipmentPacket;
$pk = PlayerArmorEquipmentPacket::getFromPool();
$pk->eid = $this->getHolder()->getID();
$pk->slots = $slots;
$pk->encode();
@ -298,7 +298,7 @@ class PlayerInventory extends BaseInventory{
//$pk2 = clone $pk;
//$pk2->eid = 0;
$pk2 = new ContainerSetContentPacket;
$pk2 = ContainerSetContentPacket::getFromPool();
$pk2->windowid = 0x78; //Armor window id constant
$pk2->slots = $armor;
$player->dataPacket($pk2);
@ -333,7 +333,7 @@ class PlayerInventory extends BaseInventory{
$target = [$target];
}
$pk = new ContainerSetContentPacket();
$pk = ContainerSetContentPacket::getFromPool();
$pk->slots = [];
for($i = 0; $i < $this->getSize(); ++$i){ //Do not send armor by error here
$pk->slots[$i] = $this->getItem($i);
@ -365,7 +365,7 @@ class PlayerInventory extends BaseInventory{
$target = [$target];
}
$pk = new ContainerSetSlotPacket;
$pk = ContainerSetSlotPacket::getFromPool();
$pk->slot = $index;
$pk->item = clone $this->getItem($index);

View File

@ -42,14 +42,14 @@ class ShapedRecipe implements Recipe{
*/
public function __construct(Item $result, array $shape = []){
if(count($shape) === 0){
throw new \Exception("Must provide a shape");
throw new \InvalidArgumentException("Must provide a shape");
}
if(count($shape) > 3){
throw new \Exception("Crafting recipes should be 1, 2, 3 rows, not " . count($shape));
throw new \InvalidStateException("Crafting recipes should be 1, 2, 3 rows, not " . count($shape));
}
foreach($shape as $row){
if(strlen($row) === 0 or strlen($row) > 3){
throw new \Exception("Crafting rows should be 1, 2, 3 characters, not " . count($row));
throw new \InvalidStateException("Crafting rows should be 1, 2, 3 characters, not " . count($row));
}
$this->rows[] = $row;
$len = strlen($row);

View File

@ -44,11 +44,11 @@ class ShapelessRecipe implements Recipe{
*
* @returns ShapelessRecipe
*
* @throws \Exception
* @throws \InvalidArgumentException
*/
public function addIngredient(Item $item){
if(count($this->ingredients) >= 9){
throw new \Exception("Shapeless recipes cannot have more than 9 ingredients");
throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients");
}
$it = clone $item;

View File

@ -129,9 +129,8 @@ class SimpleTransactionGroup implements TransactionGroup{
public function canExecute(){
$haveItems = [];
$needItems = [];
$this->matchItems($haveItems, $needItems);
return count($haveItems) === 0 and count($needItems) === 0 and count($this->transactions) > 0;
return $this->matchItems($haveItems, $needItems) and count($haveItems) === 0 and count($needItems) === 0 and count($this->transactions) > 0;
}
public function execute(){
@ -139,7 +138,7 @@ class SimpleTransactionGroup implements TransactionGroup{
return false;
}
Server::getInstance()->getPluginManager()->callEvent($ev = new InventoryTransactionEvent($this));
Server::getInstance()->getPluginManager()->callEvent($ev = InventoryTransactionEvent::createEvent($this));
if($ev->isCancelled()){
foreach($this->inventories as $inventory){
$inventory->sendContents($inventory->getViewers());