• S'inscrire
    • Se connecter
    • Recherche
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes

    Machine avec plusieurs input

    Sans suite
    1.7.10
    2
    3
    883
    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.
    • Infinite
      Infinite dernière édition par

      Bonjour ! ou reBonjour !
      J’ai créé une machine il y a très peu de temps grace au tuto de BrokenSwing mais j’aimerai avoir un craft avec plusieurs item en input dans chaque slot
      Exemple: “3 sticks dans le premier slot , 2 sticks dans le 2ème slot et enfin 1 charbon dans le 3ème slot donne 4 buches”
      La question a déja été posée dans le tuto en question mais aucune réponse n’a vraiment été donnée.

      Voici quelques classes potentiellement utile pour qu’on me fournisse de l’aide:

      La tile entity de ma machine :

      
      package com.iutils.infinite.tileentities;
      
      import com.iutils.infinite.recipes.CompressorRecipes;
      
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.item.ItemStack;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.nbt.NBTTagList;
      import net.minecraft.network.NetworkManager;
      import net.minecraft.network.Packet;
      import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraftforge.common.util.Constants;
      
      public class CompressorTE extends TileEntity implements IInventory
      {
          private ItemStack[] contents = new ItemStack[4];
          private String customName;
          private int workingTime = 0;
          private int workingTimeNeeded = 200;
      
          @Override
          public void readFromNBT(NBTTagCompound compound)
          {
              super.readFromNBT(compound);
      
              if (compound.hasKey("CustomName", Constants.NBT.TAG_STRING))
              {
                  this.customName = compound.getString("CustomName");
              }
      
              NBTTagList nbttaglist = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
              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 void writeToNBT(NBTTagCompound compound)
          {
              super.writeToNBT(compound);
              NBTTagList nbttaglist = new NBTTagList();
      
              if (this.hasCustomInventoryName())
              {
                  compound.setString("CustomName", this.customName);
              }
      
              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);
          }
      
          public Packet getDescriptionPacket()
          {
              NBTTagCompound nbttagcompound = new NBTTagCompound();
              this.writeToNBT(nbttagcompound);
              return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbttagcompound);
          }
      
          public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
          {
              this.readFromNBT(pkt.func_148857_g());
          }
      
          @Override
          public int getSizeInventory()
          {
              return this.contents.length;
          }
      
          @Override
          public ItemStack getStackInSlot(int slotIndex)
          {
              return this.contents[slotIndex];
          }
      
          @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 this.hasCustomInventoryName() ? this.customName : "tile.compressor.name";
          }
      
          @Override
          public boolean hasCustomInventoryName()
          {
              return this.customName != null && !this.customName.isEmpty();
          }
      
          public void setCustomName(String customName)
          {
              this.customName = customName;
          }
      
          @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 slotIndex, ItemStack stack)
          {
              return true;
          }
      
          public boolean isBurning()
          {
              return this.workingTime > 0;
          }
          private boolean canSmelt()
          {
              if (this.contents[0] == null || this.contents[1] == null || this.contents[2] == null)
              {
                  return false;
              }
              else
              {
                  ItemStack itemstack = CompressorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]});
                  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())
              {
                  this.workingTime = 1;
              }
              if(this.canSmelt() && this.workingTime == this.workingTimeNeeded)
              {
                  this.smeltItem();
                  this.workingTime = 0;
              }
              if(!this.canSmelt())
              {
                     this.workingTime= 0;
              }
              System.out.println("wT = " + workingTime);
              System.out.println("wTN = " + workingTimeNeeded);
          }
      
          public void smeltItem()
          {
              if (this.canSmelt())
              {
                  ItemStack itemstack = CompressorRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]});
                   if (this.contents[3] == null)
                   {
                        this.contents[3] = itemstack.copy();
                   }
                   else if (this.contents[3].getItem() == itemstack.getItem())
                   {
                        this.contents[3].stackSize += itemstack.stackSize;
                   }
      
                   –this.contents[0].stackSize;
                   –this.contents[1].stackSize;
                   –this.contents[2].stackSize;
      
                   if (this.contents[0].stackSize <= 0)
                   {
                       this.contents[0] = null;
                   }
                   if (this.contents[1].stackSize <= 0)
                   {
                       this.contents[1] = null;
                   }
                   if (this.contents[2].stackSize <= 0)
                   {
                       this.contents[2] = null;
                   }
              }
          }
      }
      
      

      La classe des recipes :

      
      package com.iutils.infinite.recipes;
      
      import java.util.HashMap;
      import java.util.Iterator;
      import java.util.Map;
      import java.util.Map.Entry;
      
      import net.minecraft.block.Block;
      import net.minecraft.init.Blocks;
      import net.minecraft.init.Items;
      import net.minecraft.item.Item;
      import net.minecraft.item.ItemStack;
      
      public class CompressorRecipes
      {
          private static final CompressorRecipes smeltingBase = new CompressorRecipes();
          private Map smeltingList = new HashMap();
      
          public CompressorRecipes()
          {
              this.addRecipe(Items.apple, Items.apple, Items.arrow, new ItemStack(Items.iron_helmet));
              this.addRecipe(Items.apple, Items.apple, Items.apple, new ItemStack(Items.golden_apple));
          }
      
          public void addRecipe(ItemStack stack1, ItemStack stack2, ItemStack stack3, ItemStack stack4)
          {
              ItemStack[] stackList = new ItemStack[]{stack1, stack2, stack3};
              this.smeltingList.put(stackList, stack4);
          }
      
              public void addRecipe(Item item1, Item item2, Item item3, ItemStack stack)
          {
              this.addRecipe(new ItemStack(item1), new ItemStack(item2), new ItemStack(item3), stack);
          }
      
          public void addRecipe(Block block1, Item item2, Item item3, ItemStack stack)
          {
              this.addRecipe(Item.getItemFromBlock(block1), item2, item3, stack);
          }
      
          public void addRecipe(Block block1, Block block2, Item item3, ItemStack stack)
          {
              this.addRecipe(Item.getItemFromBlock(block1), Item.getItemFromBlock(block2), item3, stack);
          }
      
          public void addRecipe(Block block1, Block block2, Block block3, ItemStack stack)
          {
              this.addRecipe(Item.getItemFromBlock(block1), Item.getItemFromBlock(block2), Item.getItemFromBlock(block3), stack);
          }
      
          public ItemStack getSmeltingResult(ItemStack[] stack)
          {
              Iterator iterator = this.smeltingList.entrySet().iterator();
              Entry entry;
      
              do
              {
                  if (!iterator.hasNext())
                  {
                      return null;
                  }
                 entry = (Entry)iterator.next();
             }
             while (!this.isSameKey(stack, (ItemStack[])entry.getKey()));
      
             return (ItemStack)entry.getValue();
           }
      
          private boolean isSameKey(ItemStack[] stackList, ItemStack[] stackList2)
          {
              boolean isSame = false;
              for(int i=0; i<=2; i++)
              {
                  if(stackList*.getItem() == stackList2*.getItem())
                  {
                      isSame = true;
                  }
                  else
                  {
                      return false;
                  }
              }
              return isSame;
          }
      
          public Map getSmeltingList()
          {
             return this.smeltingList;
          }
      
      public static CompressorRecipes smelting()
         {
             return smeltingBase;
         }
      }
      
      

      En espérant que quelqu’un puisse m’aider !

      Mes Sites(Mes Sites)
      |
      |    Site général : Game & play
      |   Site de projets (en dev !) :Infinite's Ressources
      J'ai et je suis content d'avoir 16,75 points d'ICRating

      1 réponse Dernière réponse Répondre Citer 0
      • AymericRed
        AymericRed dernière édition par

        Salut, alors je pense qu’il faudrait que tout simplement dans la fonction “isSameKey(ItemStack[] stackList, ItemStack[] stackList2)” de ta classe “CompressorRecipes” tu checkes si la taille du stack en input est plus grande ou égale à la taille spécifiée dans la recette (qu’il faudra changer). Il faudra aussi changer la fonction “smeltItem()” de ta machine pour que les items disparaissent correctement de leurs slots respectifs.

        Si je vous ai aidé, n'oubliez pas d’être heureux, j'aiderai encore +

        AymericRed, moddeur expérimenté qui aide sur ce forum et qui peut accepter de faire un mod Forge rémunéré de temps en temps.

        Mes tutos : Table de craft, plugin NEI, plugin JEI, modifier l'overlay
        Je suis un membre apprécié et joueur, j'ai déjà obtenu 6 points de réputation.

        1 réponse Dernière réponse Répondre Citer 0
        • Infinite
          Infinite dernière édition par

          Je sais vraiment pas comment faire pour enlever le nombre d’items que j’ai mis dans la recette parce que je doit récupérer des données de la class CompressorRecipes

          Mes Sites(Mes Sites)
          |
          |    Site général : Game & play
          |   Site de projets (en dev !) :Infinite's Ressources
          J'ai et je suis content d'avoir 16,75 points d'ICRating

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

          MINECRAFT FORGE FRANCE © 2018

          Powered by NodeBB