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

    Résolu TileEntity Cannot be cast to

    1.12.x
    1.12.x
    2
    10
    1295
    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.
    • R
      Reikenz dernière édition par

      J’ai créer un gui mais j’ai cette erreur :

      Caused by: java.lang.ClassCastException: gr8pefish.ironbackpacks.tileenitity.TileEntityPestle cannot be cast to net.minecraftforge.items.IItemHandler
      at gr8pefish.ironbackpacks.slot.SlotPestleOutput.<init>(SlotPestleOutput.java:22) ~[SlotPestleOutput.class:?]
      at gr8pefish.ironbackpacks.gui.ContainerPestle.<init>(ContainerPestle.java:22) ~[ContainerPestle.class:?]
      at gr8pefish.ironbackpacks.gui.GuiHandlerPestle.getServerGuiElement(GuiHandlerPestle.java:17) ~[GuiHandlerPestle.class:?]
      at net.minecraftforge.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:254) ~[NetworkRegistry.class:?]
      at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:87) ~[FMLNetworkHandler.class:?]
      at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2808) ~[EntityPlayer.class:?]
      at gr8pefish.ironbackpacks.blocks.BlockPestle.onBlockActivated(BlockPestle.java:93) ~[BlockPestle.class:?]
      at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:472) ~[PlayerInteractionManager.class:?]
      at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:767) ~[NetHandlerPlayServer.class:?]
      at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?]
      at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?]
      at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?]
      at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_152]
      at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_152]
      at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?]
      … 5 more
      

      Autre erreur :

      [20:06:29] [Server thread/ERROR] [FML]: A TileEntity type gr8pefish.ironbackpacks.tileenitity.TileEntityPestle has throw an exception trying to write state. It will not persist. Report this to the mod author
      java.lang.RuntimeException: class gr8pefish.ironbackpacks.tileenitity.TileEntityPestle is missing a mapping! This is a bug!
      at net.minecraft.tileentity.TileEntity.writeInternal(TileEntity.java:89) ~[TileEntity.class:?]
      at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:80) ~[TileEntity.class:?]
      at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:412) [AnvilChunkLoader.class:?]
      at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:183) [AnvilChunkLoader.class:?]
      at net.minecraft.world.gen.ChunkProviderServer.saveChunkData(ChunkProviderServer.java:214) [ChunkProviderServer.class:?]
      at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:242) [ChunkProviderServer.class:?]
      at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:1060) [WorldServer.class:?]
      at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:468) [MinecraftServer.class:?]
      at net.minecraft.server.integrated.IntegratedServer.saveAllWorlds(IntegratedServer.java:274) [IntegratedServer.class:?]
      at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:177) [IntegratedServer.class:?]
      at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590) [MinecraftServer.class:?]
      

      TileEntityPestle :

      
      

      package gr8pefish.ironbackpacks.tileenitity;

      import com.google.common.collect.Table;
      import gr8pefish.ironbackpacks.recipe.PestleRecipe;

      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.inventory.IInventory;
      import net.minecraft.inventory.ItemStackHelper;
      import net.minecraft.item.ItemStack;
      import net.minecraft.nbt.NBTTagCompound;
      import net.minecraft.tileentity.TileEntity;
      import net.minecraft.util.EnumFacing;
      import net.minecraft.util.ITickable;
      import net.minecraft.util.NonNullList;
      import net.minecraft.util.text.ITextComponent;
      import net.minecraft.util.text.TextComponentString;
      import net.minecraft.util.text.TextComponentTranslation;
      import net.minecraftforge.common.capabilities.Capability;
      import net.minecraftforge.common.capabilities.ICapabilityProvider;
      import net.minecraftforge.items.CapabilityItemHandler;
      import net.minecraftforge.items.IItemHandler;
      import net.minecraftforge.items.IItemHandlerModifiable;
      import net.minecraftforge.items.ItemStackHandler;

      public class TileEntityPestle extends TileEntity
      {

      public ItemStackHandler inventory = new ItemStackHandler(3)
         {
             @Override
             public int getSlotLimit(int slot)
             {
                 return 1;
             }

      @Override
             protected void onContentsChanged(int slot)
             {}
         };
         private String customName;

      public String getName()
         {
             return this.hasCustomName() ? this.customName : “Mortar and Pestle”;
         }

      public boolean hasCustomName()
         {
             return this.customName != null && !this.customName.isEmpty();
         }

      public void setCustomName(String customName)
         {
             this.customName = customName;
         }

      @Override
         public ITextComponent getDisplayName()
         {
             return this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.customName);
         }

      private boolean canCraft()
         {
             if(((ItemStack)this.inventory.getStackInSlot(0)).isEmpty() || ((ItemStack)this.inventory.getStackInSlot(1)).isEmpty())
                 return false;
             else
             {
                 ItemStack result = PestleRecipe.instance().getPestleResult((ItemStack)this.inventory.getStackInSlot(0), (ItemStack)this.inventory.getStackInSlot(1));

      if(result.isEmpty())
                     return false;
                 else
                 {
                     ItemStack output = (ItemStack)this.inventory.getStackInSlot(2);

      if(output.isEmpty())
                         return true;
                     if(!output.isItemEqual(result))
                         return false;
                     int res = output.getCount() + result.getCount();
                     return res <= this.inventory.getSlotLimit(1) && res <= output.getMaxStackSize();

      }

      }

      }

      public void craftItem()
         {
             if(this.canCraft())
             {
                 ItemStack input1 = (ItemStack)this.inventory.getStackInSlot(0);
                 ItemStack input2 = (ItemStack)this.inventory.getStackInSlot(1);
                 ItemStack result = PestleRecipe.instance().getPestleResult(input1, input2);
                 ItemStack output = (ItemStack)this.inventory.getStackInSlot(2);

      if(output.isEmpty())
                     this.inventory.setStackInSlot(2, result.copy());
                 else if(output.getItem() == result.getItem())
                     output.grow(result.getCount());

      input1.shrink(1);
                 input2.shrink(1);
             }
         }

      @Override
         public boolean hasCapability(Capability capability, EnumFacing facing)
         {
             if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
                 return true;
             return super.hasCapability(capability, facing);
         }

      @Override
         public <t>T getCapability(Capability <t>capability, EnumFacing facing)
         {
             if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
                 return (T)inventory;
             return super.getCapability(capability, facing);
         }

      }

      
      

      GuidHandlerPestle :

      
      

      package gr8pefish.ironbackpacks.gui;

      import gr8pefish.ironbackpacks.tileenitity.TileEntityPestle;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.util.math.BlockPos;
      import net.minecraft.world.World;
      import net.minecraftforge.fml.common.network.IGuiHandler;

      public class GuiHandlerPestle implements IGuiHandler
      {

      public static final int PESTLE_GUI = 0;
         public static final int FORGE_GUI = 0;

      @Override
         public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
         {
             if(ID == PESTLE_GUI)
                 return new ContainerPestle(player.inventory, ((TileEntityPestle)world.getTileEntity(new BlockPos(x, y, z))));
             return null;
         }

      @Override
         public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
         {
             if(ID == PESTLE_GUI)
                 return new GuiPestle(player.inventory, ((TileEntityPestle)world.getTileEntity(new BlockPos(x, y, z))));
             return null;
         }

      GuiPestle :

      
      

      package gr8pefish.ironbackpacks.gui;

      import gr8pefish.ironbackpacks.IronBackpacks;
      import gr8pefish.ironbackpacks.tileenitity.TileEntityPestle;

      import net.minecraft.client.gui.inventory.GuiContainer;
      import net.minecraft.client.renderer.GlStateManager;
      import net.minecraft.entity.player.InventoryPlayer;
      import net.minecraft.inventory.Container;
      import net.minecraft.util.ResourceLocation;

      public class GuiPestle extends GuiContainer{

      private static final ResourceLocation PESTLE_GUI_TEXTURE = new ResourceLocation(IronBackpacks.MODID + “:textures/gui/gui_pestle.png”);
      private final InventoryPlayer player;
      private final TileEntityPestle tileentity;

      public GuiPestle(InventoryPlayer player, TileEntityPestle tileentity) {
      super(new ContainerPestle(player, tileentity));
      this.player = player;
      this.tileentity = tileentity;
      }

      @Override
      protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
      String s = this.tileentity.getDisplayName().getUnformattedComponentText();
      this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
      this.fontRenderer.drawString(this.player.getDisplayName().getUnformattedComponentText(), 8, this.ySize - 96 + 2, 4210752);
      }

      @Override
      protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
      GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
      this.mc.getTextureManager().bindTexture(PESTLE_GUI_TEXTURE);
      this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);

      }

      }

      
      

      Voilà j’espère que vous pourrais m’aider :p</t></t></init></init>

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

        yo

        gr8pefish.ironbackpacks.slot.SlotPestleOutput

        pourquoi avoir pris le code du mod IronBackpack ?

        envoi cette class stp

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

          Je l’ai pris pour les backpacks ^^

          package gr8pefish.ironbackpacks.slot;
          
          import gr8pefish.ironbackpacks.recipe.PestleRecipe;
          import gr8pefish.ironbackpacks.tileenitity.TileEntityPestle;
          
          import net.minecraft.entity.player.EntityPlayer;
          import net.minecraft.inventory.IInventory;
          import net.minecraft.inventory.Slot;
          import net.minecraft.item.ItemStack;
          import net.minecraft.util.math.MathHelper;
          import net.minecraftforge.items.IItemHandler;
          import net.minecraftforge.items.SlotItemHandler;
          
          public class SlotPestleOutput extends SlotItemHandler
          {
          
             private final EntityPlayer player;
             private int removeCount;
          
             public SlotPestleOutput(EntityPlayer player, TileEntityPestle tileentity, int index, int xPosition, int yPosition)
             {
                 super((IItemHandler)tileentity, index, xPosition, yPosition);
                 this.player = player;
             }
          
             @Override
             public boolean isItemValid(ItemStack stack)
             {
                 return false;
             }
          
             @Override
             public ItemStack decrStackSize(int amount)
             {
                 if(this.getHasStack())
                     this.removeCount += Math.min(amount, this.getStack().getCount());
                 return super.decrStackSize(amount);
             }
          
             @Override
             public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
             {
                 this.onCrafting(stack);
                 super.onTake(player, stack);
                 return stack;
             }
          
             @Override
             protected void onCrafting(ItemStack stack, int amount)
             {
                 this.removeCount += amount;
                 this.onCrafting(stack);
             }
          
          }
          

          [size=small

          #s3gt_translate_tooltip_mini { display: none !important; }]

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

            super((IItemHandler)tileentity, index, xPosition, yPosition); ton tile entity n’implement pas l’interface IItemHandler c’est pour ca que ta une castExcep

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

              Donc je change quoi oui je débute donc je m’y connais pas trop

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

                copier du code complexe sans connaitre c’est pas conseiller 😕
                implement ta class rajoute a la declaration de class
                “implements IItemHandler”

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

                  Je met ma class en abstract ou je génère le code qu’il me dit ?

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

                    non faut pas la mettre en abstract gen le code
                    en gen le code ca va d’implementer les methods abstraites de l’interface

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

                      Et ensuite j’ai test sa crash:

                      Laclasse après:

                      
                      package fr.malyumod.slot;
                      
                      import fr.malyumod.recipe.PestleRecipe;
                      import fr.malyumod.tileenitity.TileEntityPestle;
                      import net.minecraft.entity.player.EntityPlayer;
                      import net.minecraft.inventory.IInventory;
                      import net.minecraft.inventory.Slot;
                      import net.minecraft.item.ItemStack;
                      import net.minecraft.util.math.MathHelper;
                      import net.minecraftforge.items.IItemHandler;
                      import net.minecraftforge.items.SlotItemHandler;
                      
                      public class SlotPestleOutput extends SlotItemHandler implements IItemHandler
                      {
                      
                          private final EntityPlayer player;
                          private int removeCount;
                      
                          public SlotPestleOutput(EntityPlayer player, TileEntityPestle tileentity, int index, int xPosition, int yPosition)
                          {
                              super((IItemHandler)tileentity, index, xPosition, yPosition);
                              this.player = player;
                          }
                      
                          @Override
                          public boolean isItemValid(ItemStack stack)
                          {
                              return false;
                          }
                      
                          @Override
                          public ItemStack decrStackSize(int amount)
                          {
                              if(this.getHasStack())
                                  this.removeCount += Math.min(amount, this.getStack().getCount());
                              return super.decrStackSize(amount);
                          }
                      
                          @Override
                          public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
                          {
                              this.onCrafting(stack);
                              super.onTake(player, stack);
                              return stack;
                          }
                      
                          @Override
                          protected void onCrafting(ItemStack stack, int amount)
                          {
                              this.removeCount += amount;
                              this.onCrafting(stack);
                          }
                      
                          @Override
                          public int getSlots()
                          {
                              // TODO Auto-generated method stub
                              return 0;
                          }
                      
                          @Override
                          public ItemStack getStackInSlot(int slot)
                          {
                              // TODO Auto-generated method stub
                              return null;
                          }
                      
                          @Override
                          public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
                          {
                              // TODO Auto-generated method stub
                              return null;
                          }
                      
                          @Override
                          public ItemStack extractItem(int slot, int amount, boolean simulate)
                          {
                              // TODO Auto-generated method stub
                              return null;
                          }
                      
                          @Override
                          public int getSlotLimit(int slot)
                          {
                              // TODO Auto-generated method stub
                              return 0;
                          }
                      
                      }
                      

                      [size=small

                      #s3gt_translate_tooltip_mini { display: none !important; }]

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

                        le crash log stp
                        il faut remplir les methods que ta implementées maintenant je peu pas d’aider je connais pas l’api de ironbackpacks
                        regarde selon les backpacks du mod comment il a fait et qu’a t-il mit dans ces methods

                        je crois plutôt que tu devrait refaire un item avec gui fait par toi histoire d’au moins y comprendre un truc mdr car la tu galère comme pas possible
                        si tu fait ton propre code ca devrait être intensément moins dur déjà

                        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