Résolu Poser un bloc via un item
-
Bonjours,
Je reviens encore avec un problème :Je veux créer un items qui crée un bloc au dessus du bloc sur lequel on clic, je me suis un peu inspiré des class Itemboat, ItemBed et Itemseed.
Le résultat marche temps que je fais apparaître des blocs vanilla mais quand mes blocs sont ajouté le jeu crash
La class de l’item :
public class GrainesChamps extends Item{ private Block plante = BlocksH.BriqueDeCharbon; public GrainesChamps() { super(); } public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World world, int x, int y, int z, int par7, float par8, float par9, float par10) { if (world.isRemote) { return true; } else if (par7 != 1) { return false; } else if(world.getBlock(x, y, z) == Blocks.dirt && world.isAirBlock(x, y+1, z)) { world.setBlock(x, y+1, z, plante); –par1ItemStack.stackSize; return true; } else return false; } }
la class d’un des blocs que j’ai essayé de mettre (rien de plus simple) :
public class BlocBriqueDeCharbon extends Block{ public BlocBriqueDeCharbon(Material material) { super(material); } }
Le rapport d’erreur :
---- Minecraft Crash Report ---- // Surprise! Haha. Well, this is awkward. Time: 09/03/14 14:39 Description: Ticking memory connection java.lang.NullPointerException: Ticking memory connection at net.minecraft.world.chunk.storage.ExtendedBlockStorage.func_150818_a(ExtendedBlockStorage.java:100) at net.minecraft.world.chunk.Chunk.func_150807_a(Chunk.java:685) at net.minecraft.world.World.setBlock(World.java:549) at net.minecraft.world.World.setBlock(World.java:697) at hagrud.Veberisation.Items.GrainesChamps.onItemUse(GrainesChamps.java:34) at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:150) at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:424) at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:596) 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:242) at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:762) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.world.chunk.storage.ExtendedBlockStorage.func_150818_a(ExtendedBlockStorage.java:100) at net.minecraft.world.chunk.Chunk.func_150807_a(Chunk.java:685) at net.minecraft.world.World.setBlock(World.java:549) at net.minecraft.world.World.setBlock(World.java:697) at hagrud.Veberisation.Items.GrainesChamps.onItemUse(GrainesChamps.java:34) at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:150) at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:424) at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:596) 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:242) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@68801131 Stacktrace: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:762) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787) -- System Details -- Details: Minecraft Version: 1.7.2 Operating System: Windows 8 (amd64) version 6.2 Java Version: 1.7.0_45, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 632548824 bytes (603 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 5763 (322728 bytes; 0 MB) allocated, 5037 (282072 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95 FML: MCP v9.01-pre FML v7.2.116.1024 Minecraft Forge 10.12.0.1024 4 mods loaded, 4 mods active mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available FML{7.2.116.1024} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.0.1024.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Forge{10.12.0.1024} [Minecraft Forge] (forgeSrc-1.7.2-10.12.0.1024.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available veberisation{0.0.1} [Veberisation] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Profiler Position: N/A (disabled) Vec3 Pool Size: 1592 (89152 bytes; 0 MB) allocated, 1115 (62440 bytes; 0 MB) used Player Count: 1 / 8; [EntityPlayerMP['Player687'/378, l='New World', x=243,88, y=66,41, z=172,35]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
Le jeu a l’air de crash sur la fonction world.setBlock(x, y+1, z, plante);
note : La class est un essais au final je ne veux pas ajouter des plantes mais des blocs c’est pourquoi je n’utilise pas IPlantable.
Merci pour votre aide.
-
java.lang.NullPointerException. Ton bloc est null, fait voir ta classe principale.
-
Mon problème ce trouve peut-être là :s
Ma classe principale appelle des fonctions qui viennent d’autres classes pour ajouter les blocs et les items.
Ma classe principale
@Mod(modid = Main.MODID, name = "Veberisation", version = "0.0.1") public class Main{ public static final String MODID = "veberisation"; @Instance(MODID) public static Main instance; @SidedProxy(clientSide = "hagrud.Veberisation.Proxy.ClientProxy", serverSide = "hagrud.Veberisation.Proxy.CommonProxy") public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent event) { hagrud.Veberisation.Base.PetiteChose.addCreatTabs(); hagrud.Veberisation.Base.ItemsH.addItems(); hagrud.Veberisation.Base.BlocksH.addBlocks(); } @EventHandler public void init(FMLInitializationEvent event) { proxy.registerRender(); } @EventHandler public void postInit(FMLPostInitializationEvent event) { } }
Ma classe BlocksH.java qui ajoute les blocs
public class BlocksH { public static Block BriqueDeCharbon; public static Block HerbeReplace; public static Block PTest; public static Block Pblesauvage; public static void addBlocks() { BriqueDeCharbon = new BlocBriqueDeCharbon(Material.rock).setBlockName("brique de charbon").setBlockTextureName("veberisation" + ":Bcharbon") .setCreativeTab(CreativeTabs.tabMaterials); GameRegistry.registerBlock(BriqueDeCharbon, "briquecharbon"); HerbeReplace = new HerbreReplace().setBlockName("herbe") .setCreativeTab(CreativeTabs.tabDecorations); GameRegistry.registerBlock(HerbeReplace, "Herbe"); PTest = new PTest(Material.plants).setBlockName("plantetest") .setCreativeTab(CreativeTabs.tabDecorations); GameRegistry.registerBlock(PTest, "Test"); Pblesauvage = new PBlesauvage().setBlockName("planteblesauvage") .setCreativeTab(CreativeTabs.tabDecorations); GameRegistry.registerBlock(Pblesauvage, "blesauvage"); } }
Cette organisation me permet d’avoir un code plus clair (de mon point de vue).
-
Initialise tes blocs avant tes items :
hagrud.Veberisation.Base.BlocksH.addBlocks();
hagrud.Veberisation.Base.ItemsH.addItems();
Comme cela, ça devrait fonctionner. -
Parfait merci de la réponse.