Tu as fait des changements entre temps alors, car dans le premier crash il y avait un npe ici :
at fr.mrazerty31.IHC4.Berry.onItemUse(Berry.java:46)
Ton les cas ton bloc est null, envoie tout ta classe principale
Bonsoir tout le monde, désolé du flood intensif de topics, mais j’ai un problème que je n’arrive pas à résoudre (malgré mes recherches Google) donc j’explique :
Je veux créer une nouvelle plante tout est bien, aucune erreur sur le debugger java mais quand je clique-droit sur la farmland avec la graine, le jeu crash :huh: Et je ne sais pas pourquoi
Classe du Block (Plantation) :
package fr.mrazerty31.IHC4; import javax.swing.Icon; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.BlockCarrot; import net.minecraft.block.BlockCrops; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.util.IIcon; public class BlockBerryPlant extends BlockCarrot { public static String[] type = new String[]{"b1", "b2", "b3", "b4", "b5", "b6", "b7"}; private IIcon[] IconArray; public IIcon getIcon(int side, int metadata) { return metadata < type.length && metadata >= 0 ? IconArray[metadata] : IconArray[0]; } public void registerIcons(IIconRegister iconregister) { IconArray = new IIcon[type.length]; for(int i = 0; i < type.length; i++) { IconArray[i] = iconregister.registerIcon("ihc4mod:" + type*); } } protected Item getSeedItem() { return IHC4.berrySeeds; } protected Item getCropItem() { return IHC4.berry; } public int damageDropped(int metadata) { return metadata; } }
Crash report : http://pastebin.com/47T5HgTF
Envoie la classe Berry.java il y a une NPE dedans à la ligne 46
Classe berry :
package fr.mrazerty31.IHC4; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.EnumPlantType; import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.util.ForgeDirection; public class Berry extends ItemFood { public Berry(int p_i45339_1_, float p_i45339_2_, boolean p_i45339_3_) { super(p_i45339_1_, p_i45339_2_, p_i45339_3_); this.setCreativeTab(CreativeTabs.tabFood); } }
Voici mon crash report : http://pastebin.com/1j3HRNpX
@‘MrAzErTy31’:
Classe berry :
package fr.mrazerty31.IHC4; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.EnumPlantType; import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.util.ForgeDirection; public class Berry extends ItemFood { public Berry(int p_i45339_1_, float p_i45339_2_, boolean p_i45339_3_) { super(p_i45339_1_, p_i45339_2_, p_i45339_3_); this.setCreativeTab(CreativeTabs.tabFood); } }
Voici mon crash report : http://pastebin.com/1j3HRNpX
Pas cette classe l’autre celui de la seed.
Je n’ai pas créer une classe pour ça : (dans le preInit)
berrySeeds = new ItemSeeds(blockBerry, Blocks.farmland).setUnlocalizedName("berry_seeds").setTextureName("ihc4mod:berry_seeds").setCreativeTab(CreativeTabs.tabMaterials);
Tu as fait des changements entre temps alors, car dans le premier crash il y avait un npe ici :
at fr.mrazerty31.IHC4.Berry.onItemUse(Berry.java:46)
Ton les cas ton bloc est null, envoie tout ta classe principale
Classe principale :
package fr.mrazerty31.IHC4; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemSeeds; import net.minecraft.item.ItemStack; import net.minecraft.util.WeightedRandomChestContent; import net.minecraftforge.common.ChestGenHooks; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; 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.registry.GameRegistry; import fr.mrazerty31.IHC4.proxy.CommonProxy; @Mod(modid = IHC4.MODID, name = "IHC4 Mod", version = IHC4.VERSION) public class IHC4 { public static final String MODID = "ihc4mod"; public static final String VERSION = "1.0"; public static IHC4 instance; @SidedProxy(clientSide = "fr.mrazerty31.IHC4.proxy.ClientProxy", serverSide = "fr.mrazerty31.IHC4.proxy.CommonProxy") public static CommonProxy proxy; /* Déclaration des Items */ public static Item berry, ironBerry, goldenBerry, berrySeeds; /* Déclaration des Blocks */ public static Block blockBerry; @EventHandler public void preInit(FMLPreInitializationEvent event) { berry = new Berry(1, 0.3F, false).setUnlocalizedName("berry").setTextureName("ihc4mod:berry"); ironBerry = new IronBerry(1, 0.3F, false).setUnlocalizedName("iron_berry").setTextureName("ihc4mod:berry_iron"); goldenBerry = new GoldBerry(1, 0.3F, false).setUnlocalizedName("golden_berry").setTextureName("ihc4mod:berry_gold"); berrySeeds = new ItemSeeds(blockBerry, Blocks.farmland).setUnlocalizedName("berry_seeds").setTextureName("ihc4mod:berry_seeds").setCreativeTab(CreativeTabs.tabMaterials); blockBerry = new BlockBerryPlant().setBlockName("block_berry"); } @EventHandler public void init(FMLInitializationEvent event) { GameRegistry.registerItem(berry, "berry"); GameRegistry.registerItem(ironBerry, "iron_berry"); GameRegistry.registerItem(goldenBerry, "golden_berry"); GameRegistry.registerItem(berrySeeds, "berry_seeds"); GameRegistry.registerBlock(blockBerry, "block_berry"); ChestGenHooks.addItem(ChestGenHooks.MINESHAFT_CORRIDOR, new WeightedRandomChestContent(berry, 0, 0, 4, 10)); proxy.registerRender(); } @EventHandler public void postInit(FMLPostInitializationEvent event) { GameRegistry.addRecipe(new ItemStack(ironBerry), "ib", 'i', Blocks.iron_block, 'b', berry); GameRegistry.addRecipe(new ItemStack(goldenBerry), " g ", "gbg", " g ", 'g', Items.gold_ingot, 'b', berry); } }
Merci de vos réponses
Ok, c’est bien ce que je pensais, toutes ta classe principale est mal foutu.
Normalement, ça devrait être comme ça :
preInit :
// initialisation des blocs
// enregistrement des blocs
// initialisation des items
// enregistrement des items
init :
// le reste.
Donc :
package fr.mrazerty31.IHC4; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemSeeds; import net.minecraft.item.ItemStack; import net.minecraft.util.WeightedRandomChestContent; import net.minecraftforge.common.ChestGenHooks; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; 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.registry.GameRegistry; import fr.mrazerty31.IHC4.proxy.CommonProxy; @Mod(modid = IHC4.MODID, name = "IHC4 Mod", version = IHC4.VERSION) public class IHC4 { public static final String MODID = "ihc4mod"; public static final String VERSION = "1.0"; public static IHC4 instance; @SidedProxy(clientSide = "fr.mrazerty31.IHC4.proxy.ClientProxy", serverSide = "fr.mrazerty31.IHC4.proxy.CommonProxy") public static CommonProxy proxy; /* Déclaration des Items */ public static Item berry, ironBerry, goldenBerry, berrySeeds; /* Déclaration des Blocks */ public static Block blockBerry; @EventHandler public void preInit(FMLPreInitializationEvent event) { blockBerry = new BlockBerryPlant().setBlockName("block_berry"); GameRegistry.registerBlock(blockBerry, "block_berry"); berry = new Berry(1, 0.3F, false).setUnlocalizedName("berry").setTextureName("ihc4mod:berry"); ironBerry = new IronBerry(1, 0.3F, false).setUnlocalizedName("iron_berry").setTextureName("ihc4mod:berry_iron"); goldenBerry = new GoldBerry(1, 0.3F, false).setUnlocalizedName("golden_berry").setTextureName("ihc4mod:berry_gold"); berrySeeds = new ItemSeeds(blockBerry, Blocks.farmland).setUnlocalizedName("berry_seeds").setTextureName("ihc4mod:berry_seeds").setCreativeTab(CreativeTabs.tabMaterials); GameRegistry.registerItem(berry, "berry"); GameRegistry.registerItem(ironBerry, "iron_berry"); GameRegistry.registerItem(goldenBerry, "golden_berry"); GameRegistry.registerItem(berrySeeds, "berry_seeds"); } @EventHandler public void init(FMLInitializationEvent event) { ChestGenHooks.addItem(ChestGenHooks.MINESHAFT_CORRIDOR, new WeightedRandomChestContent(berry, 0, 0, 4, 10)); proxy.registerRender(); } @EventHandler public void postInit(FMLPostInitializationEvent event) { GameRegistry.addRecipe(new ItemStack(ironBerry), "ib", 'i', Blocks.iron_block, 'b', berry); GameRegistry.addRecipe(new ItemStack(goldenBerry), " g ", "gbg", " g ", 'g', Items.gold_ingot, 'b', berry); } }
Merci pour la réponse Mais ça crash toujours quand je place la graine sur la farmland
Voici le crash report : http://pastebin.com/Ee1uqUx8
D’après le crash report il me semble que ca viens de la classe du bloc
Classe du bloc plante :
package fr.mrazerty31.IHC4; import javax.swing.Icon; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.BlockCarrot; import net.minecraft.block.BlockCrops; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.util.IIcon; public class BlockBerryPlant extends BlockCarrot { private String[] type = new String[]{"block_berry_stage_0", "block_berry_stage_1", "block_berry_stage_2", "block_berry_stage_3", "block_berry_stage_4", "block_berry_stage_5", "block_berry_stage_6"}; private IIcon[] IconArray; public IIcon getIcon(int side, int metadata) { return metadata < type.length && metadata >= 0 ? IconArray[metadata] : IconArray[0]; } public void registerBlocksIcons(IIconRegister iconregister) { IconArray = new IIcon[type.length]; for(int i = 0; i < type.length; i++) IconArray[i] = iconregister.registerIcon("ihc4mod:" + type*); } protected Item getSeedItem() { return IHC4.berrySeeds; } protected Item getCropItem() { return IHC4.berry; } public int damageDropped(int metadata) { return metadata; } }
envoi ta classe blockBerryPlant, tu as un problème au getIcon
(J’ai mis à jour mon post)
C’est registerBlockIcons et non registerBlocksIcons
OH god … Merci beaucoup robin !
pense a mettre ton sujet en résolue
je sais que ce sujet est vieux et que vous ne faite plus de support pour la 1.7.10 mais j’ai un problème c’est que mon éclipse accepte pas les “*” dans les ligne de code
comme ici
for(int i = 0; i < type.length; i++) IconArray* = iconregister.registerIcon("valerium:" + type*);
ça devrait être [i]
et non une étoile.