Ajouter un gui et un container à un bloc
-
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) ???
-
pour avoir plus de slots c’est pas compliqué il suffit d’ajouter des slots au container puis d’augmenter la taille de l’inventaire dans le TileEntity
ensuite tu devras également faire une texture avec plus de ligne|colonne selon ce que tu veux faire, après tu peux aussi afficher la texture avec un algorithme qui vas positionner “des bouts de textures” a l’écran pour n’utiliser que une seul texture ou celle de minecraft déjà existante
-
@SpyMan ok mais quels lignes ?
-
La texture de coffre à 3 lignes tu peux la trouver dans les ressource de Minecraft.
Et pour avoir plus de slot, il faut adapter le code du container et la taille du tableau d’itemstack du tileEntity.Par contre il serait vraiment bien que tu te calmes sur les messages.
Je viens de faire du ménage dans la discussion, tu as posté pleins de messages en double ou inutile. Si tu n’as pas de réponse au bout de 15 minutes ça ne sert à rien de reposter un autre message, ça veut dire que je ne suis pas dispo pour répondre. (je fais d’autres choses aussi de mes journées / soirées).
EDIT : je viens même de voir que tu as posté d’autres messages dans une demande d’aide de quelqu’un d’autre. Arrêtes tout de suite ce genre de comportement, sinon on ne va pas bien s’entendre. -
@robin4002 mais la j’aurai besoin d’aide sur un autre truc
-
Si c’est en rapport avec les gui et container, tu peux poster ta question ici.
Sinon ouvres une demande d’aide dans la section appropriée : https://www.minecraftforgefrance.fr/category/21/support-pour-les-moddeurs
-
@robin4002 deja fait tien si tu peut m’aider
-
bonjour, j’aimerai faire un GUI qui reste affiché à l’écran (pour des stat de joueur et autres variable) est-ce que qqn sais comment faire?
il y aurait donc aucun bloc pour l’afficher
-
Dans ce cas ce n’est pas un gui qu’il te faut, ce que tu dois faire c’est une modification du HUD (avec l’event RenderGameOverlay).
Fais une recherche de ce terme sur le forum, tu devrais trouver pas mal de demande d’aide résolu.
Si jamais tu as besoin d’aide, créés une demande dans la section support pour les moddeurs plutôt que poster ici (car la modif du HUD n’a rien à voir avec la création d’un gui + container pour un bloc). -
@robin4002 merci je savais pas qu’il fallais faire autres chose qu’un GUI donc j’ai posté où sa me semblais le plus logique
-
Ce message a été supprimé ! -
Ce message a été supprimé ! -
@robin4002 Salut j’ai un énorme problème et je crois que ça vient des métadata… A chaque fois que je place mon block mon jeu se ferme… Mais si je le redémarre et que je fait in rightClick sur mon block sauvegardé, mon Gui apparait et je peux intéragir avec. Help please !