示例#1
0
 public function moveOrMergeItem($index, $item, $from)
 {
     $emptyIndex = -1;
     // TODO (vy): Should grab the item's const max stack size.
     $maxStack = 64;
     for ($i = 0; $i < $this->length; $i++) {
         if ($this->Items[$i]->isEmpty() && $emptyIndex == -1) {
             $emptyIndex == $i;
         } else {
             if ($this->Items[$i]->id == $item->id && $this->Items[$i]->metadata == $item->metadata && $this->Items[$i]->icount < $maxStack) {
                 $emptyIndex = -1;
                 if ($from != null) {
                     $from->Items[$index] = ItemStack::emptyStack();
                 }
                 // If mergine two stacks becomes more than max stack, we create one with max size
                 // and create one with the remainder.
                 if ($this->Items[$i]->icount + $item->icount > $maxStack) {
                     $item = new ItemStack($item->id, $this->icount - ($maxStack - $this->Items[$i]->icount), $this->metadata, $this->nbt);
                     $this->Items[$i] = new ItemStack($item->id, $maxStack);
                 }
                 $this->Items[$i] = new ItemStack($item->id, $this->Items[$i]->icount + $item->icount, $item->metadata);
                 return $i;
             }
         }
     }
 }
 public function moveOrMergeItem($index, $slot, $from)
 {
     for ($i = 0; $i < $this->length; $i++) {
         if ($this->isValid($slot, $i)) {
             if (empty($this->Items[$i])) {
                 $this->Items[$i] = $slot;
                 $from->Items[$i] = ItemStack::emptyStack();
                 return $i;
             }
         }
     }
     return -1;
 }
 public function handleWindowChange($index, $value)
 {
     $current = $CraftingRepository->getRecipe($this->Bench());
     if ($index == self::craftingOutput) {
         if (empty($value) && $current != null) {
             $this->removeItemFromOutput($current);
             $current = $CraftingRepository->getRecipe($this->Bench());
         }
     }
     if ($current == null) {
         $this->Items[self::craftingOutput] = ItemStack::emptyStack();
     } else {
         $this->Items[self::craftingOutput] = $current->output();
     }
 }
示例#4
0
 public function getSlots()
 {
     $l = $this->windowAreaLength();
     $slots = array_fill(0, $l, 0);
     for ($i = 0; $i < $l; $i++) {
         $slots[$i] = ItemStack::emptyStack();
     }
     foreach ($this->WindowAreas as $Area) {
         for ($i = 0; $i < $Area->length; $i++) {
             $index = $Area->startIndex + $i;
             $slots[$index] = $Area->Items[$i];
         }
     }
     return $slots;
 }