diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 0e111670..8d9eef60 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -415,9 +415,8 @@ class BlockAPI{ if($target->onBreak($item, $player) === false){ return $this->cancelAction($target, $player, false); } - if(($player->gamemode & 0x01) === 0 and $item->useOn($target) and $item->getMetadata() >= $item->getMaxDurability()){ - $player->setSlot($player->slot, new Item(AIR, 0, 0), false); - } + + $item->mineBlock($target, $player); }else{ return $this->cancelAction($target, $player, false); } @@ -446,7 +445,7 @@ class BlockAPI{ $target = $player->level->getBlock($vector); $block = $target->getSide($face); - $item = $player->getSlot($player->slot); + $item = $player->getHeldItem(); if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){ //If no block exists or not allowed in CREATIVE if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){ @@ -479,10 +478,7 @@ class BlockAPI{ return false; } - if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){ - if($item->count <= 0){ - $player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false); - } + if($item->isActivable === true && $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){ return false; } @@ -528,12 +524,7 @@ class BlockAPI{ $t->data["creator"] = $player->username; } - if(($player->gamemode & 0x01) === 0x00){ - --$item->count; - if($item->count <= 0){ - $player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false); - } - } + $player->consumeSingleItem(); return false; } diff --git a/src/Player.php b/src/Player.php index 1e089166..c6acd15a 100755 --- a/src/Player.php +++ b/src/Player.php @@ -23,6 +23,9 @@ class Player{ public $slot; public $hotbar; public $curHotbarIndex = 0; + /** + * @var Item[] + */ public $armor = []; public $loggedIn = false; public $gamemode; @@ -193,7 +196,7 @@ class Player{ public function getSpawn(){ return $this->spawnPosition; } - + /** * @param Vector3 $pos * @@ -2302,10 +2305,7 @@ class Player{ $e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power+$power) * 1.5, 1.0); $this->server->api->entity->spawnToAll($e); if(($this->gamemode & 0x01) == 0x0) { - $bow = $this->getSlot($this->slot); - if(++$bow->meta >= $bow->getMaxDurability()){ - $this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0); - } + $this->getHeldItem()->hurtAndBreak(1, $this); $this->removeItem(ARROW, 0, 1, send: true); } } @@ -2652,7 +2652,6 @@ class Player{ $this->addCraftingIngridient($packet->slot, $slot->getID(), $slot->getMetadata(), $slot->count); $this->addCraftingResult($packet->slot, $citem->getID(), $citem->getMetadata(), $citem->count); } - }else{ $this->toCraft = []; $this->craftingItems = []; @@ -2998,7 +2997,22 @@ class Player{ } return false; } - + + /** + * Removes a single item from whatever player is holding. + * @param boolean $send Force send inventory to player. + */ + public function consumeSingleItem($send = false){ + $it = $this->getHeldItem(); + if(($this->gamemode & 0x01) === 0x00) --$it->count; + + if($it->count <= 0){ + $this->setSlot($this->slot, BlockAPI::getItem(0, 0, 0), false); + } + + if($send) $this->sendInventory(); + } + public function removeItem($type, $damage, $count, $send = true){ while($count > 0){ $remove = 0; @@ -3089,15 +3103,6 @@ class Player{ } } - public function damageArmorPart($slot, $part){ - $part->useOn($this->entity, true); - if($part->getMetadata() >= $part->getMaxDurability()){ - $this->setArmor($slot, BlockAPI::getItem(AIR, 0, 0), false); - return; - } - $this->setArmor($slot, $part, false); - } - /** * @return string */ @@ -3121,6 +3126,11 @@ class Player{ return false; } + /** + * @deprecated armor is damaged by Entity::hurtArmor and cant be damaged by singular pieces + */ + public function damageArmorPart($slot, $part){} + /** * @deprecated 16x16x16 chunk sending was removed */ diff --git a/src/entity/Animal.php b/src/entity/Animal.php index b21aab0d..1f2bc748 100644 --- a/src/entity/Animal.php +++ b/src/entity/Animal.php @@ -140,9 +140,7 @@ abstract class Animal extends Creature implements Ageable, Breedable{ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ $slot = $e->player->getHeldItem(); if($this->isFood($slot->getID()) && $this->inLove <= 0 && !$this->isBaby() && $this->loveTimeout <= 0){ - if(($e->player->gamemode & 0x01) === SURVIVAL){ - $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1); - } + $e->player->consumeSingleItem(); $this->inLove = 600; return true; } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 68dffc21..9176c260 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1047,11 +1047,7 @@ class Entity extends Position $slot = $e->player->getHeldItem(); $damage = $slot->getDamageAgainstOf($this); $this->harm($damage, $e->eid); - if($slot->isTool() && (!$this->isPlayer() || ($this->player->gamemode & 0x01) === 0)){ - if($slot->useOn($this) and $slot->getMetadata() >= $slot->getMaxDurability()){ - $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); - } - } + $slot->hurtEnemy($this, $e->player); //TODO dont try destroying if harm was cancelled? return true; } return false; @@ -1558,16 +1554,28 @@ class Entity extends Position foreach($this->player->armor as $slot => $part){ if($part instanceof ArmorItem){ $pnts += $part->getDamageReduceAmount(); - $this->player->damageArmorPart($slot, $part); } } - $this->player->sendArmor($this->player); } return $pnts; } + + public function hurtArmor($dmg){ + if($this->isPlayer()){ + $v2 = (int)($dmg / 4); + if($v2 < 1) $v2 = 1; + + foreach($this->player->armor as $slot => $part){ + $part->hurtAndBreak($v2, $this->player); + } + $this->player->sendArmor(); + } + } + public function applyArmor($damage, $cause){ if(is_numeric($cause) || $cause === "explosion"){ $var3 = 25 - $this->getArmorValue(); + $this->hurtArmor($damage); //uses damage without armor affection $var4 = $damage * $var3 + $this->carryoverDamage; $damage = $var4 / 25; $this->carryoverDamage = $var4 % 25; diff --git a/src/entity/animal/Cow.php b/src/entity/animal/Cow.php index 441ff126..e8a18386 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -26,7 +26,7 @@ class Cow extends Animal{ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ $slot = $e->player->getHeldItem(); if($slot->getID() === BUCKET && $slot->getMetadata() === 0){ - $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); //remove only 1 bucket + $e->player->consumeSingleItem(); $e->player->addItem(BUCKET, 1, 1, true); return true; } diff --git a/src/entity/animal/Pig.php b/src/entity/animal/Pig.php index 93aabfb3..46cd725b 100644 --- a/src/entity/animal/Pig.php +++ b/src/entity/animal/Pig.php @@ -62,7 +62,7 @@ class Pig extends Animal implements Rideable{ if($slot->getID() === SADDLE){ if(!$this->isSaddled()){ - $e->player->removeItem($slot->getID(), 0, 1, send: true); + $e->player->consumeSingleItem(send: true); $this->setSaddled(1); } return true; //avoid further interactions diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index d79c8701..3a7fe09f 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -75,25 +75,18 @@ class Sheep extends Animal{ $slot = $e->player->getHeldItem(); if($slot->getID() === SHEARS){ if(!$this->isSheared() && !$this->isBaby()){ - if($e->player->gamemode != 1) $slot->useOn($this); $this->setSheared(1); $speedX = (lcg_value() * 0.2 - 0.1) + (lcg_value() - lcg_value()) * 0.1; $speedZ = (lcg_value() * 0.2 - 0.1) + (lcg_value() - lcg_value()) * 0.1; $speedY = 0.2 + (lcg_value()) * 0.05; $this->server->api->entity->dropRawPos($this->level, $this->x, $this->y + 1, $this->z, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3)), $speedX, $speedY, $speedZ); - if($slot->getMetadata() >= $slot->getMaxDurability()){ - $e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); - }else{ - $e->player->setSlot($e->player->slot, $slot); - } + $slot->hurtAndBreak(1, $e->player); } return true; }elseif($slot->getID() === DYE){ $this->setColor($this->switchColorMeta($slot->getMetadata())); - if(($e->player->gamemode & 0x01) === SURVIVAL){ - $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); - } + $e->player->consumeSingleItem(); } } return parent::interactWith($e, $action); diff --git a/src/entity/monster/Creeper.php b/src/entity/monster/Creeper.php index b1279f9c..12bd50e6 100644 --- a/src/entity/monster/Creeper.php +++ b/src/entity/monster/Creeper.php @@ -27,8 +27,6 @@ class Creeper extends Monster{ $this->setState($v === null ? !$this->getState() : $v); } - - /** * @return boolean */ @@ -40,11 +38,7 @@ class Creeper extends Monster{ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ $slot = $e->player->getHeldItem(); if($slot->getID() === FLINT_AND_STEEL && !$this->isIgnited()){ - if($slot->useOn($this) && $slot->getMetadata() >= $slot->getMaxDurability()){ - $e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); - }else{ - $e->player->setSlot($e->player->slot, $slot); - } + $slot->hurtAndBreak(1, $e->player); $this->ignite(); return true; } diff --git a/src/material/Item.php b/src/material/Item.php index f8f535b6..fa194dde 100755 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -220,18 +220,30 @@ class Item{ } - public function useOn($object, $force = false){ - if($force){ - if(($object instanceof Entity) and !$this->isSword()){ - $this->meta += 2; - }else{ - $this->meta++; + /** + * @param int $dmg - damage dealt to item + * @param Player $player - player who used the item + */ + public function hurtAndBreak($dmg, Player $player){ + if(($player->gamemode & 1) !== 0) return; //dont break items in creative + + if($this->getMaxDurability() !== false){ + $this->meta += $dmg; + if($this->meta > $this->getMaxDurability()){ + $player->consumeSingleItem(); } - return true; } + } + + public function hurtEnemy(Entity $target, Player $attacker){ + + } + + public function mineBlock(Block $block, Player $player){ return false; } + public function isTool(){ return false; } @@ -334,4 +346,11 @@ class Item{ }; } + /** + * @deprecated Item damaging changed. Use hurtAndBreak to damage the item and update it in the client's inventory correctly. + */ + public function useOn($object, $force = false){ + return false; + } + } diff --git a/src/material/block/misc/TNTBlock.php b/src/material/block/misc/TNTBlock.php index aeef0412..5fb3da3e 100644 --- a/src/material/block/misc/TNTBlock.php +++ b/src/material/block/misc/TNTBlock.php @@ -10,9 +10,7 @@ class TNTBlock extends SolidBlock{ public function onActivate(Item $item, Player $player){ if($item->getID() === FLINT_STEEL){ - if(($player->gamemode & 0x01) === 0){ - $item->useOn($this); - } + $item->hurtAndBreak(1, $player); $data = array( "x" => $this->x + 0.5, "y" => $this->y, diff --git a/src/material/block/plant/BeetrootBlock.php b/src/material/block/plant/BeetrootBlock.php index c1b51d73..88a22d4d 100644 --- a/src/material/block/plant/BeetrootBlock.php +++ b/src/material/block/plant/BeetrootBlock.php @@ -32,9 +32,7 @@ class BeetrootBlock extends FlowableBlock{ $this->meta = 7; } $this->level->setBlock($this, $this, true, false, true); - if(($player->gamemode & 0x01) === 0){ - $player->removeItem(DYE,0x0F,1); - } + $player->consumeSingleItem(); return true; } return false; diff --git a/src/material/block/plant/CarrotBlock.php b/src/material/block/plant/CarrotBlock.php index 498399f4..36c3e931 100644 --- a/src/material/block/plant/CarrotBlock.php +++ b/src/material/block/plant/CarrotBlock.php @@ -25,9 +25,7 @@ class CarrotBlock extends FlowableBlock{ $this->meta = 7; } $this->level->setBlock($this, $this, true, false, true); - if(($player->gamemode & 0x01) === 0){ - $player->removeItem(DYE,0x0F,1); - } + $player->consumeSingleItem(); return true; } return false; diff --git a/src/material/block/plant/CyanFlowerBlock.php b/src/material/block/plant/CyanFlowerBlock.php index 8486ede6..16c3c97c 100644 --- a/src/material/block/plant/CyanFlowerBlock.php +++ b/src/material/block/plant/CyanFlowerBlock.php @@ -34,11 +34,9 @@ class CyanFlowerBlock extends FlowableBlock{ public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ - if(($player->gamemode & 0x01) === 0){ - $player->removeItem(DYE,0x0F,1); - } $random = new Random(); self::placeFlowers($this->level, new Vector3($this->x, $this->y, $this->z), $random, $random->nextRange(2, 5), 2); + $player->consumeSingleItem(); return true; } return false; diff --git a/src/material/block/plant/DandelionBlock.php b/src/material/block/plant/DandelionBlock.php index 236fa778..9c61d1bd 100644 --- a/src/material/block/plant/DandelionBlock.php +++ b/src/material/block/plant/DandelionBlock.php @@ -29,11 +29,9 @@ class DandelionBlock extends FlowableBlock{ public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ - if(($player->gamemode & 0x01) === 0){ - $player->removeItem(DYE,0x0F,1); - } $random = new Random(); self::placeFlowers($this->level, new Vector3($this->x, $this->y, $this->z), $random, $random->nextRange(2, 5), 2); + $player->consumeSingleItem(); return true; } return false; diff --git a/src/material/block/plant/MelonStemBlock.php b/src/material/block/plant/MelonStemBlock.php index a9e3c542..2022f819 100644 --- a/src/material/block/plant/MelonStemBlock.php +++ b/src/material/block/plant/MelonStemBlock.php @@ -58,9 +58,7 @@ class MelonStemBlock extends FlowableBlock{ $this->meta = 7; } $this->level->setBlock($this, $this, true, false, true); - if(($player->gamemode & 0x01) === 0){ - $player->removeItem(DYE,0x0F,1); - } + $player->consumeSingleItem(); return true; } return false; diff --git a/src/material/block/plant/PotatoBlock.php b/src/material/block/plant/PotatoBlock.php index 3ab969fe..54ec8cec 100644 --- a/src/material/block/plant/PotatoBlock.php +++ b/src/material/block/plant/PotatoBlock.php @@ -34,9 +34,7 @@ class PotatoBlock extends FlowableBlock{ $this->meta = 7; } $this->level->setBlock($this, $this, true, false, true); - if(($player->gamemode & 0x01) === 0){ - $player->removeItem(DYE,0x0F,1); - } + $player->consumeSingleItem(); return true; } return false; diff --git a/src/material/block/plant/PumpkinStemBlock.php b/src/material/block/plant/PumpkinStemBlock.php index c7492623..a40f9f5f 100644 --- a/src/material/block/plant/PumpkinStemBlock.php +++ b/src/material/block/plant/PumpkinStemBlock.php @@ -58,9 +58,7 @@ class PumpkinStemBlock extends FlowableBlock{ $this->meta = 7; } $this->level->setBlock($this, $this, true, false, true); - if(($player->gamemode & 0x01) === 0){ - $player->removeItem(DYE,0x0F,1); - } + $player->consumeSingleItem(); return true; } return false; diff --git a/src/material/block/plant/SaplingBlock.php b/src/material/block/plant/SaplingBlock.php index a6acde15..86cc8048 100644 --- a/src/material/block/plant/SaplingBlock.php +++ b/src/material/block/plant/SaplingBlock.php @@ -36,9 +36,7 @@ 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); - if(($player->gamemode & 0x01) === 0){ - $player->removeItem(DYE,0x0F,1); - } + $player->consumeSingleItem(); return true; } return false; diff --git a/src/material/block/plant/SugarcaneBlock.php b/src/material/block/plant/SugarcaneBlock.php index d4928460..f17fd596 100644 --- a/src/material/block/plant/SugarcaneBlock.php +++ b/src/material/block/plant/SugarcaneBlock.php @@ -29,9 +29,7 @@ class SugarcaneBlock extends FlowableBlock{ $this->level->fastSetBlockUpdateMeta($this->x, $this->y, $this->z, $this->meta, true); } - if(($player->gamemode & 0x01) === 0){ - $player->removeItem(DYE,0x0F,1); - } + $player->consumeSingleItem(); return true; } return false; diff --git a/src/material/block/plant/WheatBlock.php b/src/material/block/plant/WheatBlock.php index 53bf67f4..176a2065 100644 --- a/src/material/block/plant/WheatBlock.php +++ b/src/material/block/plant/WheatBlock.php @@ -25,9 +25,7 @@ class WheatBlock extends FlowableBlock{ $this->meta = 7; } $this->level->setBlock($this, $this, true, false, true); - if(($player->gamemode & 0x01) === 0){ - $player->removeItem(DYE,0x0F,1); - } + $player->consumeSingleItem(); return true; } return false; diff --git a/src/material/block/solid/DirtBlock.php b/src/material/block/solid/DirtBlock.php index bf96b7c2..46131b49 100644 --- a/src/material/block/solid/DirtBlock.php +++ b/src/material/block/solid/DirtBlock.php @@ -11,11 +11,7 @@ class DirtBlock extends SolidBlock{ public function onActivate(Item $item, Player $player){ if($item->isHoe()){ if($this->getSide(1)->isTransparent === false) return false; - if(($player->gamemode & 0x01) === 0){ - $item->useOn($this); - if($item->getMetadata() >= $item->getMaxDurability()) $player->setSlot($player->slot, new Item(AIR, 0, 0), false); - else $player->setSlot($player->slot, $item, true); - } + $item->hurtAndBreak(1, $player); //TODO move to ItemHoe $this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, FARMLAND, 0, true); return true; } diff --git a/src/material/block/solid/GrassBlock.php b/src/material/block/solid/GrassBlock.php index d6181801..c598b134 100644 --- a/src/material/block/solid/GrassBlock.php +++ b/src/material/block/solid/GrassBlock.php @@ -16,18 +16,12 @@ class GrassBlock extends SolidBlock{ public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ - if(($player->gamemode & 0x01) === 0){ - $player->removeItem(DYE,0x0F,1); - } + $player->consumeSingleItem(); TallGrassObject::growGrass($this->level, $this, new Random(), 8, 2); return true; }elseif($item->isHoe()){ if($this->getSide(1)->isTransparent === false) return false; - if(($player->gamemode & 0x01) === 0){ - $item->useOn($this); - if($item->getMetadata() >= $item->getMaxDurability()) $player->setSlot($player->slot, new Item(AIR, 0, 0), false); - else $player->setSlot($player->slot, $item, true); - } + $item->hurtAndBreak(1, $player); //TODO move to ItemHoe $this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, FARMLAND, 0, true); $this->seedsDrop(); return true; diff --git a/src/material/item/base/ItemHoe.php b/src/material/item/base/ItemHoe.php index 277b75fb..0c3cb416 100644 --- a/src/material/item/base/ItemHoe.php +++ b/src/material/item/base/ItemHoe.php @@ -5,15 +5,6 @@ abstract class ItemHoe extends ItemTool public function isHoe(){ return true; } - - public function useOn($object, $force = false){ - if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){ - $this->meta++; - return true; - }else{ - return parent::useOn($object, $force); - } - } public function getLevel(){ return match ($this->id) { diff --git a/src/material/item/base/ItemSword.php b/src/material/item/base/ItemSword.php index 6bd725e0..14bd259a 100644 --- a/src/material/item/base/ItemSword.php +++ b/src/material/item/base/ItemSword.php @@ -17,5 +17,15 @@ abstract class ItemSword extends ItemTool default => false, }; } + + public function hurtEnemy(Entity $target, Player $attacker){ + $this->hurtAndBreak(1, $attacker); + } + + + public function mineBlock(Block $block, Player $player){ + $this->hurtAndBreak(2, $player); + return true; + } } diff --git a/src/material/item/base/ItemTool.php b/src/material/item/base/ItemTool.php index e5a3af25..061cc065 100644 --- a/src/material/item/base/ItemTool.php +++ b/src/material/item/base/ItemTool.php @@ -11,16 +11,23 @@ abstract class ItemTool extends Item public function isTool(){ return true; } - public function useOn($object, $force = false){ - - if($this->isSword() && !($object instanceof Entity)){ - $this->meta += 2; - }else if(($object instanceof Entity) && !$this->isSword()){ - $this->meta += 2; - }else{ - $this->meta++; + + public function hurtEnemy(Entity $target, Player $attacker){ + if($this->isPickaxe() || $this->isAxe() || $this->isShovel()){ + $this->hurtAndBreak(2, $attacker); + return; } - return true; + + parent::hurtEnemy($target, $attacker); + } + + public function mineBlock(Block $block, Player $player){ + if($this->isPickaxe() || $this->isAxe() || $this->isShovel()){ + $this->hurtAndBreak(1, $player); + return true; + } + + return parent::mineBlock($block, $player); } } diff --git a/src/material/item/generic/MinecartItem.php b/src/material/item/generic/MinecartItem.php index b8923748..19475fea 100755 --- a/src/material/item/generic/MinecartItem.php +++ b/src/material/item/generic/MinecartItem.php @@ -18,8 +18,6 @@ class MinecartItem extends Item{ ]; $e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_MINECART, $data); $server->api->entity->spawnToAll($e); - if(($player->gamemode & 0x01) === 0x00){ - $player->removeItem($this->getID(), $this->getMetadata(), 1, false); - } + $player->consumeSingleItem(); } } \ No newline at end of file diff --git a/src/material/item/generic/PaintingItem.php b/src/material/item/generic/PaintingItem.php index 4ce688c8..329e9222 100644 --- a/src/material/item/generic/PaintingItem.php +++ b/src/material/item/generic/PaintingItem.php @@ -38,7 +38,7 @@ class PaintingItem extends Item{ private static $right = array(4, 5, 3, 2); public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if($target->isTransparent === false and $face > 1 and $block->isSolid === false){ + if($target->isTransparent === false && $face > 1 and $block->isSolid === false){ $server = ServerAPI::request(); if($face < 2 || $face > 5) return; @@ -65,9 +65,8 @@ class PaintingItem extends Item{ $painting->eid = $server->api->entity->getNextEID(); $server->api->entity->addRaw($painting); $server->api->entity->spawnToAll($painting); - if(($player->gamemode & 0x01) === 0x00){ - $player->removeItem($this->getID(), $this->getMetadata(), 1, false); - } + + $player->consumeSingleItem(); return true; } return false; diff --git a/src/material/item/generic/SpawnEggItem.php b/src/material/item/generic/SpawnEggItem.php index f41e9a01..68de416d 100644 --- a/src/material/item/generic/SpawnEggItem.php +++ b/src/material/item/generic/SpawnEggItem.php @@ -17,9 +17,7 @@ class SpawnEggItem extends Item{ ); $e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data); ServerAPI::request()->api->entity->spawnToAll($e); - if(($player->gamemode & 0x01) === 0){ - -- $this->count; - } + $player->consumeSingleItem(); return true; } } \ No newline at end of file diff --git a/src/material/item/tool/FlintSteelItem.php b/src/material/item/tool/FlintSteelItem.php index 134b160a..b9a9f825 100644 --- a/src/material/item/tool/FlintSteelItem.php +++ b/src/material/item/tool/FlintSteelItem.php @@ -8,19 +8,11 @@ class FlintSteelItem extends ItemTool{ } public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if(($player->gamemode & 0x01) === 0 and $this->useOn($block) and $this->getMetadata() >= $this->getMaxDurability()){ - $player->setSlot($player->slot, new Item(AIR, 0, 0), false); - } - + $this->hurtAndBreak(1, $player); if($block->getID() === AIR && $target->isSolid){ $level->fastSetBlockUpdate($block->x, $block->y, $block->z, FIRE, 0, true); return true; } return false; } - - public function useOn($object, $force = false){ - ++$this->meta; - return true; - } } \ No newline at end of file diff --git a/src/material/item/tool/ShearsItem.php b/src/material/item/tool/ShearsItem.php index 059ede72..db14e68c 100755 --- a/src/material/item/tool/ShearsItem.php +++ b/src/material/item/tool/ShearsItem.php @@ -5,11 +5,11 @@ class ShearsItem extends ItemTool{ parent::__construct(SHEARS, $meta, $count, "Shears"); } - public function useOn($object, $force = false){ - if(($object instanceof Sheep) and $this->id === SHEARS){ - $this->meta++; + public function mineBlock(Block $block, Player $player){ + if($block->getID() === LEAVES || $block->getID() === COBWEB){ + $this->hurtAndBreak(1, $player); return true; } - parent::useOn($object, $force); + return parent::mineBlock($block, $player); } } \ No newline at end of file