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

Résolu [1.7.10] - Gui ne s'ouvrant pas !

1.7.x
1.7.10
2
10
366
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.
  • ZunF1x
    ZunF1x dernière édition par ZunF1x 18 févr. 2019, 11:11 18 févr. 2019, 08:30

    Quand je clique sur le bloc en question sa fait bien l’annimation avec la main comme quoi je l’ai ouvert mais la gui ne s’affiche pas !!

    la classe du bloc en question:

    package fr.askipie.funfight;
    import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
    import net.minecraft.block.Block;
    import net.minecraft.block.material.Material;
    import net.minecraft.entity.EntityLivingBase;
    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;
    public class GUITutoriel extends Block
    {
    protected GUITutoriel(Material p_i45394_1_)
    {
    super(p_i45394_1_);
    }
    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(FunFight.instance, 0, world, x, y, z);
    return true;
    }
    }
    @Override
    public TileEntity createTileEntity(World world, int metadata)
    {
    return new TileEntityFungie();
    }
    public TileEntity createNewTileEntity(World world, int metadata) //Instancie le TileEntity
    {
    return new TileEntityFungie();
    }
    @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);
    }
    }

    le code du GUI Handler:

    package fr.askipie.funfight;
    import cpw.mods.fml.common.Mod.Instance;
    import cpw.mods.fml.common.network.IGuiHandler;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.world.World;
    public class GuiHandlerFungie implements IGuiHandler
    {
    @Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
    {
    TileEntity tile = world.getTileEntity(x, y, z);
    if(tile instanceof TileEntityFungie)
    {
    return new ContainerCupboard((TileEntityFungie)tile, player.inventory);
    }
    return null;
    }
    @Override
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
    {
    TileEntity tile = world.getTileEntity(x, y, z);
    if(tile instanceof TileEntityFungie)
    {
    return new GuiCupboard((TileEntityFungie)tile, player.inventory);
    }
    return null;
    }
    }

    la gui:

    package fr.askipie.funfight;
    import org.lwjgl.opengl.GL11;
    import cpw.mods.fml.common.network.IGuiHandler;
    import net.minecraft.client.gui.inventory.GuiContainer;
    import net.minecraft.client.resources.I18n;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.ResourceLocation;
    import net.minecraft.world.World;
    public class GuiCupboard implements IGuiHandler
    {
    public GuiCupboard(TileEntityFungie tile, InventoryPlayer inventory)
    {
    // TODO Auto-generated constructor stub
    }
    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 TileEntityFungie)
    {
    return new ContainerCupboard((TileEntityFungie)tile, player.inventory);
    }
    }
    return null;
    }
    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 TileEntityFungie)
    {
    return new GuiCupboard((TileEntityFungie)tile, player.inventory);
    }
    }
    return null;
    }
    }

    le container:

    package fr.askipie.funfight;
    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;
    import net.minecraft.tileentity.TileEntity;
    public class ContainerCupboard extends Container
    {
    private TileEntityFungie tileMachineFungie;
    public ContainerCupboard(TileEntityFungie tile, InventoryPlayer inventory)
    {
    }
    public void ContainerMachineTuto(TileEntityFungie tile, InventoryPlayer inventory)
    {
    this.tileMachineFungie = tile;
    this.addSlotToContainer(new Slot(tile, 0, 49, 75)); //Lancez votre jeu en debug pour calibrer vos slots
    this.addSlotToContainer(new Slot(tile, 1, 89, 75));
    this.addSlotToContainer(new Slot(tile, 2, 129, 75));
    this.addSlotToContainer(new SlotResult(tile, 3, 89, 135)); //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.tileMachineFungie.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, 171 + i * 18));
    }
    }
    for (i = 0; i < 9; ++i)
    {
    this.addSlotToContainer(new Slot(inventory, i, 17 + i * 18, 229));
    }
    }
    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.tileMachineFungie.getSizeInventory())
    {
    if (!this.mergeItemStack(itemstack1, this.tileMachineFungie.getSizeInventory(), this.inventorySlots.size(), true))
    {
    return null;
    }
    }
    else if (!this.mergeItemStack(itemstack1, 0, this.tileMachineFungie.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.tileMachineFungie.closeInventory();
    }
    }

    et le tile entity:

    package fr.askipie.funfight;
    import cpw.mods.fml.common.Mod.Instance;
    import cpw.mods.fml.common.network.NetworkRegistry;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.nbt.NBTTagList;
    import net.minecraft.network.NetworkManager;
    import net.minecraft.network.Packet;
    import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraftforge.common.util.Constants;
    public class TileEntityFungie extends TileEntity implements IInventory
    {
    private ItemStack[] contents = new ItemStack[4]; //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
    private String customName;
    @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
    public ItemStack getStackInSlot(int slotIndex) { //Renvoie L'itemStack se trouvant dans le slot passé en argument
    return this.contents[slotIndex];
    }
    @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() { //J'ai décider qu'on ne pouvait pas mettre de nom custom
    return "tile.machineTuto";
    }
    @Override
    public boolean hasCustomInventoryName() {
    return false;
    }
    @Override
    public int getInventoryStackLimit() {
    return 64;
    }
    @Override
    public boolean isUseableByPlayer(EntityPlayer player) {
    return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
    }
    @Override
    public void openInventory() {
    }
    @Override
    public void closeInventory() {
    }
    @Override
    public boolean isItemValidForSlot(int slot, ItemStack stack) {
    return slot == 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 = FungieMachineRecipes.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 = FungieMachineRecipes.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;
    }
    }
    }
    @Override
    public void readFromNBT(NBTTagCompound compound)
    {
    super.readFromNBT(compound);
    }
    @Override
    public void writeToNBT(NBTTagCompound compound)
    {
    super.writeToNBT(compound);
    }
    public Packet getDescriptionPacket()
    {
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    this.writeToNBT(nbttagcompound);
    return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbttagcompound);
    }
    public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
    {
    this.readFromNBT(pkt.func_148857_g());
    }
    }

    Merci de me repondre au plus vite car mon serveur moddé ouvre ce soir !

    1 réponse Dernière réponse Répondre Citer 0
    • robin4002
      robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par 18 févr. 2019, 18:27

      Salut,

      J’ai l’impression que tu essaies d’avancer trop vite et donc tu ne fais que de copier/coller du code que tu ne comprends pas …
      Il va falloir que tu prenne ton temps et que tu t’assures d’avoir compris avant de passer à la suite.

      Déjà je vois plusieurs problèmes, le constructeur de ton container est vide et ce qui devrait être dedans se trouve actuellement dans une fonction public void ContainerMachineTuto(TileEntityFungie tile, InventoryPlayer inventory).

      Ensuite ton GuiCupboard implémente l’interface IGuiHandler alors qu’elle devrait hériter de la classe GuiScreen. Une grosse partie de son code actuelle est inutile et il devrait avoir complètement autre chose à la place.

      ZunF1x 2 réponses Dernière réponse 18 févr. 2019, 18:34 Répondre Citer 0
      • ZunF1x
        ZunF1x @robin4002 dernière édition par 18 févr. 2019, 18:34

        @robin4002 faut que j’ajoute quoi dans les container ??

        1 réponse Dernière réponse Répondre Citer 0
        • ZunF1x
          ZunF1x @robin4002 dernière édition par 18 févr. 2019, 19:08

          @robin4002 faut que je regle quoi sur les classes ?

          1 réponse Dernière réponse Répondre Citer 0
          • robin4002
            robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par 18 févr. 2019, 19:10

            Retournes lire les tutoriels que tu as suivis et tu trouvera ce qu’il te manque dans ton gui.

            Pour le container je t’ai déjà dit, ce que devrait être dans le constructeur se trouve actuellement dans ta fonction void ContainerMachineTuto (et cette fonction ne devrait pas exiter)

            ZunF1x 2 réponses Dernière réponse 18 févr. 2019, 20:02 Répondre Citer 0
            • ZunF1x
              ZunF1x @robin4002 dernière édition par 18 févr. 2019, 20:02

              @robin4002 est-ce que tu a le droit de me donner les classes sans erreurs du guihandler du bloc et tout les autres ou c’est mort ?

              1 réponse Dernière réponse Répondre Citer 0
              • ZunF1x
                ZunF1x @robin4002 dernière édition par 18 févr. 2019, 20:08

                @robin4002 bon ok je doit me debrouiller tout seul alors 😞

                1 réponse Dernière réponse Répondre Citer 0
                • robin4002
                  robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par 18 févr. 2019, 20:36

                  Alors c’est pas vraiment une question d’avoir le droit, c’est plus une question d’avoir le temps / l’envie.

                  Et j’ai d’autre chose à faire que déboguer du code d’une version datant d’un autre temps.

                  Je préfère allouer mon temps dans la rédaction de tutoriel pour la 1.13.2 sachant que forge vient d’arriver pour cette version.

                  ZunF1x 2 réponses Dernière réponse 18 févr. 2019, 20:37 Répondre Citer 0
                  • ZunF1x
                    ZunF1x @robin4002 dernière édition par robin4002 18 févr. 2019, 22:10 18 févr. 2019, 20:37

                    @robin4002 ouai je vais ressayer de refaire toute les classes et ci ca marche pas tempi j’abandonne je supprime fungieMachine et j’énérverait plus personne avec mes gui

                    puis si ta pas envie c’est pas grave

                    1 réponse Dernière réponse Répondre Citer 0
                    • ZunF1x
                      ZunF1x @robin4002 dernière édition par 18 févr. 2019, 21:44

                      @robin4002 c’est bon le container pour un coffre s’ouvre mais maintenant je vais essayer de mieux reflechir sur les codes et faire fonctionner ma machine !

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

                      MINECRAFT FORGE FRANCE © 2018

                      Powered by NodeBB