empty buckets can be stacked now

This commit is contained in:
GameHerobrine 2025-04-11 22:37:39 +03:00
parent 938637b2a2
commit 012f03a52b
4 changed files with 35 additions and 6 deletions

3
.gitignore vendored
View file

@ -23,3 +23,6 @@ Desktop.ini
# Mac crap
.DS_Store
# nano
*.swp

View file

@ -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;

View file

@ -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;

View file

@ -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;
}