Non résolu Problème avec les stairs
-
Bonjour,
Oui encore moi, mais voilà j’ai voulu ajouté une stairs à mon mod sauf que quand je lance mon jeu je reçoit un crash-report alors j’ai essayé de comprendre d’où ça vient et apparemment ça vient de l’enregistrement du block enfin je croit.
Voici les codes :
import com.google.common.collect.Lists; import fr.vesperia.vesperiamod.References; import fr.vesperia.vesperiamod.blocks.BlockAlloyMachine; import fr.vesperia.vesperiamod.blocks.BlockObsidianDoor; import fr.vesperia.vesperiamod.blocks.BlockOresBlock; import fr.vesperia.vesperiamod.blocks.BlockReinforcedObsidian; import fr.vesperia.vesperiamod.blocks.BlockSpectral; import fr.vesperia.vesperiamod.blocks.BlockStairsBase; import fr.vesperia.vesperiamod.blocks.ores.BlockOres; import net.minecraft.block.Block; import net.minecraft.block.BlockPlanks; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.registry.GameRegistry; @Mod.EventBusSubscriber(modid = References.MODID) public class ModBlocks { public static final ModBlocks instance = new ModBlocks(); public static Block copper_ore; public static Block tin_ore; public static Block cobalt_ore; public static Block manganese_ore; public static Block copper_block; public static Block tin_block; public static Block cobalt_block; public static Block manganese_block; public static Block pyrite_block; public static Block silver_block; public static Block ebonite_block; public static Block vespene_block; public static Block alloy_machine; public static Block reinforced_obsidian; public static Block obsidian_door; public static Block spectral_block; public static Block obsidian_stairs; private List<Block> blocks; public void init() { blocks = Lists.newArrayList(); copper_ore = new BlockOres("copper_ore"); tin_ore = new BlockOres("tin_ore"); cobalt_ore = new BlockOres("cobalt_ore"); manganese_ore = new BlockOres("manganese_ore"); copper_block = new BlockOresBlock("copper_block"); tin_block = new BlockOresBlock("tin_block"); cobalt_block = new BlockOresBlock("cobalt_block"); manganese_block = new BlockOresBlock("manganese_block"); pyrite_block = new BlockOresBlock("pyrite_block"); silver_block = new BlockOresBlock("silver_block"); ebonite_block = new BlockOresBlock("ebonite_block"); vespene_block = new BlockOresBlock("vespene_block"); alloy_machine = new BlockAlloyMachine("alloy_machine"); reinforced_obsidian = new BlockReinforcedObsidian("reinforced_obsidian"); obsidian_door = new BlockObsidianDoor(Material.IRON, "obsidian_door"); spectral_block = new BlockSpectral("spectral_block"); obsidian_stairs = new BlockStairsBase("obsidian_stairs", ModBlocks.obsidian_stairs.getDefaultState()); for(Block b : blocks) { ItemBlock ib = new ItemBlock(b); ib.setRegistryName(b.getRegistryName()); GameRegistry.findRegistry(Item.class).register(ib); } } @SubscribeEvent public void registerModels(ModelRegistryEvent e) { for(Block b : blocks) { registerModel(b); } } public static void registerModel(Block block) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(new ResourceLocation(References.MODID, block.getUnlocalizedName().substring(5)), "inventory")); } public List<Block> getBlocks() { return blocks; } }
import fr.vesperia.vesperiamod.init.ModBlocks; import fr.vesperia.vesperiamod.init.ModItems; import net.minecraft.block.BlockStairs; import net.minecraft.block.SoundType; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemBlock; public class BlockStairsBase extends BlockStairs { public BlockStairsBase(String name, IBlockState modelState) { super(modelState); setUnlocalizedName(name); setRegistryName(name); setHardness(50.0F); setResistance(1000.0F); setHarvestLevel("pickaxe", 3); setSoundType(SoundType.STONE); setCreativeTab(VesperiaMod.Modtab); ModBlocks.instance.getBlocks().add(this); ModItems.instance.getItems().add(new ItemBlock(this).setRegistryName(this.getRegistryName())); } }
import fr.vesperia.vesperiamod.init.ModBlocks; import fr.vesperia.vesperiamod.init.ModItems; import fr.vesperia.vesperiamod.registry.RenderRegistry; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class RegisteringEvent { @SubscribeEvent public void registerItems(RegistryEvent.Register<Item> e) { ModItems.instance.init(); e.getRegistry().registerAll(ModItems.instance.getItems().toArray(new Item[0])); } @SubscribeEvent public void BlockRegister(RegistryEvent.Register<Block> e) { ModBlocks.instance.init(); e.getRegistry().registerAll(ModBlocks.instance.getBlocks().toArray(new Block[0])); } }
// This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~] Time: 5/1/20 3:04 PM Description: Initializing game java.lang.NullPointerException: Initializing game at fr.vesperia.vesperiamod.init.ModBlocks.init(ModBlocks.java:80) at fr.vesperia.vesperiamod.event.RegisteringEvent.BlockRegister(RegisteringEvent.java:25) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_5_RegisteringEvent_BlockRegister_Register.invoke(.dynamic) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144) at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:847) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:630) at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252) at net.minecraft.client.Minecraft.init(Minecraft.java:514) at net.minecraft.client.Minecraft.run(Minecraft.java:422) 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:25) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Client thread Stacktrace: at fr.vesperia.vesperiamod.init.ModBlocks.init(ModBlocks.java:80) at fr.vesperia.vesperiamod.event.RegisteringEvent.BlockRegister(RegisteringEvent.java:25) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_5_RegisteringEvent_BlockRegister_Register.invoke(.dynamic) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144) at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:847) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:630) at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252) at net.minecraft.client.Minecraft.init(Minecraft.java:514) -- Initialization -- Details: Stacktrace: at net.minecraft.client.Minecraft.run(Minecraft.java:422) 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:25) -- System Details -- Details: Minecraft Version: 1.12.2 Operating System: Windows 8.1 (amd64) version 6.3 Java Version: 1.8.0_251, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 696570912 bytes (664 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.42 Powered by Forge 14.23.5.2847 5 mods loaded, 5 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored | State | ID | Version | Source | Signature | |:----- |:----------- |:------------ |:-------------------------------- |:--------- | | LCH | minecraft | 1.12.2 | minecraft.jar | None | | LCH | mcp | 9.42 | minecraft.jar | None | | LCH | FML | 8.0.99.99 | forgeSrc-1.12.2-14.23.5.2847.jar | None | | LCH | forge | 14.23.5.2847 | forgeSrc-1.12.2-14.23.5.2847.jar | None | | LCH | vesperiamod | 1.0 | bin | None | Loaded coremods (and transformers): GL info: ' Vendor: 'Intel' Version: '4.3.0 - Build 10.18.14.4264' Renderer: 'Intel(R) HD Graphics 4600' Launched Version: 1.12.2 LWJGL: 2.9.4 OpenGL: Intel(R) HD Graphics 4600 GL version 4.3.0 - Build 10.18.14.4264, Intel 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: Current Language: English (US) Profiler Position: N/A (disabled) CPU: 4x Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz
Voilà j’espère pouvoir régler ce soucis. Merci d’avance.
-
Bonsoir,
Le NPE vient d’icifor(Block b : blocks)
Ta liste de bloc n’est jamais initialisé, donc forcement ça fait un NPE. Le problème est global à tous tes blocs et ne semble pas lié à ton escalier.
-
@Deans a dit dans Problème avec les stairs :
Block b : blocks
Bonsoir,
Merci de m’avoir répondu sauf que comment je fait pour pouvoir faire fonctionner tout ça ?
Merci d’avance.
-
Ah, erreur de ma part, ta variable est en fait initialisé plus bas, je n’avais pas vu (dans la fonction init, ligne 56).
Mais il serait mieux de remplacer:
private List<Block> blocks; public void init() { blocks = Lists.newArrayList();
Par :
private final List<Block> blocks = Lists.newArrayList(); public void init() {
Comme ça pas de risque de npe (d’ailleurs pareil pour les blocs, vaut mieux tout déclarer en constante).
-
Je vient juste faire ce que tu m’as dit et je crash toujours et pareil que le crash-report que j’ai mis plus haut.
-
@Deans a dit dans Problème avec les stairs :
at fr.vesperia.vesperiamod.init.ModBlocks.init(ModBlocks.java:80)
Il y a quoi à cette ligne ? (les lignes sur le code que tu as envoyé ne semble pas correspondre).