Non résolu Problème de plantation [1.7.10]
-
Bonjour ou Bonsoir,
Je vient vers vous car j’ai un petit soucis au niveau de ma plantation de mon mod.
Voici le crash-report et les codes de ma plantation :import java.util.Random; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fr.irisium.irisiummod.IrisiumMod; import net.minecraft.block.Block; import net.minecraft.block.BlockBush; import net.minecraft.block.IGrowable; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class BlockSteeliteCropsMod extends BlockBush implements IGrowable { protected int maxGrowthStage = 7; @SideOnly(Side.CLIENT) protected IIcon[] iIcon; public BlockSteeliteCropsMod() { setTickRandomly(true); float f = 0.5F; setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f); setCreativeTab(IrisiumMod.IrisiumMod); setHardness(0.0F); setStepSound(soundTypeGrass); disableStats(); } @Override protected boolean canPlaceBlockOn(Block parBlock) { return parBlock == Blocks.farmland; } public void incrementGrowStage(World parWorld, Random parRand, int parX, int parY, int parZ) { int growStage = parWorld.getBlockMetadata(parX, parY, parZ) + MathHelper.getRandomIntegerInRange(parRand, 2, 5); if (growStage > maxGrowthStage) { growStage = maxGrowthStage; } parWorld.setBlockMetadataWithNotify(parX, parY, parZ, growStage, 2); } @Override public Item getItemDropped(int p_149650_1_, Random parRand, int parFortune) { return Item.getItemFromBlock(this); } @Override public int getRenderType() { return 1; } @Override @SideOnly(Side.CLIENT) public IIcon getIcon(int parSide, int parGrowthStage) { return iIcon [parGrowthStage]; } public interface IGrowable { boolean func_149851_a(World p_149851_1_, int p_149851_2_, int p_149851_3_, int p_149851_4_, boolean p_149851_5_); boolean func_149852_a(World p_149852_1_, Random p_149852_2_, int p_149852_3_, int p_149852_4_, int p_149852_5_); void func_149853_b(World p_149853_1_, Random p_149853_2_, int p_149853_3_, int p_149853_4_, int p_149853_5_); } public boolean func_149851_a(World parWorld, int parX, int parY, int parZ, boolean p_149851_5_) { return parWorld.getBlockMetadata(parX, parY, parZ) != 7; } @Override public boolean func_149852_a(World p_149852_1_, Random parRand, int p_149852_3_, int p_149852_4_, int p_149852_5_) { return true; } @Override public void func_149853_b(World parWorld, Random parRand, int parX, int parY, int parZ) { incrementGrowStage(parWorld, parRand, parX, parY, parZ); } @Override public void updateTick(World parWorld, int parX, int parY, int parZ, Random parRand) { super.updateTick(parWorld, parX, parY, parZ, parRand); int growStage = parWorld.getBlockMetadata(parX, parY, parZ) + 1; if (growStage > 7) { growStage = 7; } parWorld.setBlockMetadataWithNotify(parX, parY, parZ, growStage, 2); } }
---- Minecraft Crash Report ---- // Would you like a cupcake? Time: 03/01/19 00:13 Description: Rendering item java.lang.NullPointerException: Rendering item at fr.irisium.irisiummod.block.crops.BlockSteeliteCropsMod.getIcon(BlockSteeliteCropsMod.java:68) at net.minecraft.block.Block.getBlockTextureFromSide(Block.java:686) at net.minecraft.item.ItemBlock.getIconFromDamage(ItemBlock.java:51) at net.minecraft.item.Item.getIconIndex(Item.java:457) at net.minecraft.item.ItemStack.getIconIndex(ItemStack.java:131) at net.minecraft.client.renderer.entity.RenderItem.renderItemIntoGUI(RenderItem.java:420) at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:585) at net.minecraft.client.gui.inventory.GuiContainer.func_146977_a(GuiContainer.java:289) at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:114) at net.minecraft.client.renderer.InventoryEffectRenderer.drawScreen(InventoryEffectRenderer.java:44) at net.minecraft.client.gui.inventory.GuiContainerCreative.drawScreen(GuiContainerCreative.java:673) at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1137) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1067) at net.minecraft.client.Minecraft.run(Minecraft.java:962) at net.minecraft.client.main.Main.main(Main.java:164) 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 net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at fr.irisium.irisiummod.block.crops.BlockSteeliteCropsMod.getIcon(BlockSteeliteCropsMod.java:68) at net.minecraft.block.Block.getBlockTextureFromSide(Block.java:686) at net.minecraft.item.ItemBlock.getIconFromDamage(ItemBlock.java:51) at net.minecraft.item.Item.getIconIndex(Item.java:457) at net.minecraft.item.ItemStack.getIconIndex(ItemStack.java:131) at net.minecraft.client.renderer.entity.RenderItem.renderItemIntoGUI(RenderItem.java:420) -- Item being rendered -- Details: Item Type: net.minecraft.item.ItemBlock@417df2ed Item Aux: 0 Item NBT: null Item Foil: false Stacktrace: at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:585) at net.minecraft.client.gui.inventory.GuiContainer.func_146977_a(GuiContainer.java:289) at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:114) at net.minecraft.client.renderer.InventoryEffectRenderer.drawScreen(InventoryEffectRenderer.java:44) at net.minecraft.client.gui.inventory.GuiContainerCreative.drawScreen(GuiContainerCreative.java:673) -- Screen render details -- Details: Screen name: net.minecraft.client.gui.inventory.GuiContainerCreative Mouse location: Scaled: (152, 44). Absolute: (305, 391) Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2
J’espère pouvoir trouver une solution à mon problème.
Cordialement, Xemnys -
Courte réponse : 1.7.0 est le problème
Vrai réponse: dans ta fonction getIcon() tu renvois l’icon venant du tableau iIcon avec l’index parGrowthStage cependant ton iIcon n’est jamais initialiser, ton tableau est null et donc quand t’essaye de get un élément dans un tableau null ça crash.Tu peut init le tableau dans le constructeur
-
Bonjour,
Je ne comprend pas trop ou je doit placer le “init” dans le constructeur.Cordialement, Xemnys
-
C’est bon problème résolu, il fallait mettre un
return this.blockIcon;
Cordialement, Xemnys
-
Là tu n’as résolu du tout, tu as juste fait en sorte que la plante affiche toujours la même texture, peu importe son niveau de pousse …
-
tu dois initialiser ton tableau dans ton constructeur
public BlockSteeliteCropsMod() { iIcon = new IIcon[] {} setTickRandomly(true); float f = 0.5F; setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f); setCreativeTab(IrisiumMod.IrisiumMod); setHardness(0.0F); setStepSound(soundTypeGrass); disableStats(); }
tu mes tes IIcon dans le tableau et tu return une icon en fonction du stage de la plante ave le parGrowthStage ou encore ton propre index en fonction du grow stage.
Un conseille va apprendre les bases du java ça t’aidera beaucoup pour faire ton mod,