From 9d1369bfe957e2e411e185c28fea3587f111f3b6 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Jun 2013 20:02:25 +0200 Subject: [PATCH] Fixed items being consumed on CREATIVE mode --- src/API/BlockAPI.php | 3 ++- src/Player.php | 14 ++++++++++---- src/material/block/plant/MelonStem.php | 4 +++- src/material/block/plant/Sapling.php | 4 +++- src/material/block/plant/Wheat.php | 4 +++- src/material/block/solid/Dirt.php | 4 +++- src/material/block/solid/Grass.php | 8 ++++++-- 7 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 3df7a1f207..5645fd8047 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -266,10 +266,11 @@ class BlockAPI{ $player->lastBreak = microtime(true); if($this->server->api->dhandle("player.block.break", array("player" => $player, "target" => $target, "item" => $item)) !== false){ - $drops = $target->getDrops($item, $player); if($target->onBreak($item, $player) === false){ return $this->cancelAction($target, $player, false); } + $item->useOn($target); + $drops = $target->getDrops($item, $player); }else{ return $this->cancelAction($target, $player, false); } diff --git a/src/Player.php b/src/Player.php index 6931d99297..feafddfb72 100644 --- a/src/Player.php +++ b/src/Player.php @@ -365,13 +365,19 @@ class Player{ return; $s = (int) $s; if(!isset($this->inventory[$s])){ - return false; + $this->dataPacket(MC_CONTAINER_SET_SLOT, array( + "windowid" => 0, + "slot" => (int) $s, + "block" => AIR, + "stack" => 0, + "meta" => 0, + )); } $slot = $this->inventory[$s]; $this->dataPacket(MC_CONTAINER_SET_SLOT, array( "windowid" => 0, - "slot" => ((int) $s) + 9, + "slot" => (int) $s, "block" => $slot->getID(), "stack" => $slot->count, "meta" => $slot->getMetadata(), @@ -1349,7 +1355,7 @@ class Player{ $damage = 1;//$this->server->difficulty; } $target->harm($damage, $this->eid); - if($slot->isTool() === true){ + if($slot->isTool() === true and ($this->gamemode & 0x01) === 0){ $slot->useOn($target); } } @@ -1630,7 +1636,7 @@ class Player{ $this->dataPacket(MC_CONTAINER_SET_CONTENT, array( "windowid" => 0, "count" => count($this->inventory), - "slots" => $this->inventory + "slots" => $this->inventory, )); } diff --git a/src/material/block/plant/MelonStem.php b/src/material/block/plant/MelonStem.php index ad21b9d8ac..5646e7c51a 100644 --- a/src/material/block/plant/MelonStem.php +++ b/src/material/block/plant/MelonStem.php @@ -76,7 +76,9 @@ class MelonStemBlock extends FlowableBlock{ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta = 0x07; $this->level->setBlock($this, $this); - $item->count--; + if(($player->gamemode & 0x01) === 0){ + $item->count--; + } return true; } return false; diff --git a/src/material/block/plant/Sapling.php b/src/material/block/plant/Sapling.php index 128bf873a7..513586c94f 100644 --- a/src/material/block/plant/Sapling.php +++ b/src/material/block/plant/Sapling.php @@ -55,7 +55,9 @@ class SaplingBlock extends FlowableBlock{ public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03); - $item->count--; + if(($player->gamemode & 0x01) === 0){ + $item->count--; + } return true; } return false; diff --git a/src/material/block/plant/Wheat.php b/src/material/block/plant/Wheat.php index a0c35542c2..dd3420f50d 100644 --- a/src/material/block/plant/Wheat.php +++ b/src/material/block/plant/Wheat.php @@ -45,7 +45,9 @@ class WheatBlock extends FlowableBlock{ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta = 0x07; $this->level->setBlock($this, $this); - $item->count--; + if(($player->gamemode & 0x01) === 0){ + $item->count--; + } return true; } return false; diff --git a/src/material/block/solid/Dirt.php b/src/material/block/solid/Dirt.php index a39bce9eb0..286066a2de 100644 --- a/src/material/block/solid/Dirt.php +++ b/src/material/block/solid/Dirt.php @@ -33,7 +33,9 @@ class DirtBlock extends SolidBlock{ public function onActivate(Item $item, Player $player){ if($item->isHoe()){ - $item->useOn($this); + if(($this->gamemode & 0x01) === 0){ + $item->useOn($this); + } $this->level->setBlock($this, BlockAPI::get(FARMLAND, 0)); return true; } diff --git a/src/material/block/solid/Grass.php b/src/material/block/solid/Grass.php index 469df82fa5..947a8bbf9c 100644 --- a/src/material/block/solid/Grass.php +++ b/src/material/block/solid/Grass.php @@ -38,11 +38,15 @@ class GrassBlock extends SolidBlock{ public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ - $item->count--; + if(($player->gamemode & 0x01) === 0){ + $item->count--; + } TallGrassObject::growGrass($this->level, $this, new Random()); return true; }elseif($item->isHoe()){ - $item->useOn($this); + if(($this->gamemode & 0x01) === 0){ + $item->useOn($this); + } $this->level->setBlock($this, new FarmlandBlock()); return true; }