10 janv. 2017, 18:44

@‘AymericRed’:

Je dois dire que ce n’est pas une mauvaise idée, l’adapterais donc le tuto prochainement, mais par contre dans le lien que tu as donné les valeurs dand la fonction sont les mêmes qu’ici.

Woops, effectivement ! Le comble c’est que je n’arrive plus à retrouver l’endroit exact où j’ai chopé ces valeurs, haha.
Pour me faire pardonner, je mets directement mon code ci-dessous (fonctionnant pour une table de craft 5x5 */!*)


   @Override
   public ItemStack    transferStackInSlot(EntityPlayer player, int slotId) {
       ItemStack       itemstack = null;
       Slot            slot = this.inventorySlots.get(slotId);

       if (slot != null && slot.getHasStack()) {
           ItemStack   itemstack1 = slot.getStack();

           itemstack = itemstack1.copy();

           /**
            *  If the slot belongs to the craftResult slot,
            *  Put the itemStack in the 27 slots player inventory
            */
           if (slotId == 0) {
               if (!this.mergeItemStack(itemstack1, 26, 62, true)) {
                   return (null);
               }
               slot.onSlotChange(itemstack1, itemstack);
           }

           /**
            *  If the slot belongs to the 27 slots player inventory,
            *  Put the itemStack in the 9 slots player hotbar
            */
           else if (slotId >= 26 && slotId < 53) {
               if (!this.mergeItemStack(itemstack1, 53, 62, false)) {
                   return (null);
               }
           }

           /**
            *  If the slot belongs to the 9 slots player hotbar,
            *  Put the itemStack in the 27 slots player inventory
            */
           else if (slotId >= 53 && slotId < 62) {
               if (!this.mergeItemStack(itemstack1, 26, 53, false)) {
                   return (null);
               }
           }

           /**
            * If the slot doesn't match with any of the if condition above,
            * Put the itemStack in the whole player inventory (hotbar + 27 slots)
            */
           else if (!this.mergeItemStack(itemstack1, 26, 62, false)) {
               return (null);
           }

           if (itemstack1.stackSize == 0) {
               slot.putStack((ItemStack) null);
           } else {
               slot.onSlotChanged();
           }

           if (itemstack1.stackSize == itemstack.stackSize) {
               return (null);
           }

           slot.onPickupFromSlot(player, itemstack1);
       }
       return (itemstack);
   }

J’ai même commenté pour que ce soit plus clair ! 😄

Je me permets encore une fois aux personnes qui liront ce message plus tard, qu’en fin de compte ces fameuses valeurs (26, 53, 62) sont propres à la taille du inventorySlots de votre container (qui change à chaque fois que vous faites this.addSlotToContainer). À vous d’adapter ces valeurs en fonction de la grille de craft 4x4, 6x6 ou 100x100, etc…