From 42e81209619bf20dd72070f322e29adb6a35d2bf Mon Sep 17 00:00:00 2001 From: dktapps Date: Tue, 6 Sep 2016 19:14:07 +0100 Subject: [PATCH] Remove creative container open checks (lines up with 0.14) --- src/pocketmine/block/Anvil.php | 4 - src/pocketmine/block/BurningFurnace.php | 4 - src/pocketmine/block/Chest.php | 5 +- src/pocketmine/block/EnchantingTable.php | 3 - src/pocketmine/block/TrappedChest.php | 158 +---------------------- 5 files changed, 6 insertions(+), 168 deletions(-) diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 73c2e6c0f..f2623019f 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -60,10 +60,6 @@ class Anvil extends Fallable{ public function onActivate(Item $item, Player $player = null){ if($player instanceof Player){ - if($player->isCreative()){ - return true; - } - $player->addWindow(new AnvilInventory($this)); } diff --git a/src/pocketmine/block/BurningFurnace.php b/src/pocketmine/block/BurningFurnace.php index 84de41121..84ef2fbb6 100644 --- a/src/pocketmine/block/BurningFurnace.php +++ b/src/pocketmine/block/BurningFurnace.php @@ -123,10 +123,6 @@ class BurningFurnace extends Solid{ } } - if($player->isCreative()){ - return true; - } - $player->addWindow($furnace->getInventory()); } diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index c0c4eed9a..b2bd36855 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -86,7 +86,7 @@ class Chest extends Transparent{ continue; } $c = $this->getSide($side); - if($c instanceof Chest and $c->getDamage() === $this->meta){ + if($c->getId() === $this->id and $c->getDamage() === $this->meta){ $tile = $this->getLevel()->getTile($c); if($tile instanceof TileChest and !$tile->isPaired()){ $chest = $tile; @@ -164,9 +164,6 @@ class Chest extends Transparent{ } } - if($player->isCreative()){ - return true; - } $player->addWindow($chest->getInventory()); } diff --git a/src/pocketmine/block/EnchantingTable.php b/src/pocketmine/block/EnchantingTable.php index 59539906b..a9a50ce25 100644 --- a/src/pocketmine/block/EnchantingTable.php +++ b/src/pocketmine/block/EnchantingTable.php @@ -86,9 +86,6 @@ class EnchantingTable extends Transparent{ public function onActivate(Item $item, Player $player = null){ if($player instanceof Player){ //TODO lock - if($player->isCreative()){ - return true; - } $player->addWindow(new EnchantInventory($this)); } diff --git a/src/pocketmine/block/TrappedChest.php b/src/pocketmine/block/TrappedChest.php index 3e189c252..b2ecb204c 100644 --- a/src/pocketmine/block/TrappedChest.php +++ b/src/pocketmine/block/TrappedChest.php @@ -21,161 +21,13 @@ namespace pocketmine\block; -use pocketmine\item\Item; -use pocketmine\item\Tool; -use pocketmine\math\AxisAlignedBB; -use pocketmine\nbt\NBT; -use pocketmine\nbt\tag\CompoundTag; -use pocketmine\nbt\tag\Enum; -use pocketmine\nbt\tag\Int as IntTag; -use pocketmine\nbt\tag\String as StringTag; -use pocketmine\Player; -use pocketmine\tile\Chest as TileChest; -use pocketmine\tile\Tile; - -class TrappedChest extends Transparent{ - - protected $id = self::CHEST; - - public function __construct($meta = 0){ - $this->meta = $meta; - } - - public function canBeActivated(){ - return true; - } - - public function getHardness(){ - return 2.5; - } +class TrappedChest extends Chest{ + + //TODO: Redstone! + + protected $id = self::TRAPPED_CHEST; 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], - ]; - } }