diff --git a/.gitignore b/.gitignore index b712de5d..b95b2968 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ Desktop.ini # Mac crap .DS_Store + +# nano +*.swp diff --git a/src/Player.php b/src/Player.php index af8986d1..6bda217f 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1524,7 +1524,7 @@ class Player{ if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY){ return; } - + switch($packet->pid()){ case 0x01: break; @@ -2495,6 +2495,7 @@ class Player{ $this->dataPacket($pk); break; } + if($item->getID() !== AIR and $slot->getID() == $item->getID()){ if($slot->count < $item->count){ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false){ @@ -2735,7 +2736,7 @@ class Player{ $s = $this->getSlot($slot); if($s->count <= 0 or $s->getID() === AIR){ $this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $item->count), false); - }else if($s->getID() == $item->getID() && $s->getMetadata() == $item->getMetadata() && ($s->count + $item->count) <= $s->maxStackSize){ + }else if($s->getID() == $item->getID() && $s->getMetadata() == $item->getMetadata() && ($s->count + $item->count) <= $s->getMaxStackSize()){ $this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $s->count + $item->count), false); }else{ $f1 = 0.3; diff --git a/src/material/Item.php b/src/material/Item.php index b4110055..b7997318 100755 --- a/src/material/Item.php +++ b/src/material/Item.php @@ -133,6 +133,10 @@ class Item{ public $id; public $meta; public $count; + /** + * @var int + * Max stack size of the item. Use Item::getMaxStackSize to get stack size for specific item. + */ public $maxStackSize = 64; public $durability = 0; public $name; diff --git a/src/material/item/generic/BucketItem.php b/src/material/item/generic/BucketItem.php index 8b0ccb84..79e9d765 100644 --- a/src/material/item/generic/BucketItem.php +++ b/src/material/item/generic/BucketItem.php @@ -10,20 +10,31 @@ class BucketItem extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(BUCKET, $meta, $count, "Bucket"); $this->isActivable = true; - $this->maxStackSize = 1; + $this->maxStackSize = 16; $this->name = BucketItem::$possiblenames[$this->meta]; } + public function getMaxStackSize(){ + if($this->getMetadata() == 0) return 16; + return 1; + } + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($this->meta === AIR){ if($target instanceof LiquidBlock && $target->getMetadata() == 0){ $level->setBlock($target, new AirBlock(), true, false, true); if(($player->gamemode & 0x01) === 0){ - $this->meta = match($target->getID()){ + $meta = match($target->getID()){ WATER, STILL_WATER => WATER, LAVA, STILL_LAVA => LAVA, default => 0 }; + if($this->count <= 1){ + $this->meta = $meta; + }else{ + --$this->count; + $player->addItem(BUCKET, $meta, 1); + } } return true; } @@ -33,7 +44,12 @@ class BucketItem extends Item{ $level->setBlock($block, $water, true, false, true); //$water->place($this, $player, $block, $target, $face, $fx, $fy, $fz); if(($player->gamemode & 0x01) === 0){ - $this->meta = 0; + if($this->count <= 1){ + $this->meta = 0; + }else{ + --$this->count; + $player->addItem(BUCKET, $meta, 0); + } } return true; } @@ -43,7 +59,12 @@ class BucketItem extends Item{ $level->setBlock($block, $lava, true, false, true); //$lava->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz); if(($player->gamemode & 0x01) === 0){ - $this->meta = 0; + if($this->count <= 1){ + $this->meta = 0; + }else{ + --$this->count; + $player->addItem(BUCKET, $meta, 0); + } } return true; }