Ajouter un gui et un container à un bloc
-
@robin4002 tu peut regler mon souci ou pas des que je marque FunFight.instance ca marche pas (FunFight est ma classe principale)
-
Car tu n’as pas créé de variable instance dans ta classe principale.
Va voir le tutoriel sur la base du mod pour savoir comment faire : https://www.minecraftforgefrance.fr/topic/526/créer-la-base-de-votre-mod
-
@robin4002 J’ai ajouter
@Instance("FunFight") public static FunFight instance;mais la gui s’ouvre toujours pas

-
Ah oui normal, il te manque les fonctions gérant le tile entity dans la classe de ton bloc.
https://www.minecraftforgefrance.fr/topic/995/ajouter-une-entité-à-votre-bloc-tile-entity -
@robin4002 sinon est-ce que je pourrai t’envoyer un lien mediafire de mon workspace de mod car je suis pas fort niveau codage je suis perdu sur les codes et tout est-ce que tu peut ???
-
Je n’ai plus aucune workspace 1.7.10 sur mon ordinateur, donc ça va être compliqué.
-
@robin4002 ouai mais c’est deja compilé ya plus qu’a lancer avec eclipse et ca vat marcher normalement !
-
Alors non, pour déboguer quelque chose il faut les sources, donc ce n’est pas déjà compilé.
-
@robin4002 alors tu veux bien j’ai que 12 ans alors pour coder c’est pas tres bien !
@robin4002 meme si ya tout dans dossier du mod ? -
@robin4002 tien essaye si ca marche pas c’est pas grave je me debrouillerai:
-
Non mais de toute façon la 1.7.10 ne m’intéresse pas, cette version est obsolète, je ne dev plus sur cette version.
Ça ne sert à rien d’insister.Suis le tutoriel sur les tile entity, il te manque que 2 fonctions dans la classe du bloc et ça devrait fonctionner.
-
Quand j’ouvre ma gui en cliquant sur le bloc mon jeu crash j’aurai besoin d’aide car je ne sais pas pourquoi:
la classe du bloc en question
package fr.askipie.funfight; 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 { public GUITutoriel(Material p_i45394_1_) { super(p_i45394_1_); } @Override public boolean hasTileEntity(int metadata) { return true; } @Override public TileEntity createTileEntity(World world, int metadata) { if(metadata == 0) { return new TileEntityFungie(); } else if(metadata == 1) { return new TileEntityFungie(); } else if(metadata == 2) { return new TileEntityFungie(); } return null; } 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; } } 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 void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityFungie) { if(stack.hasDisplayName()) { ((TileEntityFungie)tile).setCustomName(stack.getDisplayName()); } } } }la classe du tileEntity :
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.tileentity.TileEntity; import net.minecraftforge.common.util.Constants; public class TileEntityFungie extends TileEntity implements IInventory { private ItemStack[] contents = new ItemStack[27]; private String customName; @Override public boolean hasCustomInventoryName() { return false; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); // exécute ce qui se trouve dans la fonction readFromNBT de la classe mère (lecture de la position du tile entity) if(compound.hasKey("fungieMachine", Constants.NBT.TAG_STRING)) // si un tag custom name de type string existe { this.customName = compound.getString("fungieMachine"); // on le lit } NBTTagList nbttaglist = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND); // on obtient la liste de tags nommée Items this.contents = new ItemStack[this.getSizeInventory()]; // on réinitialise le tableau for(int i = 0; i < nbttaglist.tagCount(); ++i) // i varie de 0 à la taille la liste { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); // on lit le tag nbt int j = nbttagcompound1.getByte("Slot") & 255; // on lit à quel slot se trouve l'item stack if(j >= 0 && j < this.contents.length) { this.contents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); // on lit l'item stack qui se trouve dans le tag } } } @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); // exécute se qui se trouve dans la fonction writeToNBT de la classe mère (écriture de la position du tile entity) if(this.hasCustomInventoryName()) // s'il y a un nom custom { compound.setString("fungieMachine", this.customName); // on le met dans le tag nbt } NBTTagList nbttaglist = new NBTTagList(); // on créé une nouvelle liste de tags for(int i = 0; i < this.contents.length; ++i) // i varie de 0 à la taille de notre tableau { if(this.contents[ i] != null) // si l'item stack à l'emplacement i du tableau n'est pas null { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); // on créé un tag nbt nbttagcompound1.setByte("Slot", (byte)i); // on enregistre son emplacement dans le tableau this.contents[ i].writeToNBT(nbttagcompound1); // on écrit l'item dans le tag nbttaglist.appendTag(nbttagcompound1); // on ajoute le tab à la liste } } compound.setTag("Items", nbttaglist); // on enregistre la liste dans le tag nbt } @Override public int getSizeInventory() { return this.contents.length; } @Override public ItemStack getStackInSlot(int slotIndex) { return this.contents[slotIndex]; } @Override public ItemStack decrStackSize(int slotIndex, int amount) { if(this.contents[slotIndex] != null) // si le contenu dans l'emplacement n'est pas null { ItemStack itemstack; if(this.contents[slotIndex].stackSize <= amount) // si la quantité est inférieur où égale à ce qu'on souhaite retirer { itemstack = this.contents[slotIndex]; // la variable itemstack prends la valeur du contenu this.contents[slotIndex] = null; // on retire ce qui est dans la variable contents this.markDirty(); // met à jour le tile entity return itemstack; // renvoie itemstack } else // sinon { itemstack = this.contents[slotIndex].splitStack(amount); // la fonction splitStack(quantité) retire dans this.contents[slotIndex] le contenu et le met dans itemstack if(this.contents[slotIndex].stackSize == 0) // au cas où la quantité passe à 0 (ce qui ne devrait pas arriver en temps normal) { this.contents[slotIndex] = null; // on met sur null, ça évite de se retrouver avec des itemstack bugué qui contiennent 0 } this.markDirty(); // met à jour le tile entity return itemstack; // renvoie itemstack } } else // sinon si le contenu dans cette emplacement est null { return null; // renvoie null, puisqu'il n'y a rien dans cette emplacement } } @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; // met l'item stack dans le tableau if(stack != null && stack.stackSize > this.getInventoryStackLimit()) // si la taille de l'item stack dépasse la limite maximum de l'inventaire { stack.stackSize = this.getInventoryStackLimit(); // on le remet sur la limite } this.markDirty(); // met à jour le tile entity } @Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.customName : "tile.cupboard"; } public void setCustomName(String customName) { this.customName = customName; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; } @Override public boolean isItemValidForSlot(int slotIndex, ItemStack stack) { return true; } @Instance("funfight") // attention il doit respecter les majuscules/minuscules public static FunFight instance; { NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandlerFungie()); } }
Sa me soule ca marche jamais avec moi je suis vraiment nul serieux!!!
-
Il faudrait un copier/coller du rapport de crash.
-
@robin4002 ca crash plus mais la gui ne souvre toujours pas:
la classe du blocs:
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 { public GUITutoriel(Material p_i45394_1_) { super(p_i45394_1_); } @Override public TileEntity createTileEntity(World world, int metadata) { if(metadata == 0) { return new TileEntityFungie(); } else if(metadata == 1) { return new TileEntityFungie(); } else if(metadata == 2) { return new TileEntityFungie(); } return null; } 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; } } 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 void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityFungie) { if(stack.hasDisplayName()) { ((TileEntityFungie)tile).setCustomName(stack.getDisplayName()); } } } } -
Remplaces tout ça :
@Override public TileEntity createTileEntity(World world, int metadata) { if(metadata == 0) { return new TileEntityFungie(); } else if(metadata == 1) { return new TileEntityFungie(); } else if(metadata == 2) { return new TileEntityFungie(); } return null; }par juste ça :
@Override public TileEntity createTileEntity(World world, int metadata) { return new TileEntityFungie(); }Vu que tu n’as pas de metadata toutes tes conditions sont inutiles.
Enfin ajoutes la fonction pour indiquer que le bloc a un tile entity :
@Override public boolean hasTileEntity(int metadata) { return true; } -
@robin4002 pi le crash report:
---- Minecraft Crash Report ---- // This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~] Time: 17/02/19 21:27 Description: Ticking memory connection java.lang.ClassCastException: fr.askipie.funfight.GuiCupboard cannot be cast to net.minecraft.inventory.Container at cpw.mods.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:243) at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:75) at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) at fr.askipie.funfight.GUITutoriel.onBlockActivated(GUITutoriel.java:46) at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409) at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at cpw.mods.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:243) at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:75) at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) at fr.askipie.funfight.GUITutoriel.onBlockActivated(GUITutoriel.java:46) at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409) at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74) at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@15b615c Stacktrace: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 8.1 (amd64) version 6.3 Java Version: 1.8.0_202, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 840750248 bytes (801 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1558 4 mods loaded, 4 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored UCHIJAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) UCHIJAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1558-1.7.10.jar) UCHIJAAAA Forge{10.13.4.1558} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1558-1.7.10.jar) UCHIJAAAA funfight{1.0.0} [FunFight] (bin) GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread. Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Player Count: 1 / 8; [EntityPlayerMP['Player468'/149, l='New World', x=-420,72, y=1,00, z=-1869,36]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge' -
Ah c’est causé par quelque chose que je n’avais pas vu avant. Dans ta classe
GuiHandlerFungietu as inversé le contenu des fonctions rapport à ce qu’il faudrait.getServerGuiElementdoit retourner un container et non un gui, et l’inverse pourgetClientGuiElement -
@robin4002 apres tout ce temps… ENFIN CA MARCHE !!! et c’est ou qu’on met la texture du coffre pour notre gui ?
-
Cela dépend de ce que tu as mis dans la classe GuiCupboard.
Il y a une variable de type ResourceLocation, le chemin indiqué dedans est l’endroit où il cherche la texture. -
@robin4002 est-ce que tu aurai une texture d’un coffre minecraft a 3 lignes stp ??
et puis comme je fait si je veux que mon coffre ai 6 lignes (en tout 54 slot) ???