Ajouter un gui et un container à un bloc
-
Ton inventaire à 18 slots :
private ItemStack[] contents = new ItemStack[18];
Or dans ton container tu mets 9x3 slots (27)for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(tile, j + i * 9, 8 + j * 18, 18 + i * 18)); } }Donc forcement ça fait un ArrayIndexOutOfBoundsException
-
MERCI BEAUCOUP

ça marche enfin merci!
-
Mon block ne s’ouvre pas

Mon onBlockActivated :
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(CompleatCraft.instance, 0, world, x, y, z); return true; } -
Salut,
Il faudrait le code de CompleatCraft et du gui handler. -
Oui désoler je n’avais plus de co

CompleatCraft :
package Package1.common; import Package1.common.FourTotal.BlockFour; import Package1.common.FourTotal.GuiBlockFour; import Package1.common.FourTotal.TileEntityFour; import Package1.common.Proxy.CommonProxy; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; @Mod(modid = "compleatcraft", name = "Compleat Craft", version = "1.0.0" ) public class CompleatCraft { @Instance("compleatcraft") public static CompleatCraft instance; @SidedProxy(clientSide = "Package1.common.Proxy.ClientProxy", serverSide = "Package1.common.Proxy.CommonProxy") public static CommonProxy proxy; public static final String MODID = "compleatcraft"; public static Block BlockFourConstuct; @EventHandler public void preInit(FMLPreInitializationEvent event) { ItemsMod.init(); ItemsMod.register(); BlocksMod.init(); BlocksMod.register(); proxy.registerTileEntities(); BlockFourConstuct = new BlocksMod(Material.rock).setBlockName("BlockFour"); } @EventHandler public void init(FMLInitializationEvent event) { proxy.registerRender(); GameRegistry.registerTileEntity(TileEntityFour.class, "compleatcraft:TileEntityFour"); GameRegistry.registerBlock(BlockFourConstuct, "Block_Four"); GameRegistry.registerTileEntity(TileEntityFour.class, MODID + ":FourTileEntity"); NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); } @EventHandler public void postInit(FMLPostInitializationEvent event) { } }Le guihandler :
package Package1.common; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import Package1.common.FourTotal.ContainerBlockFour; import Package1.common.FourTotal.GuiBlockFour; import Package1.common.FourTotal.TileEntityFour; import cpw.mods.fml.common.network.IGuiHandler; public class GuiHandler 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 TileEntityFour) { return new ContainerBlockFour((TileEntityFour)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 TileEntityFour) { return new GuiBlockFour((TileEntityFour)tile, player.inventory); } return null; } } -
Je ne vois pas d’erreur ici.
Dans la classe de ton bloc tu as bien tout le code qu’il faut pour le tile entity ? -
Mon bloc :
package Package1.common.FourTotal; import Package1.common.CompleatCraft; import cpw.mods.fml.common.network.internal.FMLNetworkHandler; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; 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 BlockFour extends BlockContainer { public BlockFour(Material material) { super(Material.rock); this.setResistance(8.0F); this.setHarvestLevel("pickaxe", 2); this.setBlockTextureName(CompleatCraft.MODID + ":BlockFour"); } @Override public TileEntity createNewTileEntity(World world, int metadata) { return new TileEntityFour(); } @Override public boolean hasTileEntity(int metadata) { 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 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(CompleatCraft.instance, 0, world, x, y, z); return true; } } } -
Ajoutes System.out.println(“test”); au dessus de player.openGui(CompleatCraft.instance, 0, world, x, y, z); dans le bloc, puis System.out.println(“test 2”); au dessus de return new GuiBlockFour((TileEntityFour)tile, player.inventory); dans le GuiHandler.
Vas en jeu, fais un clic sur ton bloc et regardes ce que tu as dans la console. -
Il ne se passe rien dans la console.
-
Ajoutes @Override au dessus de la fonction onBlockActivated ?
-
Toujours rien ^^
-
Pas d’erreur lorsque tu ajoutes le override ?
-
Non

-
Je ne vois pas comment c’est possible o_O
-
Bizarrre, montres la classe de ton block avec le system.out et le @Override, voir si ils sont bien placés.
-
-
Et le “test” apparaît vraiment aucune fois dans la console quand tu cliques droit sur ton bloc ?
-
Non, il n’y a rien
-
Dans ta classe principale, à la déclaration de ton block, tu fais un new BlocksMod, alors que depuis le début tu nous montres ta classe BlockFour, donc erreur très bête.
-
Ok merci c’est bon mais après l’avoir ouvert mon jeu crash et maintenant, je ne peux plus lancer mon monde.
Crash report :
[16:35:37] [Server thread/INFO]: Starting integrated minecraft server version 1.7.10 [16:35:37] [Server thread/INFO]: Generating keypair [16:35:37] [Server thread/INFO] [FML]: Injecting existing block and item data into this server instance [16:35:37] [Server thread/INFO] [FML]: Applying holder lookups [16:35:37] [Server thread/INFO] [FML]: Holder lookups applied [16:35:37] [Server thread/INFO] [FML]: Loading dimension 0 (New World) (net.minecraft.server.integrated.IntegratedServer@6034c282) [16:35:37] [Server thread/INFO] [FML]: Loading dimension 1 (New World) (net.minecraft.server.integrated.IntegratedServer@6034c282) [16:35:37] [Server thread/INFO] [FML]: Loading dimension -1 (New World) (net.minecraft.server.integrated.IntegratedServer@6034c282) [16:35:37] [Server thread/INFO]: Preparing start region for level 0 [16:35:38] [Server thread/INFO]: Changing view distance to 12, from 10 [16:35:38] [Server thread/ERROR]: Encountered an unexpected exception net.minecraft.util.ReportedException: Ticking block entity at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:709) ~[MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) ~[MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] Caused by: java.lang.NullPointerException at Package1.common.FourTotal.BlockFourRecipes.isSameKey(BlockFourRecipes.java:73) ~[BlockFourRecipes.class:?] at Package1.common.FourTotal.BlockFourRecipes.getSmeltingResult(BlockFourRecipes.java:63) ~[BlockFourRecipes.class:?] at Package1.common.FourTotal.TileEntityFour.smeltItem(TileEntityFour.java:213) ~[TileEntityFour.class:?] at Package1.common.FourTotal.TileEntityFour.updateEntity(TileEntityFour.java:200) ~[TileEntityFour.class:?] at net.minecraft.world.World.updateEntities(World.java:2160) ~[World.class:?] at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:515) ~[WorldServer.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703) ~[MinecraftServer.class:?] … 4 more [16:35:38] [Server thread/ERROR]: This crash report has been saved to: D:\BUREAU\FREEZER-regroupement de dossiers\Codage\Mods\Forge 1.7.10\eclipse\.\crash-reports\crash-2017-07-17_16.35.38-server.txt [16:35:38] [Server thread/INFO]: Stopping server [16:35:38] [Server thread/INFO]: Saving players [16:35:38] [Server thread/INFO]: Saving worlds [16:35:38] [Server thread/INFO]: Saving chunks for level 'New World'/Overworld [16:35:38] [Server thread/INFO]: Saving chunks for level 'New World'/Nether [16:35:38] [Server thread/INFO]: Saving chunks for level 'New World'/The End [16:35:38] [Client thread/INFO] [STDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: –-- Minecraft Crash Report ---- // On the bright side, I bought you a teddy bear! Time: 17/07/17 16:35 Description: Ticking block entity java.lang.NullPointerException: Ticking block entity at Package1.common.FourTotal.BlockFourRecipes.isSameKey(BlockFourRecipes.java:73) at Package1.common.FourTotal.BlockFourRecipes.getSmeltingResult(BlockFourRecipes.java:63) at Package1.common.FourTotal.TileEntityFour.smeltItem(TileEntityFour.java:213) at Package1.common.FourTotal.TileEntityFour.updateEntity(TileEntityFour.java:200) at net.minecraft.world.World.updateEntities(World.java:2160) at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:515) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703) 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 Package1.common.FourTotal.BlockFourRecipes.isSameKey(BlockFourRecipes.java:73) at Package1.common.FourTotal.BlockFourRecipes.getSmeltingResult(BlockFourRecipes.java:63) at Package1.common.FourTotal.TileEntityFour.smeltItem(TileEntityFour.java:213) at Package1.common.FourTotal.TileEntityFour.updateEntity(TileEntityFour.java:200) -- Block entity being ticked -- Details: Name: compleatcraft:FourTileEntity // Package1.common.FourTotal.TileEntityFour Block type: ID #177 (tile.BlockFour // Package1.common.FourTotal.BlockFour) Block data value: 0 / 0x0 / 0b0000 Block location: World: (-206,67,152), Chunk: (at 2,4,8 in -13,9; contains blocks -208,0,144 to -193,255,159), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511) Actual block type: ID #177 (tile.BlockFour // Package1.common.FourTotal.BlockFour) Actual block data value: 0 / 0x0 / 0b0000 Stacktrace: at net.minecraft.world.World.updateEntities(World.java:2160) at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:515) -- Affected level -- Details: Level name: New World All players: 0 total; [] Chunk stats: ServerChunkCache: 625 Drop: 0 Level seed: -8957039999929459700 Level generator: ID 00 - default, ver 1\. Features enabled: true Level generator options: Level spawn location: World: (-196,64,148), Chunk: (at 12,4,4 in -13,9; contains blocks -208,0,144 to -193,255,159), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511) Level time: 221841 game time, 18584 day time Level dimension: 0 Level storage version: 0x04ABD - Anvil Level weather: Rain time: 21306 (now: true), thunder time: 153946 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true Stacktrace: at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703) 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 10 (amd64) version 10.0 Java Version: 1.8.0_131, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 919065176 bytes (876 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 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: 12, tallocated: 94 FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1614 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.1614-1.7.10.jar) UCHIJAAAA Forge{10.13.4.1614} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar) UCHIJAAAA compleatcraft{1.0.0} [Compleat Craft] (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: 0 / 8; [] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge' [16:35:38] [Client thread/INFO] [STDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:393]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2017-07-17_16.35.38-server.txt [16:35:38] [Client thread/INFO] [FML]: Waiting for the server to terminate/save. [16:35:39] [Server thread/INFO] [FML]: Unloading dimension 0 [16:35:39] [Server thread/INFO] [FML]: Unloading dimension -1 [16:35:39] [Server thread/INFO] [FML]: Unloading dimension 1 [16:35:39] [Server thread/INFO] [FML]: Applying holder lookups [16:35:39] [Server thread/INFO] [FML]: Holder lookups applied [16:35:39] [Server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded. [16:35:39] [Client thread/INFO] [FML]: Server terminated. AL lib: (EE) alc_cleanup: 1 device not closed Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release