MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Problème machine

    Planifier Épinglé Verrouillé Déplacé Résolu 1.7.x
    1.7.10
    4 Messages 3 Publieurs 1.2k Vues 1 Watching
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • I Hors-ligne
      Iska
      dernière édition par

      Bonjour ,
      J’ai un problème : sur ma machine la recette ne veut pas s’effectuer 😕
      Mes classes :
      TileTaneurTable :

      public class TileTaneurTable extends TileEntity implements IInventory {
      
      private ItemStack[] contents = new ItemStack[17]; 
      private int workingTime = 0; 
      private int workingTimeNeeded = 200; 
      
      @Override 
          public void writeToNBT(NBTTagCompound compound)
          {
              super.writeToNBT(compound);
              NBTTagList nbttaglist = new NBTTagList();
      
              for (int i = 0; i < this.contents.length; ++i) 
              {
                  if (this.contents* != null)
                  {
                      NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                      nbttagcompound1.setByte("Slot", (byte)i);
                      this.contents*.writeToNBT(nbttagcompound1);
                      nbttaglist.appendTag(nbttagcompound1);
                  }
              }
      
              compound.setTag("Items", nbttaglist);
              compound.setShort("workingTime",(short)this.workingTime); 
              compound.setShort("workingTimeNeeded", (short)this.workingTimeNeeded);
          }
      
      @Override
          public void readFromNBT(NBTTagCompound compound)
          {
              super.readFromNBT(compound);
      
              NBTTagList nbttaglist = compound.getTagList("Items", 10);
              this.contents = new ItemStack[this.getSizeInventory()];
      
              for (int i = 0; i < nbttaglist.tagCount(); ++i) 
              {
                  NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                  int j = nbttagcompound1.getByte("Slot") & 255;
      
                  if (j >= 0 && j < this.contents.length)
                  {
                      this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                  }
              }
      
              this.workingTime = compound.getShort("workingTime"); 
              this.workingTimeNeeded = compound.getShort("workingTimeNeeded");
          }
      
      @Override
      public int getSizeInventory() { 
      return this.contents.length;
      }
      
      @Override
      public ItemStack getStackInSlot(int slotIndex) { 
      return this.contents[slotIndex];
      }
      @SideOnly(Side.CLIENT)
      public int getCookProgress()
      {
      return this.workingTime * 33 / this.workingTimeNeeded; //33 correspond à la hauteur de la barre de progression car notre barre de progression se déroule de haut en bas
      }
      @Override 
      public ItemStack decrStackSize(int slotIndex, int amount) {
      if (this.contents[slotIndex] != null)
             {
                 ItemStack itemstack;
      
                 if (this.contents[slotIndex].stackSize <= amount)
                 {
                     itemstack = this.contents[slotIndex];
                     this.contents[slotIndex] = null;
                     this.markDirty();
                     return itemstack;
                 }
                 else
                 {
                     itemstack = this.contents[slotIndex].splitStack(amount);
      
                     if (this.contents[slotIndex].stackSize == 0)
                     {
                         this.contents[slotIndex] = null;
                     }
      
                     this.markDirty();
                     return itemstack;
                 }
             }
             else
             {
                 return null;
             }
      }
      
      @Override
      public ItemStack getStackInSlotOnClosing(int slotIndex) {
      if (this.contents[slotIndex] != null)
              {
                  ItemStack itemstack = this.contents[slotIndex];
                  this.contents[slotIndex] = null;
                  return itemstack;
              }
              else
              {
                  return null;
              }
      }
      
      @Override
      public void setInventorySlotContents(int slotIndex, ItemStack stack) {
      this.contents[slotIndex] = stack;
      
              if (stack != null && stack.stackSize > this.getInventoryStackLimit())
              {
                  stack.stackSize = this.getInventoryStackLimit();
              }
      
              this.markDirty();
      }
      
      @Override
      public String getInventoryName() { 
      return "tile.machineTuto";
      }
      
      @Override
      public boolean hasCustomInventoryName() {
      return false;
      }
      
      @Override
      public int getInventoryStackLimit() {
      return 64;
      }
      
      @Override
      public boolean isUseableByPlayer(EntityPlayer player) {
      return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
      }
      
      @Override
      public void openInventory() {
      
      }
      
      @Override
      public void closeInventory() {
      
      }
      
      @Override
      public boolean isItemValidForSlot(int slot, ItemStack stack) {
      return slot == 16 ? false : true;
      }
      
      public boolean isBurning()
          {
      return this.workingTime > 0;
      }
      
      private boolean canSmelt()
          {
              if (this.contents[0] == null || this.contents[1] == null || this.contents[2] == null|| this.contents[3] == null|| this.contents[4] == null|| this.contents[5] == null|| this.contents[6] == null|| this.contents[7] == null|| this.contents[8] == null || this.contents[9] == null|| this.contents[10] == null|| this.contents[11] == null|| this.contents[12] == null|| this.contents[13] == null|| this.contents[14] == null|| this.contents[15] == null) 
              {
                  return false; //On ne peut pas lancer le processus
              }
              else
              {
                  ItemStack itemstack = TaneurTableRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]}); //Il y a une erreur ici, c'est normal, on y vient après (c'est pour les recettes)
                  if (itemstack == null) return false; 
                  if (this.contents[3] == null) return true; 
                  if (!this.contents[3].isItemEqual(itemstack)) return false;
                  int result = contents[3].stackSize + itemstack.stackSize;
                  return result <= getInventoryStackLimit() && result <= this.contents[3].getMaxStackSize(); 
              }
          }
      
      public void updateEntity() 
          {
          if(this.isBurning() && this.canSmelt()) 
          {
          ++this.workingTime; 
          }
          if(this.canSmelt() && !this.isBurning()) //Si la recette est bonne mais qu'elle n'est toujours pas lancée, on la lance
          {
          this.workingTime = 1; //La méthode isBurning() renverra true maintenant (1>0)
          }
          if(this.canSmelt() && this.workingTime == this.workingTimeNeeded) //Si on est arrivé au bout du temps de cuisson et que la recette est toujours bonne
          {
          this.smeltItem(); //on "cuit" les items
          this.workingTime = 0; //et on réinitialise le temps de cuisson
          }
              if(!this.canSmelt()) //Si la recette la recette n'est plus bonne
              {
                     this.workingTime= 0; //le temps de cuisson est de 0
              }
          }
      
      public void smeltItem()
          {
              if (this.canSmelt())
              {
                  ItemStack itemstack = TaneurTableRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2], this.contents[3], this.contents[4], this.contents[5], this.contents[6], this.contents[7], this.contents[8], this.contents[9], this.contents[10], this.contents[11], this.contents[12], this.contents[13], this.contents[14], this.contents[15]}); //On récupère l'output de la recette
                   if (this.contents[16] == null) //Si il y a rien dans le slot d'output
                   {
                        this.contents[16] = itemstack.copy(); //On met directement l'ItemStack
                   }
                   else if (this.contents[16].getItem() == itemstack.getItem()) //Et si l'item que l'on veut est le même que celui qu'il y a déjà
                   {
                        this.contents[16].stackSize += itemstack.stackSize; // Alors ont incrémente l'ItemStack
                   }
      
                   –this.contents[0].stackSize; 
                   –this.contents[1].stackSize;
                   –this.contents[2].stackSize;
                   –this.contents[3].stackSize; 
                   –this.contents[4].stackSize;
                   –this.contents[5].stackSize;
                   –this.contents[6].stackSize; 
                   –this.contents[7].stackSize;
                   –this.contents[8].stackSize;
                   –this.contents[9].stackSize; 
                   –this.contents[10].stackSize;
                   –this.contents[11].stackSize;
                   –this.contents[12].stackSize; 
                   –this.contents[13].stackSize;
                   –this.contents[14].stackSize;
                   –this.contents[15].stackSize; 
      
                   if (this.contents[0].stackSize <= 0) //Si les slots sont vides, on remet à null le slot
                   {
                       this.contents[0] = null;
                   }
                   if (this.contents[1].stackSize <= 0)
                   {
                       this.contents[1] = null;
                   }
                   if (this.contents[2].stackSize <= 0)
                   {
                       this.contents[2] = null;
                   }
      
                   if (this.contents[3].stackSize <= 0)
                   {
                       this.contents[3] = null;
                   }
                   if (this.contents[4].stackSize <= 0)
                   {
                       this.contents[4] = null;
                   }
                   if (this.contents[5].stackSize <= 0)
                   {
                       this.contents[5] = null;
                   }
                   if (this.contents[6].stackSize <= 0)
                   {
                       this.contents[6] = null;
                   }
                   if (this.contents[7].stackSize <= 0)
                   {
                       this.contents[7] = null;
                   }
                   if (this.contents[8].stackSize <= 0)
                   {
                       this.contents[8] = null;
                   }
                   if (this.contents[9].stackSize <= 0)
                   {
                       this.contents[9] = null;
                   }
                   if (this.contents[10].stackSize <= 0)
                   {
                       this.contents[10] = null;
                   }
                   if (this.contents[11].stackSize <= 0)
                   {
                       this.contents[11] = null;
                   }
                   if (this.contents[12].stackSize <= 0)
                   {
                       this.contents[12] = null;
                   }
                   if (this.contents[13].stackSize <= 0)
                   {
                       this.contents[13] = null;
                   }
                   if (this.contents[14].stackSize <= 0)
                   {
                       this.contents[14] = null;
                   }
                   if (this.contents[15].stackSize <= 0)
                   {
                       this.contents[15] = null;
                   }
      
              }
          }
      }
      
      

      ContainerTaneurTable

      public class ContainerTaneurTable extends Container {
      
      private TileTaneurTable tileMachineTuto;
      private int i;
      
      public ContainerTaneurTable(TileTaneurTable tile, InventoryPlayer inventory)
      {
              this.tileMachineTuto = tile;
              this.addSlotToContainer(new Slot(tile, 0, 11, 93)); 
              this.addSlotToContainer(new Slot(tile, 1, 29, 93));
              this.addSlotToContainer(new Slot(tile, 2, 47, 93)); 
              this.addSlotToContainer(new Slot(tile, 3, 65, 93));
      
              this.addSlotToContainer(new Slot(tile, 4, 11, 111)); 
              this.addSlotToContainer(new Slot(tile, 5, 29, 111));
              this.addSlotToContainer(new Slot(tile, 6, 47, 111)); 
              this.addSlotToContainer(new Slot(tile, 7, 65, 111));
      
              this.addSlotToContainer(new Slot(tile, 8, 11, 129)); 
              this.addSlotToContainer(new Slot(tile, 9, 29, 129));
              this.addSlotToContainer(new Slot(tile, 10, 47, 129)); 
              this.addSlotToContainer(new Slot(tile, 11, 65, 129));
      
              this.addSlotToContainer(new Slot(tile, 12, 11, 147)); 
              this.addSlotToContainer(new Slot(tile, 13, 29, 147));
              this.addSlotToContainer(new Slot(tile, 14, 47, 147)); 
              this.addSlotToContainer(new Slot(tile, 15, 65, 147));
      
              this.addSlotToContainer(new SlotResult(tile, 16, 137, 124)); 
              this.bindPlayerInventory(inventory); 
      }
      
      private void bindPlayerInventory(InventoryPlayer inventory)
       {
         for (int i = 0; i < 3; i++) {
           for (int j = 0; j < 9; j++) {
             addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 17 + j * 18, 171 + i * 18));
           }
         }
         for (i = 0; i < 9; i++) {
           addSlotToContainer(new Slot(inventory, i, 17 + i * 18, 229));
         }
       }
      
       public ItemStack transferStackInSlot(EntityPlayer player, int slot)
       {
         ItemStack stack = null;
         Slot slots = (Slot)this.inventorySlots.get(slot);
         if ((slots != null) && (slots.getHasStack()))
         {
           ItemStack stack1 = slots.getStack();
           stack = stack1.copy();
           if (slot < 2)
           {
             if (!mergeItemStack(stack1, 3, 38, true)) {
               return null;
             }
             slots.onSlotChange(stack1, stack);
           }
           if ((slot >= 2) && 
             (!mergeItemStack(stack1, 0, 1, true))) {
             return null;
           }
           if (stack1.stackSize == 0) {
             slots.putStack((ItemStack)null);
           } else {
             slots.onSlotChanged();
           }
           if (stack1.stackSize == stack.stackSize) {
             return null;
           }
           slots.onPickupFromSlot(player, stack1);
         }
         return stack;
       }
      
       public void onContainerClosed(EntityPlayer player)
       {
         super.onContainerClosed(player);
         this.tileMachineTuto.closeInventory();
       }
      
       public boolean canInteractWith(EntityPlayer player)
       {
         return this.tileMachineTuto.isUseableByPlayer(player);
       }
      }
      
      

      GuiTaneurTable

      public class GuiTaneurTable extends GuiContainer {
      
      private static final ResourceLocation texture = new ResourceLocation("citrine:textures/gui/container/GuiTaneurTable.png");
          private TileTaneurTable tileCompressor;
          private IInventory playerInv;
      
       public GuiTaneurTable(TileTaneurTable tileCompressor, InventoryPlayer inventory)
       {
         super(new ContainerTaneurTable(tileCompressor, inventory));
         this.tileCompressor = tileCompressor;
         this.playerInv = inventory;
         this.allowUserInput = true;
         this.ySize = 340;
         this.xSize = 200;
       }
      
       protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y)
       {
         GL11.glColor4f(1.0F, 1.5F, 1.0F, 1.0F);
         this.mc.getTextureManager().bindTexture(texture);
         int k = (this.width - this.xSize) / 2;
         int l = (this.height - this.ySize) / 2;
         drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
         if (this.tileCompressor.isBurning())
         {
           int i = this.tileCompressor.getCookProgress();
           drawTexturedModalRect(k + 80, l + 117, 215, 117, 30, i);
         }
       }
      
       protected void drawGuiContainerForegroundLayer(int x, int y)
       {
         this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName(), new Object[0]), 15, this.ySize - 180, 4210752);
       }
      }
      
      

      TaneurTableRecipes :

      public class TaneurTableRecipes {private static final TaneurTableRecipes smeltingBase = new TaneurTableRecipes(); //Permet d'instancier votre classe car vous le l'instancierez nul part ailleur
      private Map smeltingList = new HashMap(); //Ceci permet de mettre vos recettes
      
      public TaneurTableRecipes()
      {
      this.addRecipe(Items.leather, Items.leather,Items.leather,Items.leather,Items.leather,Items.leather,Items.leather,Items.leather,Items.leather,Items.leather,Items.leather,Items.leather,Items.leather,Items.leather,Items.leather,Items.leather, new ItemStack(RegistryItems.pileOfSkin));
      }
      
      @SuppressWarnings("unchecked")
      public void addRecipe(ItemStack stack1, ItemStack stack2, ItemStack stack3, ItemStack stack4,ItemStack stack5,ItemStack stack6,ItemStack stack7,ItemStack stack8,ItemStack stack9,ItemStack stack10,ItemStack stack11,ItemStack stack12,ItemStack stack13,ItemStack stack14,ItemStack stack15,ItemStack stack16,ItemStack stack17) //Cette fonction de comprend que des ItemStack, c'est celle qui ajoute les recettes à la HashMap
      {
      ItemStack[] stackList = new ItemStack[]{stack1, stack2, stack3,stack4,stack5,stack6,stack7,stack8,stack9,stack10,stack11,stack12,stack13,stack14,stack15,stack16};
      this.smeltingList.put(stackList, stack17);
      }
      
          public void addRecipe(Item item1, Item item2, Item item3, Item item4, Item item5, Item item6, Item item7, Item item8, Item item9, Item item10, Item item11, Item item12, Item item13, Item item14, Item item15, Item item16, ItemStack stack) //1er cas
      {
      this.addRecipe(new ItemStack(item1), new ItemStack(item2), new ItemStack(item3), new ItemStack(item4), new ItemStack(item5), new ItemStack(item6), new ItemStack(item7), new ItemStack(item8), new ItemStack(item9), new ItemStack(item10), new ItemStack(item11), new ItemStack(item12), new ItemStack(item13), new ItemStack(item14), new ItemStack(item15), new ItemStack(item16), stack);
      }
      
      public ItemStack getSmeltingResult(ItemStack[] stack) //En argument : un tableau avec le contenu des trois slots d'input
       {
           Iterator iterator = this.smeltingList.entrySet().iterator();
           Entry entry;
      
           do
           {
               if (!iterator.hasNext()) // Si il n'y a plus de recettes dans la liste
               {
                   return null; //Il n'y a pas de recette correspondante
               }
             entry = (Entry)iterator.next(); //prend la recette suivante
         }
         while (!this.isSameKey(stack, (ItemStack[])entry.getKey())); //Check si le tableau passé en argument correspond à celui de la recette, vous avez une erreur ici, on crée la fonction tout de suite.
      
         return (ItemStack)entry.getValue(); //retourne l'itemstack : resultat de la recette
        }
      
      private boolean isSameKey(ItemStack[] stackList, ItemStack[] stackList2)
       {
      boolean isSame = false; //Au début ce n'est pas la même
      for(int i=0; i<=2; i++) // Pour les 3 items
      {
      if(stackList*.getItem() == stackList2*.getItem()) //On vérifie si ce sont les même
      {
      isSame = true; // Si c'est le cas alors isSame vaut true
      }
      else
      {
      return false; //Si un seul n'est pas bon, on cherche pas, c'est pas la bonne recette
      }
      }
      return isSame;
       }
      
      public Map getSmeltingList()
       {
         return this.smeltingList;
      }
      
      public static TaneurTableRecipes smelting()
      {
      return smeltingBase;
      }
      
      }
      
      

      Merci d’avance

      Iska qui vous aime
      :heart: :heart: :heart: :heart:

      1 réponse Dernière réponse Répondre Citer 0
      • SCAREXS Hors-ligne
        SCAREX
        dernière édition par

        Est-ce que tu comprends le code que tu as ?

        Site web contenant mes scripts : http://SCAREXgaming.github.io

        Pas de demandes de support par MP ni par skype SVP.
        Je n'accepte sur skype que l…

        1 réponse Dernière réponse Répondre Citer 0
        • I Hors-ligne
          Iska
          dernière édition par

          Ouais pourquoi ?

          Iska qui vous aime
          :heart: :heart: :heart: :heart:

          1 réponse Dernière réponse Répondre Citer 0
          • jglrxavpokJ Hors-ligne
            jglrxavpok Modérateurs
            dernière édition par

            Je pense que la question vient du fait que ton code est difficilement lisible et peu “propre”.
            Essaie de détailler un peu plus ton problème aussi.

            Modérateur sur MFF. 
            Mon Github: http://github.com/jglrxavpok
            Mon compte Steam si vous voulez jouer à CS:GO ou TF2 avec moi: https://steamcommunity.com/id/jglrxavpok/

            1 réponse Dernière réponse Répondre Citer 0
            • 1 / 1
            • Premier message
              Dernier message
            Design by Woryk
            ContactMentions Légales

            MINECRAFT FORGE FRANCE © 2024

            Powered by NodeBB