• Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Solved Machine à 2 slots .

    1.7.x
    1.7.10
    1
    2
    661
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      Raiigo last edited by

      Bonjour, j’ai créé un mode qui rajoute ( entre autre ) des bâtons à effets. J’aimerai pouvoir les améliorer ( que l’effets de potion soit plus puissant ) grâce à une machine à deux slots d’input ( entrée ) et 1 d’output ( sortie/résultat ). J’ai travaillé pendant longtemps dessus mais je n’ai réussis que à mettre les deux slots d’input et le slot d’output. Le problème s’est que les recettes ne marche pas.

      (Ma machine s’appelle machineUp)

      Merci à ce qui m’aideront

      Voici mes class :

      MachineUpRecipes :

      package nolann.juet.multiore.common.machineUp;
      
      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;
      import nolann.juet.multiore.common.MultiOre;
      
      public class MachineUpRecipes {
      
      private static final MachineUpRecipes smeltingBase = new MachineUpRecipes(); //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 MachineUpRecipes()
      {
      this.addRecipe(Items.apple, Items.apple, new ItemStack(Blocks.diamond_block));
      this.addRecipe(MultiOre.obsidianIngot, MultiOre.obsidianIngot, new ItemStack(MultiOre.obsidianPowder));
      }
      
      public void addRecipe(ItemStack stack1, ItemStack stack2, ItemStack stack) //Cette fonction de comprend que des ItemStack, c'est celle qui ajoute les recettes à la HashMap
      {
      ItemStack[] stackList = new ItemStack[]{stack1, stack2};
      this.smeltingList.put(stackList, stack);
      
      this.addRecipe(Items.apple, Items.apple, new ItemStack(Blocks.diamond_block));
      
      this.addRecipe(MultiOre.obsidianIngot, MultiOre.obsidianIngot, new ItemStack(MultiOre.obsidianPowder));
      
      }
      
              public void addRecipe(Item item1, Item item2, ItemStack stack) //1er cas
      {
      this.addRecipe(new ItemStack(item1), new ItemStack(item2), stack);
      
      this.addRecipe(Items.apple, Items.apple, new ItemStack(Blocks.diamond_block));
      this.addRecipe(MultiOre.obsidianIngot, MultiOre.obsidianIngot, new ItemStack(MultiOre.obsidianPowder));
      
      }
      
      public void addRecipe(Block block1, Item item2, ItemStack stack) //2nd cas
      {
      this.addRecipe(Item.getItemFromBlock(block1), item2, stack);
      }
      
      public void addRecipe(Block block1, Block block2, ItemStack stack) //3ème cas
      {
      this.addRecipe(Item.getItemFromBlock(block1), Item.getItemFromBlock(block2), 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<=3; ++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 MachineUpRecipes smelting()
      {
      return smeltingBase;
      }
      }
      
      

      GuiMachineUp :

      package nolann.juet.multiore.common.machineUp;
      
      import org.lwjgl.opengl.GL11;
      
      import net.minecraft.client.gui.inventory.GuiContainer;
      import net.minecraft.client.resources.I18n;
      import net.minecraft.entity.player.InventoryPlayer;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.util.ResourceLocation;
      import nolann.juet.multiore.common.ContainerMachineUp;
      import nolann.juet.multiore.common.MultiOre;
      
      public class GuiMachineUp extends GuiContainer {
      
      private static final ResourceLocation texture = new ResourceLocation(MultiOre.MODID,"textures/gui/container/guiMachineUp.png");
          @SuppressWarnings("unused")
      private TileEntityMachineUp tileMachineUp;
          private IInventory playerInv;
      
      public GuiMachineUp(TileEntityMachineUp tile, InventoryPlayer inventory) 
      {
      super(new ContainerMachineUp(tile, inventory));
              this.tileMachineUp = tile;
              this.playerInv = inventory;
              this.allowUserInput = false;
              this.ySize = 208;
              this.xSize = 196;
      }
      
      @Override
      protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y) 
      {
      
      GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
      this.mc.getTextureManager().bindTexture(texture);
      int k = (this.width - this.xSize) / 2;
      int l = (this.height - this.ySize) / 2;
      this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
      if(this.tileMachineUp.isBurning())
      {
      int i = this.tileMachineUp.getCookProgress(); //Nous créerons cette fonction après
      this.drawTexturedModalRect(k + 45, l + 60, 0, 209, i + 2, 16);
      }
      
      }
      
      protected void drawGuiContainerForegroundLayer(int x, int y)
          {
              this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName()), 10, this.ySize - 98, 4210752);
          }
      
      }
      
      

      MachineUp :

      package nolann.juet.multiore.common.machineUp;
      
      import net.minecraft.block.Block;
      import net.minecraft.block.BlockContainer;
      import net.minecraft.block.material.Material;
      import net.minecraft.entity.item.EntityItem;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.item.ItemStack;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraft.world.World;
      import nolann.juet.multiore.common.MultiOre;
      
      public class MachineUp extends BlockContainer 
      {
      
      public MachineUp()
      {
        super(Material.rock);
        this.setResistance(8.0F);
        this.setHarvestLevel("pickaxe", 2);
        this.setBlockTextureName(MultiOre.MODID + ":machine_up");
      }
      
      @Override
          public TileEntity createNewTileEntity(World world, int metadata) //Instancie le TileEntity
          {
              return new TileEntityMachineUp();
          }
      
          @Override
          public boolean hasTileEntity(int metadata) //Permet de savoir si le bloc a un TileEntity
          {
              return true;
          }
      
          public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
          {
              TileEntity tileentity = world.getTileEntity(x, y, z);
      
             if (tileentity instanceof IInventory)
             {
              IInventory inv = (IInventory)tileentity;
                 for (int i1 = 0; i1 < inv.getSizeInventory(); ++i1)
                 {
                     ItemStack itemstack = inv.getStackInSlot(i1);
      
                     if (itemstack != null)
                     {
                         float f = world.rand.nextFloat() * 0.8F + 0.1F;
                         float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
                         EntityItem entityitem;
      
                         for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem))
                         {
                             int j1 = world.rand.nextInt(21) + 10;
      
                             if (j1 > itemstack.stackSize)
                             {
                                 j1 = itemstack.stackSize;
                             }
      
                             itemstack.stackSize -= j1;
                             entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
                             float f3 = 0.05F;
                             entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);
                             entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F);
                             entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);
      
                             if (itemstack.hasTagCompound())
                             {
                                 entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
                             }
                         }
                     }
                 }
      
                 world.func_147453_f(x, y, z, block);
             }
      
              super.breakBlock(world, x, y, z, block, metadata);
          }
      
          public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitx, float hity, float hitz)
          {
              if (world.isRemote)
              {
                  return true;
              }
              else
              {
              player.openGui(MultiOre.instance, 0, world, x, y, z);
                  return true;
              }
          }
      
      }
      
      

      MachineUpRecipes :

      package nolann.juet.multiore.common.machineUp;
      
      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;
      import nolann.juet.multiore.common.MultiOre;
      
      public class MachineUpRecipes {
      
      private static final MachineUpRecipes smeltingBase = new MachineUpRecipes(); //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 MachineUpRecipes()
      {
      this.addRecipe(Items.apple, Items.apple, new ItemStack(Blocks.diamond_block));
      this.addRecipe(MultiOre.obsidianIngot, MultiOre.obsidianIngot, new ItemStack(MultiOre.obsidianPowder));
      }
      
      public void addRecipe(ItemStack stack1, ItemStack stack2, ItemStack stack) //Cette fonction de comprend que des ItemStack, c'est celle qui ajoute les recettes à la HashMap
      {
      ItemStack[] stackList = new ItemStack[]{stack1, stack2};
      this.smeltingList.put(stackList, stack);
      
      this.addRecipe(Items.apple, Items.apple, new ItemStack(Blocks.diamond_block));
      
      this.addRecipe(MultiOre.obsidianIngot, MultiOre.obsidianIngot, new ItemStack(MultiOre.obsidianPowder));
      
      }
      
              public void addRecipe(Item item1, Item item2, ItemStack stack) //1er cas
      {
      this.addRecipe(new ItemStack(item1), new ItemStack(item2), stack);
      
      this.addRecipe(Items.apple, Items.apple, new ItemStack(Blocks.diamond_block));
      this.addRecipe(MultiOre.obsidianIngot, MultiOre.obsidianIngot, new ItemStack(MultiOre.obsidianPowder));
      
      }
      
      public void addRecipe(Block block1, Item item2, ItemStack stack) //2nd cas
      {
      this.addRecipe(Item.getItemFromBlock(block1), item2, stack);
      }
      
      public void addRecipe(Block block1, Block block2, ItemStack stack) //3ème cas
      {
      this.addRecipe(Item.getItemFromBlock(block1), Item.getItemFromBlock(block2), 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<=3; ++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 MachineUpRecipes smelting()
      {
      return smeltingBase;
      }
      }
      
      

      SlotResultUp :

      package nolann.juet.multiore.common.machineUp;
      
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.inventory.Slot;
      import net.minecraft.item.ItemStack;
      
      public class SlotResultUp extends Slot {
      
          public SlotResultUp(IInventory inventory, int id, int x, int y) 
          {
              super(inventory, id, x, y);
          }
      
          @Override
          public boolean isItemValid(ItemStack stack) //Interdit la pose d'items dans le slot
         {
             return false;
         }
      
          public ItemStack decrStackSize(int amount)
         {
             return super.decrStackSize(amount);
         }
      
          public void onPickupFromSlot(EntityPlayer player, ItemStack stack)
         {
             super.onCrafting(stack);
             super.onPickupFromSlot(player, stack);
         }
      
      }
      
      

      TileEntityMachineUp :

      package nolann.juet.multiore.common.machineUp;
      
      import cpw.mods.fml.relauncher.Side;
      import cpw.mods.fml.relauncher.SideOnly;
      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.tileentity.TileEntity;
      
      public class TileEntityMachineUp extends TileEntity implements IInventory
      
      {
      private ItemStack[] contents = new ItemStack[3]; //0, 1 et 2 sont les inputs et 3 est l'output
      
      private int workingTime = 0; //Temps de cuisson actuel
      private int workingTimeNeeded = 200; //Temps de cuisson nécessaire
      
      @Override 
          public void writeToNBT(NBTTagCompound compound)
          {
              super.writeToNBT(compound);
              NBTTagList nbttaglist = new NBTTagList();
      
              for (int i = 0; i < this.contents.length; ++i) //pour les slots
              {
                  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); //On les enregistrent en short
              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) //Encore une fois pour les slots
              {
                  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"); //On lit nos valeurs
              this.workingTimeNeeded = compound.getShort("workingTimeNeeded");
          }
      
      public int getSizeInventory() { //Tout est dans le nom, retourne la taille de l'inventaire, pour notre bloc c'est quatre
      return this.contents.length;
      }
      
      public ItemStack getStackInSlot(int slotIndex) { //Renvoie L'itemStack se trouvant dans le slot passé en argument
      return this.contents[slotIndex];
      }
      
      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;
             }
      }
      
      public ItemStack getStackInSlotOnClosing(int slotIndex) {
      if (this.contents[slotIndex] != null)
              {
                  ItemStack itemstack = this.contents[slotIndex];
                  this.contents[slotIndex] = null;
                  return itemstack;
              }
              else
              {
                  return null;
              }
      }
      
      public void setInventorySlotContents(int slotIndex, ItemStack stack) {
      this.contents[slotIndex] = stack;
      
              if (stack != null && stack.stackSize > this.getInventoryStackLimit())
              {
                  stack.stackSize = this.getInventoryStackLimit();
              }
      
              this.markDirty();
      }
      
      public String getInventoryName() { //J'ai décider qu'on ne pouvait pas mettre de nom custom
      return "tile.machineTuto";
      }
      
      public boolean hasCustomInventoryName() {
      return false;
      }
      
      public int getInventoryStackLimit() {
      return 64;
      }
      
      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;
      }
      
      public void openInventory() {
      
      }
      
      public void closeInventory() {
      
      }
      
      public boolean isItemValidForSlot(int slot, ItemStack stack) {
      return slot == 3 ? 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) //Si les trois premiers slots sont vides
              {
                  return false; //On ne peut pas lancer le processus
              }
              else
              {
                  ItemStack itemstack = MachineUpRecipes.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; //rapport avec les recettes
                  if (this.contents[3] == null) return true; //vérifications du slot d'output
                  if (!this.contents[3].isItemEqual(itemstack)) return false; //ici aussi
                  int result = contents[3].stackSize + itemstack.stackSize;
                  return result <= getInventoryStackLimit() && result <= this.contents[3].getMaxStackSize(); //Et là aussi décidément
              }
          }
      
      public void updateEntity() //Méthode exécutée à chaque tick
          {
          if(this.isBurning() && this.canSmelt()) //Si on "cuit" et que notre recette et toujours bonne, on continue
          {
          ++this.workingTime; //incrémentation
          }
          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 = MachineUpRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1], this.contents[2]}); //On récupère l'output de la recette
                   if (this.contents[3] == null) //Si il y a rien dans le slot d'output
                   {
                        this.contents[3] = itemstack.copy(); //On met directement l'ItemStack
                   }
                   else if (this.contents[3].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[3].stackSize += itemstack.stackSize; // Alors ont incrémente l'ItemStack
                   }
      
                   –this.contents[0].stackSize; //On décrémente les slots d'input
                   –this.contents[1].stackSize;
                   –this.contents[2].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;
                   }
              }
          }
      
       @SideOnly(Side.CLIENT)
       public int getCookProgress()
       {
         return this.workingTime * 100 / this.workingTimeNeeded;
       }
      
      }
      
      

      GuiHandler :

      package nolann.juet.multiore.common;
      
      import cpw.mods.fml.common.network.IGuiHandler;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraft.world.World;
      import nolann.juet.multiore.common.machineUp.GuiMachineUp;
      import nolann.juet.multiore.common.machineUp.TileEntityMachineUp;
      
      public class GuiHandler implements IGuiHandler
      {
      @Override
      public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
      switch (ID) {
      
      case 0:
      TileEntity tile = world.getTileEntity(x, y, z);
      if(tile instanceof TileEntityMachineTuto)
      {
      return new ContainerMachineTuto((TileEntityMachineTuto)tile, player.inventory);
      }
      
      if(tile instanceof TileEntityMachineUp)
      {
      return new ContainerMachineUp((TileEntityMachineUp)tile, player.inventory);
      }
      
      }
      
      return null;
      }
      
      @Override
      public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
      switch (ID) {
      
      case 0:
      TileEntity tile = world.getTileEntity(x, y, z);
      if(tile instanceof TileEntityMachineTuto)
      {
      return new GuiMachineTuto((TileEntityMachineTuto)tile, player.inventory);
      }
      if(tile instanceof TileEntityMachineUp)
      {
      return new GuiMachineUp((TileEntityMachineUp)tile, player.inventory);
      }
      }
      
      return null;
      }
      
      }
      
      

      Mon Mod :

      :::

      Dragonite

      :::

      1 Reply Last reply Reply Quote 0
      • R
        Raiigo last edited by

        Up UP up


        J’ai réussi par pur hasard !!

        Pour ce qui voudrait faire la même machine que moi, je vous envoie les class.

        Maintenant à vous de comprendre le code et le modifier pour améliorer votre mode !!

        TileEntityMachineUp :

        
        package nolann.juet.multiore.common.machineUp;
        
        import cpw.mods.fml.relauncher.Side;
        import cpw.mods.fml.relauncher.SideOnly;
        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.tileentity.TileEntity;
        
        public class TileEntityMachineUp extends TileEntity implements IInventory
        
        {
        private ItemStack[] contents = new ItemStack[3]; //0, 1 et 2 sont les inputs et 3 est l'output
        
        private int workingTime = 0; //Temps de cuisson actuel
        private int workingTimeNeeded = 200; //Temps de cuisson nécessaire
        
        @Override 
            public void writeToNBT(NBTTagCompound compound)
            {
                super.writeToNBT(compound);
                NBTTagList nbttaglist = new NBTTagList();
        
                for (int i = 0; i < this.contents.length; ++i) //pour les slots
                {
                    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); //On les enregistrent en short
                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) //Encore une fois pour les slots
                {
                    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"); //On lit nos valeurs
                this.workingTimeNeeded = compound.getShort("workingTimeNeeded");
            }
        
        public int getSizeInventory() { //Tout est dans le nom, retourne la taille de l'inventaire, pour notre bloc c'est quatre
        return this.contents.length;
        }
        
        public ItemStack getStackInSlot(int slotIndex) { //Renvoie L'itemStack se trouvant dans le slot passé en argument
        return this.contents[slotIndex];
        }
        
        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;
               }
        }
        
        public ItemStack getStackInSlotOnClosing(int slotIndex) {
        if (this.contents[slotIndex] != null)
                {
                    ItemStack itemstack = this.contents[slotIndex];
                    this.contents[slotIndex] = null;
                    return itemstack;
                }
                else
                {
                    return null;
                }
        }
        
        public void setInventorySlotContents(int slotIndex, ItemStack stack) {
        this.contents[slotIndex] = stack;
        
                if (stack != null && stack.stackSize > this.getInventoryStackLimit())
                {
                    stack.stackSize = this.getInventoryStackLimit();
                }
        
                this.markDirty();
        }
        
        public String getInventoryName() { //J'ai décider qu'on ne pouvait pas mettre de nom custom
        return "tile.machineUp";
        }
        
        public boolean hasCustomInventoryName() {
        return false;
        }
        
        public int getInventoryStackLimit() {
        return 64;
        }
        
        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;
        }
        
        public void openInventory() {
        
        }
        
        public void closeInventory() {
        
        }
        
        public boolean isItemValidForSlot(int slot, ItemStack stack) {
        return slot == 2 ? false : true;
        }
        
        public boolean isBurning()
            {
                return this.workingTime > 0;
            }
        
        private boolean canSmelt()
            {
                if (this.contents[0] == null || this.contents[1] == null) //Si les trois premiers slots sont vides
                {
                    return false; //On ne peut pas lancer le processus
                }
                else
                {
        
                    ItemStack itemstack = MachineUpRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1]}); //Il y a une erreur ici, c'est normal, on y vient après (c'est pour les recettes)
                    if (itemstack == null) return false; //rapport avec les recettes
                    if (this.contents[2] == null) return true; //vérifications du slot d'output
                    if (!this.contents[2].isItemEqual(itemstack)) return false; //ici aussi
                    int result = contents[2].stackSize + itemstack.stackSize;
                    return result <= getInventoryStackLimit() && result <= this.contents[2].getMaxStackSize(); //Et là aussi décidément
        
                }
            }
        
        public void updateEntity() //Méthode exécutée à chaque tick
            {
            if(this.isBurning() && this.canSmelt()) //Si on "cuit" et que notre recette et toujours bonne, on continue
            {
            ++this.workingTime; //incrémentation
            }
            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 = MachineUpRecipes.smelting().getSmeltingResult(new ItemStack[]{this.contents[0], this.contents[1]}); //On récupère l'output de la recette
                     if (this.contents[2] == null) //Si il y a rien dans le slot d'output
                     {
                          this.contents[2] = itemstack.copy(); //On met directement l'ItemStack
                     }
                     else if (this.contents[2].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[2].stackSize += itemstack.stackSize; // Alors ont incrémente l'ItemStack
                     }
        
                     –this.contents[0].stackSize; //On décrémente les slots d'input
                     –this.contents[1].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;
                     }
                }
            }
        
         @SideOnly(Side.CLIENT)
         public int getCookProgress()
         {
           return this.workingTime * 100 / this.workingTimeNeeded;
         }
        
        }
        
        

        ContainerMachineUp :

        
        package nolann.juet.multiore.common.machineUp;
        
        import net.minecraft.entity.player.EntityPlayer;
        import net.minecraft.entity.player.InventoryPlayer;
        import net.minecraft.inventory.Container;
        import net.minecraft.inventory.Slot;
        import net.minecraft.item.ItemStack;
        
        public class ContainerMachineUp extends Container 
        
        {
        
        private TileEntityMachineUp tileMachineUp;
        
        public ContainerMachineUp(TileEntityMachineUp tile, InventoryPlayer inventory)
        {
                this.tileMachineUp = tile;
                this.addSlotToContainer(new Slot(tile, 0, 48, 28)); //Lancez votre jeu en debug pour calibrer vos slots
                this.addSlotToContainer(new Slot(tile, 1, 88, 28));
                this.addSlotToContainer(new SlotResultUp(tile, 2, 88, 88)); //Ici c'est un slot que j'ai créer, on le fera après
                this.bindPlayerInventory(inventory); //Les containers ont été vus dans un tutoriel de robin, merci de d'y référer
        }
        
        @Override
        public boolean canInteractWith(EntityPlayer player) {
        return this.tileMachineUp.isUseableByPlayer(player);
        }
        
        private void bindPlayerInventory(InventoryPlayer inventory)
        {
        int i;
        for (i = 0; i < 3; ++i)
                {
                    for (int j = 0; j < 9; ++j)
                    {
                        this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 17 + j * 18, 125 + i * 18));
                    }
                }
        
                for (i = 0; i < 9; ++i)
                {
                    this.addSlotToContainer(new Slot(inventory, i, 17 + i * 18, 183));
                }
        }
        
        public ItemStack transferStackInSlot(EntityPlayer player, int quantity)
            {
                ItemStack itemstack = null;
                Slot slot = (Slot)this.inventorySlots.get(quantity);
        
                if (slot != null && slot.getHasStack())
                {
                    ItemStack itemstack1 = slot.getStack();
                    itemstack = itemstack1.copy();
        
                    if (quantity < this.tileMachineUp.getSizeInventory())
                    {
                        if (!this.mergeItemStack(itemstack1, this.tileMachineUp.getSizeInventory(), this.inventorySlots.size(), true))
                        {
                            return null;
                        }
                    }
                    else if (!this.mergeItemStack(itemstack1, 0, this.tileMachineUp.getSizeInventory(), false))
                    {
                        return null;
                    }
        
                    if (itemstack1.stackSize == 0)
                    {
                        slot.putStack((ItemStack)null);
                    }
                    else
                    {
                        slot.onSlotChanged();
                    }
                }
        
                return itemstack;
            }
        
        public void onContainerClosed(EntityPlayer player)
            {
                super.onContainerClosed(player);
                this.tileMachineUp.closeInventory();
            }
        }
        
        

        GuiMachineUp :

        
        package nolann.juet.multiore.common.machineUp;
        
        import org.lwjgl.opengl.GL11;
        
        import net.minecraft.client.gui.inventory.GuiContainer;
        import net.minecraft.client.resources.I18n;
        import net.minecraft.entity.player.InventoryPlayer;
        import net.minecraft.inventory.IInventory;
        import net.minecraft.util.ResourceLocation;
        import nolann.juet.multiore.common.MultiOre;
        
        public class GuiMachineUp extends GuiContainer {
        
        private static final ResourceLocation texture = new ResourceLocation(MultiOre.MODID,"textures/gui/container/guiMachineUp.png");
            @SuppressWarnings("unused")
        private TileEntityMachineUp tileMachineUp;
            private IInventory playerInv;
        
        public GuiMachineUp(TileEntityMachineUp tile, InventoryPlayer inventory) 
        {
        super(new ContainerMachineUp(tile, inventory));
                this.tileMachineUp = tile;
                this.playerInv = inventory;
                this.allowUserInput = false;
                this.ySize = 208;
                this.xSize = 196;
        }
        
        @Override
        protected void drawGuiContainerBackgroundLayer(float partialRenderTick, int x, int y) 
        {
        
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(texture);
        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
        if(this.tileMachineUp.isBurning())
        {
        int i = this.tileMachineUp.getCookProgress(); //Nous créerons cette fonction après
        this.drawTexturedModalRect(k + 45, l + 60, 0, 209, i + 2, 16);
        }
        
        }
        
        protected void drawGuiContainerForegroundLayer(int x, int y)
            {
                this.fontRendererObj.drawString(this.playerInv.hasCustomInventoryName() ? this.playerInv.getInventoryName() : I18n.format(this.playerInv.getInventoryName()), 10, this.ySize - 98, 4210752);
            }
        
        }
        
        

        MachineUp :

        
        package nolann.juet.multiore.common.machineUp;
        
        import net.minecraft.block.Block;
        import net.minecraft.block.BlockContainer;
        import net.minecraft.block.material.Material;
        import net.minecraft.entity.item.EntityItem;
        import net.minecraft.entity.player.EntityPlayer;
        import net.minecraft.inventory.IInventory;
        import net.minecraft.item.ItemStack;
        import net.minecraft.nbt.NBTTagCompound;
        import net.minecraft.tileentity.TileEntity;
        import net.minecraft.world.World;
        import nolann.juet.multiore.common.MultiOre;
        
        public class MachineUp extends BlockContainer 
        {
        
        public MachineUp()
        {
          super(Material.rock);
          this.setResistance(8.0F);
          this.setHarvestLevel("pickaxe", 2);
          this.setBlockTextureName(MultiOre.MODID + ":machine_up");
        }
        
        @Override
            public TileEntity createNewTileEntity(World world, int metadata) //Instancie le TileEntity
            {
                return new TileEntityMachineUp();
            }
        
            @Override
            public boolean hasTileEntity(int metadata) //Permet de savoir si le bloc a un TileEntity
            {
                return true;
            }
        
            public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
            {
                TileEntity tileentity = world.getTileEntity(x, y, z);
        
               if (tileentity instanceof IInventory)
               {
                IInventory inv = (IInventory)tileentity;
                   for (int i1 = 0; i1 < inv.getSizeInventory(); ++i1)
                   {
                       ItemStack itemstack = inv.getStackInSlot(i1);
        
                       if (itemstack != null)
                       {
                           float f = world.rand.nextFloat() * 0.8F + 0.1F;
                           float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
                           EntityItem entityitem;
        
                           for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem))
                           {
                               int j1 = world.rand.nextInt(21) + 10;
        
                               if (j1 > itemstack.stackSize)
                               {
                                   j1 = itemstack.stackSize;
                               }
        
                               itemstack.stackSize -= j1;
                               entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
                               float f3 = 0.05F;
                               entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);
                               entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3 + 0.2F);
                               entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);
        
                               if (itemstack.hasTagCompound())
                               {
                                   entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
                               }
                           }
                       }
                   }
        
                   world.func_147453_f(x, y, z, block);
               }
        
                super.breakBlock(world, x, y, z, block, metadata);
            }
        
            public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitx, float hity, float hitz)
            {
                if (world.isRemote)
                {
                    return true;
                }
                else
                {
                player.openGui(MultiOre.instance, 0, world, x, y, z);
                    return true;
                }
            }
        
        }
        
        

        MachineUpRecipes :

        
        package nolann.juet.multiore.common.machineUp;
        
        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;
        import nolann.juet.multiore.common.MultiOre;
        
        public class MachineUpRecipes {
        
        private static final MachineUpRecipes smeltingBase = new MachineUpRecipes(); //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 MachineUpRecipes()
        {
        this.addRecipe(Items.apple, Items.apple, new ItemStack(Blocks.diamond_block)); //Ajout d'une recette, on fait un bloc de diamant à partie de deux pommes et une flèche
        
        }
        
        public void addRecipe(ItemStack stack1, ItemStack stack2, ItemStack stack3) //Cette fonction de comprend que des ItemStack, c'est celle qui ajoute les recettes à la HashMap
        {
        ItemStack[] stackList = new ItemStack[]{stack1, stack2};
        this.smeltingList.put(stackList, stack3);
        }
        
                public void addRecipe(Item item1, Item item2, ItemStack stack) //1er cas
        {
        this.addRecipe(new ItemStack(item1), new ItemStack(item2), stack);
        
        this.addRecipe(new ItemStack(MultiOre.obsidianIngot), new ItemStack(MultiOre.obsidianIngot), new ItemStack(MultiOre.obsidianPowder));
        this.addRecipe(new ItemStack(MultiOre.ironStick), new ItemStack(MultiOre.energieFragment), new ItemStack(MultiOre.ironStick));
        
        }
        
        public void addRecipe(Block block1, Item item2, ItemStack stack) //2nd cas
        {
        this.addRecipe(Item.getItemFromBlock(block1), item2, stack);
        }
        
        public void addRecipe(Block block1, Block block2, ItemStack stack) //3ème cas
        {
        this.addRecipe(Item.getItemFromBlock(block1), Item.getItemFromBlock(block2), 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<=1; ++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 MachineUpRecipes smelting()
        {
        return smeltingBase;
        }
        }
        
        

        SlotResultUp :

        
        package nolann.juet.multiore.common.machineUp;
        
        import net.minecraft.entity.player.EntityPlayer;
        import net.minecraft.inventory.IInventory;
        import net.minecraft.inventory.Slot;
        import net.minecraft.item.ItemStack;
        
        public class SlotResultUp extends Slot {
        
            public SlotResultUp(IInventory inventory, int id, int x, int y) 
            {
                super(inventory, id, x, y);
            }
        
            @Override
            public boolean isItemValid(ItemStack stack) //Interdit la pose d'items dans le slot
           {
               return false;
           }
        
            public ItemStack decrStackSize(int amount)
           {
               return super.decrStackSize(amount);
           }
        
            public void onPickupFromSlot(EntityPlayer player, ItemStack stack)
           {
               super.onCrafting(stack);
               super.onPickupFromSlot(player, stack);
           }
        
        }
        
        

        GuiHandler :

        
        package nolann.juet.multiore.common;
        
        import cpw.mods.fml.common.network.IGuiHandler;
        import net.minecraft.entity.player.EntityPlayer;
        import net.minecraft.tileentity.TileEntity;
        import net.minecraft.world.World;
        import nolann.juet.multiore.common.machineUp.ContainerMachineUp;
        import nolann.juet.multiore.common.machineUp.GuiMachineUp;
        import nolann.juet.multiore.common.machineUp.TileEntityMachineUp;
        
        public class GuiHandler implements IGuiHandler
        {
        @Override
        public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        switch (ID) {
        
        case 0:
        TileEntity tile = world.getTileEntity(x, y, z);
        if(tile instanceof TileEntityMachineTuto)
        {
        return new ContainerMachineTuto((TileEntityMachineTuto)tile, player.inventory);
        }
        
        if(tile instanceof TileEntityMachineUp)
        {
        return new ContainerMachineUp((TileEntityMachineUp)tile, player.inventory);
        }
        
        }
        
        return null;
        }
        
        @Override
        public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        switch (ID) {
        
        case 0:
        TileEntity tile = world.getTileEntity(x, y, z);
        if(tile instanceof TileEntityMachineTuto)
        {
        return new GuiMachineTuto((TileEntityMachineTuto)tile, player.inventory);
        }
        if(tile instanceof TileEntityMachineUp)
        {
        return new GuiMachineUp((TileEntityMachineUp)tile, player.inventory);
        }
        }
        
        return null;
        }
        
        }
        
        

        Voilà, j’espère que cela vous aura aidé !!!

        J’ai passé beaucoup de temps ( des jours ) pour réussir a faire fonctionner cette machine.

        Et faite attention car il y a du code lié à une autre machine dans le GuiHandler ( La machineTuto ) .

        Mon Mod :

        :::

        Dragonite

        :::

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Design by Woryk
        Contact / Mentions Légales

        MINECRAFT FORGE FRANCE © 2018

        Powered by NodeBB