slot should be always sent on interact now

This commit is contained in:
GameHerobrine 2023-01-11 12:50:14 +03:00
parent 21d0530d39
commit 5c153ac5da
3 changed files with 16 additions and 13 deletions

View file

@ -395,8 +395,11 @@ class BlockAPI{
if($target->onBreak($item, $player) === false){ if($target->onBreak($item, $player) === false){
return $this->cancelAction($target, $player, false); return $this->cancelAction($target, $player, false);
} }
if(($player->gamemode & 0x01) === 0 and $item->useOn($target) and $item->getMetadata() >= $item->getMaxDurability()){ $itemUse = $item->useOn($target);
$player->setSlot($player->slot, new Item(AIR, 0, 0), false); if(($player->gamemode & 0x01) === 0 and $itemUse and $item->getMetadata() >= $item->getMaxDurability()){
$player->setSlot($player->slot, new Item(AIR, 0, 0), true);
}elseif($itemUse){
$player->setSlot($player->slot, $item, true); //update slot meta TODO less packet sending?
} }
}else{ }else{
return $this->cancelAction($target, $player, false); return $this->cancelAction($target, $player, false);
@ -466,7 +469,7 @@ class BlockAPI{
if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){ if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){
if($item->count <= 0){ if($item->count <= 0){
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false); $player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), true);
} }
return false; return false;
} }
@ -508,7 +511,7 @@ class BlockAPI{
if(($player->gamemode & 0x01) === 0x00){ if(($player->gamemode & 0x01) === 0x00){
--$item->count; --$item->count;
if($item->count <= 0){ if($item->count <= 0){
$player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false); $player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), true);
} }
} }

View file

@ -1742,11 +1742,11 @@ class Player{
$packet->slots[$i] = 255; $packet->slots[$i] = 255;
}elseif($s->getID() !== AIR and $slot->getID() === AIR and ($sl = $this->hasItem($s->getID())) !== false){ }elseif($s->getID() !== AIR and $slot->getID() === AIR and ($sl = $this->hasItem($s->getID())) !== false){
$this->armor[$i] = $this->getSlot($sl); $this->armor[$i] = $this->getSlot($sl);
$this->setSlot($sl, BlockAPI::getItem(AIR, 0, 0), false); $this->setSlot($sl, BlockAPI::getItem(AIR, 0, 0), true);
}elseif($s->getID() !== AIR and $slot->getID() !== AIR and ($slot->getID() !== $s->getID() or $slot->getMetadata() !== $s->getMetadata()) and ($sl = $this->hasItem($s->getID())) !== false){ }elseif($s->getID() !== AIR and $slot->getID() !== AIR and ($slot->getID() !== $s->getID() or $slot->getMetadata() !== $s->getMetadata()) and ($sl = $this->hasItem($s->getID())) !== false){
$item = $this->armor[$i]; $item = $this->armor[$i];
$this->armor[$i] = $this->getSlot($sl); $this->armor[$i] = $this->getSlot($sl);
$this->setSlot($sl, $item, false); $this->setSlot($sl, $item, true);
}else{ }else{
$packet->slots[$i] = 255; $packet->slots[$i] = 255;
} }
@ -1851,7 +1851,7 @@ class Player{
$this->entity->heal($items[$slot->getID()], "eating"); $this->entity->heal($items[$slot->getID()], "eating");
--$slot->count; --$slot->count;
if($slot->count <= 0){ if($slot->count <= 0){
$this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false); $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), true);
} }
if($slot->getID() === MUSHROOM_STEW or $slot->getID() === BEETROOT_SOUP){ if($slot->getID() === MUSHROOM_STEW or $slot->getID() === BEETROOT_SOUP){
$this->addItem(BOWL, 0, 1, false); $this->addItem(BOWL, 0, 1, false);
@ -1885,7 +1885,7 @@ class Player{
$sZ += sin($f3) * $f1; $sZ += sin($f3) * $f1;
$this->server->api->entity->dropRawPos(new Position($this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $this->level), $packet->item, $sX, $sY, $sZ); $this->server->api->entity->dropRawPos(new Position($this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $this->level), $packet->item, $sX, $sY, $sZ);
$this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false); $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), true);
} }
if($this->entity->inAction === true){ if($this->entity->inAction === true){
$this->entity->inAction = false; $this->entity->inAction = false;
@ -2250,15 +2250,15 @@ class Player{
$s = $this->getSlot($slot); $s = $this->getSlot($slot);
$s->count -= $item->count; $s->count -= $item->count;
if($s->count <= 0){ if($s->count <= 0){
$this->setSlot($slot, BlockAPI::getItem(AIR, 0, 0), false); $this->setSlot($slot, BlockAPI::getItem(AIR, 0, 0), true);
} }
} }
foreach($craft as $slot => $item){ foreach($craft as $slot => $item){
$s = $this->getSlot($slot); $s = $this->getSlot($slot);
if($s->count <= 0 or $s->getID() === AIR){ if($s->count <= 0 or $s->getID() === AIR){
$this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $item->count), false); $this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $item->count), true);
}else{ }else{
$this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $s->count + $item->count), false); $this->setSlot($slot, BlockAPI::getItem($item->getID(), $item->getMetadata(), $s->count + $item->count), true);
} }
switch($item->getID()){ switch($item->getID()){
case WORKBENCH: case WORKBENCH:

View file

@ -9,12 +9,12 @@ class FlintSteelItem extends ItemTool{
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ 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()){ if(($player->gamemode & 0x01) === 0 and $this->useOn($block) and $this->getMetadata() >= $this->getMaxDurability()){
$player->setSlot($player->slot, new Item(AIR, 0, 0), false); $player->setSlot($player->slot, new Item(AIR, 0, 0), true); //TODO check
} }
if($block->getID() === AIR and ($target instanceof SolidBlock)){ if($block->getID() === AIR and ($target instanceof SolidBlock)){
$level->setBlock($block, new FireBlock(), true, false, true); $level->setBlock($block, new FireBlock(), true, false, true);
$block->level->scheduleBlockUpdate(new Position($block, 0, 0, $block->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); $block->level->scheduleBlockUpdate($block, Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true; return true;
} }
return false; return false;