Crash avec un ItemSeeds



  • Salut, je viens de créer une plante cultivable, mais le problème est que la graine de cette plante me fait crasher (lorsque je clique sur n'importe quelle block).

    Voici les codes : ModItems :

    public class ModItems {
    
    public static Item test_seed;
    public static Item test_item;
    
    public static void initItems() {
    
    test_seed = new ItemSeeds(ModBlocks.test_crop, Blocks.FARMLAND).setUnlocalizedName("test_seed").setRegistryName("test_seed");
    test_item = new Item().setRegistryName("test_item").setUnlocalizedName("test_item");
    
    }
    
    public static void registerItems() {
    
    initItems();
    
    registerItem(test_seed);
    registerItem(test_item);
    }
    
    @SideOnly(Side.CLIENT)
    public static void registerRenders() {
    registerRender(item_seed, 0);
    registerRender(test_item, 0);
    }
    
    private static void registerItem(Item item) {
    GameRegistry.register(item);
    }
    
    private static void registerRender(Item item, int meta) {
    ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(new ResourceLocation(References.MODID, item.getUnlocalizedName().substring(5)), "inventory"));
    }
    }
    
    

    ModBlocks:

    public class ModBlocks {
    
    public static Block test_crop;
    
    public static void init() {
    
    test_crop = new TestCrop().setUnlocalizedName("test_crop").setRegistryName("test_crop");
    }
    
    public static void registers() {
    
    init();
    
    register(test_crop);
    }
    
    @SideOnly(Side.CLIENT)
    public static void registerRenders() {
    
    registerRender(test_crop, 0);
    }
    
    public static void registerItemBlocks() {
    
    registerItemBlock(test_crop);
    }
    
    public static void register(Block block) {
    GameRegistry.register(block);
    }
    
    public static void registerRender(Block block, int meta) {
    ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), meta, new ModelResourceLocation(new ResourceLocation(References.MODID, block.getUnlocalizedName().substring(5)), "inventory"));
    }
    
    public static void registerItemBlock(Block block) {
    ItemBlock ib = new ItemBlock(block);
    ib.setRegistryName(block.getRegistryName());
    GameRegistry.register(ib);
    }
    }
    
    

    Et la class TestCrop :

    public class TestCrop extends BlockCrops {
    
       protected Item getSeed() {
    
           return ModItems.test_seed;
       }
    
       protected Item getCrop() {
    
           return ModItems.test_item;
       }
    }
    
    

    J'espère que vous pourrez m'aider.

    PS : Excusez moi pour les fautes d'orthographe (s'il y en a)



  • cc passe donc aussu le crash log car la j'ai la flemme d'analysé ton code
    en 1.11 c'est pas comme ca que l'on register des items en plus je crois
    mais passe ton crash



  • Le voilà (j'avais oublié son existence) :

    –-- Minecraft Crash Report ----
    
    // Daisy, daisy...
    Time: 4/19/18 1:02 PM
    Description: Unexpected error
    java.lang.NullPointerException: Unexpected error
     at net.minecraft.item.ItemSeeds.getPlant(ItemSeeds.java:53)
     at net.minecraft.block.Block.canSustainPlant(Block.java:1832)
     at net.minecraft.item.ItemSeeds.onItemUse(ItemSeeds.java:32)
     at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:180)
     at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClickBlock(PlayerControllerMP.java:489)
     at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1606)
     at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2276)
     at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2053)
     at net.minecraft.client.Minecraft.runTick(Minecraft.java:1841)
     at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1119)
     at net.minecraft.client.Minecraft.run(Minecraft.java:407)
     at net.minecraft.client.main.Main.main(Main.java:118)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
     at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
     at GradleStart.main(GradleStart.java:26)
    
    A detailed walkthrough of the error, its code path and all known details is as follows:
    ---------------------------------------------------------------------------------------
    -- Head --
    Thread: Client thread
    Stacktrace:
     at net.minecraft.item.ItemSeeds.getPlant(ItemSeeds.java:53)
     at net.minecraft.block.Block.canSustainPlant(Block.java:1832)
     at net.minecraft.item.ItemSeeds.onItemUse(ItemSeeds.java:32)
     at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:180)
     at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClickBlock(PlayerControllerMP.java:489)
     at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1606)
     at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2276)
     at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2053)
    -- Affected level --
    Details:
     Level name: MpServer
     All players: 1 total; [EntityPlayerSP['Player651'/178, l='MpServer', x=79.92, y=4.00, z=-641.79]]
     Chunk stats: MultiplayerChunkCache: 289, 289
     Level seed: 0
     Level generator: ID 01 - flat, ver 0\. Features enabled: false
     Level generator options:
     Level spawn location: World: (66,4,-657), Chunk: (at 2,0,15 in 4,-42; contains blocks 64,0,-672 to 79,255,-657), Region: (0,-2; contains chunks 0,-64 to 31,-33, blocks 0,0,-1024 to 511,255,-513)
     Level time: 178795 game time, 2805 day time
     Level dimension: 0
     Level storage version: 0x00000 - Unknown?
     Level weather: Rain time: 0 (now: true), thunder time: 0 (now: false)
     Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
     Forced entities: 64 total; [EntityHorse['Horse'/129, l='MpServer', x=163.54, y=4.00, z=-679.82], EntitySlime['Slime'/130, l='MpServer', x=130.38, y=4.12, z=-671.55], EntitySlime['Slime'/131, l='MpServer', x=160.51, y=5.02, z=-643.22], EntitySpider['Spider'/134, l='MpServer', x=155.00, y=4.00, z=-562.07], EntityZombie['Zombie'/1676, l='MpServer', x=136.50, y=4.00, z=-624.50], EntityCreeper['Creeper'/1681, l='MpServer', x=22.50, y=4.00, z=-686.50], EntityWitch['Witch'/1688, l='MpServer', x=20.21, y=4.00, z=-645.63], EntityWitch['Witch'/1689, l='MpServer', x=10.53, y=4.00, z=-650.34], EntitySlime['Slime'/35, l='MpServer', x=3.46, y=4.00, z=-675.84], EntityCow['Cow'/40, l='MpServer', x=10.39, y=4.00, z=-694.21], EntitySlime['Slime'/41, l='MpServer', x=6.69, y=4.00, z=-685.17], EntityCow['Cow'/54, l='MpServer', x=18.70, y=4.00, z=-707.38], EntityItem['item.item.rottenFlesh'/55, l='MpServer', x=24.66, y=4.00, z=-694.43], EntityCreeper['Creeper'/56, l='MpServer', x=28.31, y=4.00, z=-665.86], EntitySlime['Slime'/60, l='MpServer', x=43.85, y=4.28, z=-634.31], EntitySlime['Slime'/61, l='MpServer', x=47.67, y=4.00, z=-619.20], EntityCreeper['Creeper'/62, l='MpServer', x=41.19, y=4.00, z=-584.71], EntitySheep['Sheep'/64, l='MpServer', x=54.38, y=4.00, z=-715.27], EntityPig['Pig'/65, l='MpServer', x=54.46, y=4.00, z=-615.44], EntityPig['Pig'/67, l='MpServer', x=66.56, y=4.00, z=-710.55], EntitySlime['Slime'/68, l='MpServer', x=53.76, y=4.00, z=-686.24], EntitySlime['Slime'/69, l='MpServer', x=87.80, y=5.18, z=-642.19], EntityItemFrame['entity.ItemFrame.name'/70, l='MpServer', x=79.50, y=5.50, z=-637.03], EntityItemFrame['entity.ItemFrame.name'/71, l='MpServer', x=78.50, y=5.50, z=-637.03], EntityItemFrame['entity.ItemFrame.name'/72, l='MpServer', x=77.50, y=5.50, z=-637.03], EntityWitch['Witch'/1611, l='MpServer', x=92.50, y=4.00, z=-693.50], EntitySkeleton['Skeleton'/1620, l='MpServer', x=115.21, y=4.00, z=-637.55], EntitySlime['Slime'/86, l='MpServer', x=85.62, y=4.42, z=-669.86], EntityItemFrame['entity.ItemFrame.name'/87, l='MpServer', x=85.50, y=5.50, z=-637.03], EntityItemFrame['entity.ItemFrame.name'/88, l='MpServer', x=84.50, y=5.50, z=-637.03], EntityItemFrame['entity.ItemFrame.name'/89, l='MpServer', x=83.50, y=5.50, z=-637.03], EntityCreeper['Creeper'/1625, l='MpServer', x=113.50, y=4.00, z=-646.50], EntityItemFrame['entity.ItemFrame.name'/90, l='MpServer', x=82.50, y=5.50, z=-637.03], EntityItemFrame['entity.ItemFrame.name'/91, l='MpServer', x=81.50, y=5.50, z=-637.03], EntityItemFrame['entity.ItemFrame.name'/92, l='MpServer', x=80.50, y=5.50, z=-637.03], EntityItem['item.item.rottenFlesh'/93, l='MpServer', x=94.71, y=4.00, z=-602.64], EntitySpider['Spider'/1633, l='MpServer', x=125.50, y=4.00, z=-620.50], EntityZombie['Zombie'/1636, l='MpServer', x=44.74, y=4.00, z=-560.77], EntityCreeper['Creeper'/101, l='MpServer', x=107.50, y=4.00, z=-718.50], EntityItem['item.item.arrow'/102, l='MpServer', x=102.33, y=4.00, z=-669.94], EntityItem['item.item.bone'/103, l='MpServer', x=103.03, y=4.00, z=-670.48], EntityItem['item.item.arrow'/104, l='MpServer', x=111.05, y=4.00, z=-667.08], EntityItem['item.item.bone'/105, l='MpServer', x=110.59, y=4.00, z=-667.22], EntityItem['item.item.arrow'/106, l='MpServer', x=111.98, y=4.00, z=-630.73], EntityItem['item.item.arrow'/107, l='MpServer', x=109.12, y=4.00, z=-617.93], EntityItem['item.item.bone'/108, l='MpServer', x=108.78, y=4.00, z=-618.37], EntityPlayerSP['Player651'/178, l='MpServer', x=79.92, y=4.00, z=-641.79], EntityHorse['Horse'/113, l='MpServer', x=127.91, y=4.00, z=-681.10], EntitySpider['Spider'/114, l='MpServer', x=115.98, y=4.00, z=-640.99], EntitySpider['Spider'/1650, l='MpServer', x=116.50, y=4.00, z=-689.50], EntitySpider['Spider'/115, l='MpServer', x=127.01, y=4.00, z=-584.99], EntityItem['item.item.rottenFlesh'/116, l='MpServer', x=140.80, y=4.00, z=-686.30], EntitySpider['Spider'/1652, l='MpServer', x=112.99, y=4.00, z=-705.02], EntitySheep['Sheep'/117, l='MpServer', x=140.74, y=4.00, z=-667.59], EntityItem['item.item.arrow'/118, l='MpServer', x=136.42, y=4.00, z=-642.29], EntityCreeper['Creeper'/1654, l='MpServer', x=111.55, y=4.00, z=-697.20], EntityItem['item.item.bone'/119, l='MpServer', x=136.65, y=4.00, z=-641.84], EntityItem['item.item.arrow'/120, l='MpServer', x=135.67, y=4.00, z=-653.94], EntityCreeper['Creeper'/1656, l='MpServer', x=114.50, y=4.00, z=-692.50], EntityItem['item.item.bone'/121, l='MpServer', x=134.86, y=4.00, z=-655.46], EntitySlime['Slime'/122, l='MpServer', x=138.93, y=5.00, z=-621.22], EntityChicken['Chicken'/123, l='MpServer', x=143.88, y=4.00, z=-591.69], EntitySlime['Slime'/124, l='MpServer', x=127.70, y=4.00, z=-600.82], EntityCreeper['Creeper'/127, l='MpServer', x=158.24, y=4.00, z=-720.17]]
     Retry entities: 0 total; []
     Server brand: fml,forge
     Server type: Integrated singleplayer server
    Stacktrace:
     at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:456)
     at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2774)
     at net.minecraft.client.Minecraft.run(Minecraft.java:436)
     at net.minecraft.client.main.Main.main(Main.java:118)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
     at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
     at GradleStart.main(GradleStart.java:26)
    – System Details --
    Details:
     Minecraft Version: 1.11.2
     Operating System: Windows 10 (amd64) version 10.0
     Java Version: 1.8.0_161, Oracle Corporation
     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
     Memory: 575546048 bytes (548 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
     JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
     IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
     FML: MCP 9.38 Powered by Forge 13.20.1.2454 7 mods loaded, 7 mods active
     States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
     UCHIJAAAA minecraft{1.11.2} [Minecraft] (minecraft.jar)
     UCHIJAAAA mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)
     UCHIJAAAA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.11.2-13.20.1.2454.jar)
     UCHIJAAAA forge{13.20.1.2454} [Minecraft Forge] (forgeSrc-1.11.2-13.20.1.2454.jar)
     UCHIJAAAA thunderia{1.0} [Thunderia Mod] (bin)
     UCHIJAAAA jei{4.5.1.296} [Just Enough Items] (jei_1.11.2-4.5.1.296.jar)
     UCHIJAAAA waila{1.7.1} [waila] (WAILA-1.11.2.jar)
     Loaded coremods (and transformers):
     GL info: ' Vendor: 'ATI Technologies Inc.' Version: '4.5.13418 Compatibility Profile Context 15.301.2301.1002' Renderer: 'AMD Radeon(TM) R5 Graphics'
     Launched Version: 1.11.2
     LWJGL: 2.9.4
     OpenGL: AMD Radeon(TM) R5 Graphics GL version 4.5.13418 Compatibility Profile Context 15.301.2301.1002, ATI Technologies Inc.
     GL Caps: Using GL 1.3 multitexturing.
    Using GL 1.3 texture combiners.
    Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
    Shaders are available because OpenGL 2.1 is supported.
    VBOs are available because OpenGL 1.5 is supported.
     Using VBOs: Yes
     Is Modded: Definitely; Client brand changed to 'fml,forge'
     Type: Client (map_client.txt)
     Resource Packs: New Texture
     Current Language: English (US)
     Profiler Position: N/A (disabled)
     CPU: 4x AMD A8-7410 APU with AMD Radeon R5 Graphics
    

    Ps : Je crois bien que c'est comme ca qu'on register les items en 1.11(enfin je pense), sur un autre de mes mods, mes items fonctionnent bien.


  • Moddeurs confirmés Rédacteurs Administrateurs

    Salut,
    Déclares tes items et blocs en constantes, cela t'évitera ce genre de npe.
    (Le soucis vient du faire que ModBlocks.test_crop est null au moment où ta fonction initItems est appelé).

        public static final Item TEST_SEED = new ItemSeeds(ModBlocks.test_crop, Blocks.FARMLAND).setUnlocalizedName("test_seed").setRegistryName("test_seed");;
        public static final Item TEST_ITEM = new Item().setRegistryName("test_item").setUnlocalizedName("test_item");
    

    (idem pour tes blocs, et du-coup tu peux supprimer tes fonctions initItems et initBlocks)



  • Merci, maintenant il n'y a plus aucun bug


Log in to reply