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

    Résolu TileEntity Item qui disparaissent

    1.7.x
    1.7.10
    2
    14
    2778
    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.
    • Yorwan
      Yorwan dernière édition par

      bonjour comme pour chaque message dans ce forum j’ai un problème : j’ai un containeur et quand j’essaie de mettre des item dedans a coup de ligne do code  çà ne marche pas : ils apparaissent pour dès que j’essaie d’en prendre un ils disparaissent , sauf si je met le ligne de code directement dans la l’update entity , merci de vos reponse .

      le class du tileEntity

      package com.mathiasetampes.entreprise.common;
      
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.init.Items;
      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 TileEntityDistributeur extends TileEntity implements IInventory
      {
      private ItemStack[] contents = new ItemStack[10]; //0, 1 et 2 sont les inputs et 3 est l'output
      
      @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);
         }
      @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");
      
                 if (j >= 0 && j < this.contents.length)
                 {
                     this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
                 }
             }    
         }
      @Override
      public ItemStack getStackInSlot(int slotIndex) { //Renvoie L'itemStack se trouvant dans le slot passé en argument
      return this.contents[slotIndex];
      }
      @Override
      public int getSizeInventory() { //Tout est dans le nom, retourne la taille de l'inventaire, pour notre bloc c'est quatre
      return this.contents.length;
      }
      @Override //Comme dit plus haut, c'est expliqué dans le tutoriel de robin
      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 true;
      }
      
      public void retirer(int money)
      {
      for(int monney;money>500;money-=500)
          {
      if(contents[1]==null)
          contents[1] = new ItemStack(Entreprise.cinqCent);
      else
      contents[1].stackSize +=1;
          }    
      for(int monney;money>200;money-=200)
          {    
      if(contents[2]==null)
      contents[2] = new ItemStack(Entreprise.deuxCent);
      else
      contents[2].stackSize +=1;    
          }    
      for(int monney;money>100;money-=100)
          {
      if(contents[3]==null)
      contents[3] = new ItemStack(Entreprise.cent);
      else
      contents[3].stackSize +=1;  
          }    
      for(int monney;money>50;money-=50)
          {
      if(contents[4]==null)
      contents[4] = new ItemStack(Entreprise.cinquante);
      else
      contents[4].stackSize +=1;  
          }    
      for(int monney;money>20;money-=20)
          {
      if(contents[5]==null)
      contents[5] = new ItemStack(Entreprise.vingt);
      else
      contents[5].stackSize +=1;    
          }    
      for(int monney;money>10;money-=10)
          {
      if(contents[6]==null)
      contents[6] = new ItemStack(Entreprise.dix);
      else
      contents[6].stackSize +=1;
          }    
      for(int monney;money>5;money-=5)
          {
      if(contents[7]==null)
      contents[7] = new ItemStack(Entreprise.cinq);
      else
      contents[7].stackSize +=1;  
          }    
      for(int monney;money>2;money-=2)
          {
      if(contents[8]==null)
      contents[8] = new ItemStack(Entreprise.deux);
      else
      contents[8].stackSize +=1;    
          }    
      for(int monney;money>1;money-=1)
          {
      if(contents[9]==null)
      contents[9] = new ItemStack(Entreprise.un);
      else
      contents[9].stackSize +=1;    
      }    
      }
      public void test()
      {
      contents[1] = new ItemStack(Items.apple);
      }
      public boolean code(int codeTmp)
      {
      if(codeTmp == 1234)
      {
      return true;
      }
      return false;
      }
      }
      
      1 réponse Dernière réponse Répondre Citer 0
      • robin4002
        robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

        this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
        à mettre à la fin de la fonction.

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

          tu a répondu super vite merci mais çà marche pas

          1 réponse Dernière réponse Répondre Citer 0
          • robin4002
            robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

            J’ai un lecteur de flux RSS sur mon pc, il me prévient dès qu’il y a une nouvelle discussion sur le fofo.


            Essayes avec la fonction this.makeDirty();

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

              non plus dommage

              –-----------------

              à noter que les items disparaissent si je quitte le gui

              1 réponse Dernière réponse Répondre Citer 0
              • robin4002
                robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

                Tu appelles la fonction retirer où ?

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

                  dans le gui quand j’appuye sur le bouton mais je pense pas que ce soit çà : quand j’appelai retirer ou test dans le updateEntitu çà marchiat pas non plus par contre si je crée un item directement de le updateEntity çà marche ; de plus lorsque je met un item dans le slot je peut le récuperez et il ne disparait pas quand je sors du gui

                  1 réponse Dernière réponse Répondre Citer 0
                  • robin4002
                    robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

                    En effet, si tu as un bouton sur le gui il faut passer par un paquet.

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

                      un paquet ? qu est ce que c’est ? j’ai l’impression d’étre un inculte un profane

                      1 réponse Dernière réponse Répondre Citer 0
                      • robin4002
                        robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

                        https://www.youtube.com/watch?v=YlQBEuEkBso

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

                          merciiiii robin . (sur le ton des alcoolique anonyme)

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

                            network.registerMessage(PacketDistributeur.Handler.class, PacketDistributeur.class, 0, Side.SERVER);

                            package com.mathiasetampes.entreprise.common;
                            
                            import net.minecraft.entity.player.EntityPlayerMP;
                            import net.minecraft.inventory.Container;
                            import io.netty.buffer.ByteBuf;
                            import cpw.mods.fml.common.network.simpleimpl.IMessage;
                            import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
                            import cpw.mods.fml.common.network.simpleimpl.MessageContext;
                            
                            public class PacketDistributeur implements IMessage
                            {
                            private int money;
                            
                            public PacketDistributeur(int money)
                            {
                            this.money = money;
                            }
                            public PacketDistributeur()
                            {
                            
                            }
                            
                            @Override
                            public void fromBytes(ByteBuf buf)
                            {
                            this.money = buf.readInt();
                            }
                            
                            @Override
                            public void toBytes(ByteBuf buf)
                            {
                            buf.writeInt(money);
                            }
                            public class Handler implements IMessageHandler <packetdistributeur,imessage>{
                            @Override
                            public IMessage onMessage(PacketDistributeur message, MessageContext ctx)
                            {
                            EntityPlayerMP player = ctx.getServerHandler().playerEntity;
                            Container c = player.openContainer;
                            if(c instanceof ContainerDistributeur)
                            {
                            TileEntityDistributeur tile = ((ContainerDistributeur)c).getTileDistributeur();
                            tile.retirer(money);
                            }
                            return null;
                            }
                            }
                            
                            }
                            
                            

                            et l’erreur
                            :::
                            [08:53:00] [Client thread/ERROR] [FML]: Caught exception from entreprise
                            java.lang.RuntimeException: java.lang.InstantiationException: com.mathiasetampes.entreprise.common.PacketDistributeur$Handler
                            at com.google.common.base.Throwables.propagate(Throwables.java:160) ~[guava-17.0.jar:?]
                            at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.instantiate(SimpleNetworkWrapper.java:116) ~[forgeSrc-1.7.10-10.13.2.1291.jar:?]
                            at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:106) ~[forgeSrc-1.7.10-10.13.2.1291.jar:?]
                            at com.mathiasetampes.entreprise.common.Entreprise.preInit(Entreprise.java:89) ~[bin/:?]
                            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_75]
                            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_75]
                            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_75]
                            at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_75]
                            at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) ~[forgeSrc-1.7.10-10.13.2.1291.jar:?]
                            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_75]
                            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_75]
                            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_75]
                            at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_75]
                            at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
                            at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
                            at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
                            at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
                            at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
                            at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[forgeSrc-1.7.10-10.13.2.1291.jar:?]
                            at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[forgeSrc-1.7.10-10.13.2.1291.jar:?]
                            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_75]
                            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_75]
                            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_75]
                            at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_75]
                            at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
                            at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
                            at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
                            at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
                            at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
                            at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) [LoadController.class:?]
                            at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:513) [Loader.class:?]
                            at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:239) [FMLClientHandler.class:?]
                            at net.minecraft.client.Minecraft.startGame(Minecraft.java:522) [Minecraft.class:?]
                            at net.minecraft.client.Minecraft.run(Minecraft.java:931) [Minecraft.class:?]
                            at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
                            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_75]
                            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_75]
                            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_75]
                            at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_75]
                            at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
                            at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
                            at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
                            at GradleStart.main(Unknown Source) [start/:?]
                            Caused by: java.lang.InstantiationException: com.mathiasetampes.entreprise.common.PacketDistributeur$Handler
                            at java.lang.Class.newInstance(Class.java:364) ~[?:1.7.0_75]
                            at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.instantiate(SimpleNetworkWrapper.java:113) ~[forgeSrc-1.7.10-10.13.2.1291.jar:?]
                            … 41 more
                            :::</packetdistributeur,imessage>

                            1 réponse Dernière réponse Répondre Citer 0
                            • robin4002
                              robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

                              public class Handler implements IMessageHandler <packetdistributeur,imessage>->
                              public static class Handler implements IMessageHandler<packetdistributeur,imessage></packetdistributeur,imessage></packetdistributeur,imessage>

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

                                a oui c’est vrai merci

                                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