Résolu Crash avec les dalles
-
Bonjour à tous,
M’étant lancé depuis quelque semaine dans la création d’un mod rajoutant quelque block à minecraft, j’ai suivi beaucoup de vos tutoriel et je commence à comprendre le truc néanmoins, je suis coincé depuis quelques jour sur les dalles.
Après quelque recherche sur le forum, j’ai trouvé les sources pour la version 1.7.2. Mais dès que je tente de poser une dalle sur une autre (pour faire une double dalle) le jeu crash et j’obtiens cette erreur :
–-- Minecraft Crash Report ---- // This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~] Time: 03/07/14 17:54 Description: Unexpected error java.lang.NullPointerException: Unexpected error at fr.khantyer.myblock.common.ItemDalleBuche.onItemUse(ItemDalleBuche.java:79) at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:144) at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:407) at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1498) at net.minecraft.client.Minecraft.runTick(Minecraft.java:2011) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:996) at net.minecraft.client.Minecraft.run(Minecraft.java:912) at net.minecraft.client.main.Main.main(Main.java:112) 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:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) A detailed walkthrough of the error, its code path and all known details is as follows: –------------------------------------------------------------------------------------- -- Head -- Stacktrace: at fr.khantyer.myblock.common.ItemDalleBuche.onItemUse(ItemDalleBuche.java:79) at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:144) at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:407) at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1498) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['ForgeDevName'/252, l='MpServer', x=144,26, y=67,62, z=213,07]] Chunk stats: MultiplayerChunkCache: 225, 225 Level seed: 0 Level generator: ID 00 - default, ver 1\. Features enabled: false Level generator options: Level spawn location: World: (167,64,212), Chunk: (at 7,4,4 in 10,13; contains blocks 160,0,208 to 175,255,223), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Level time: 11603 game time, 11603 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 95 total; [EntityCreeper['Creeper'/137, l='MpServer', x=163,66, y=30,00, z=252,69], EntitySheep['Sheep'/136, l='MpServer', x=166,06, y=64,00, z=223,03], EntitySheep['Sheep'/139, l='MpServer', x=163,41, y=64,00, z=270,44], EntityCreeper['Creeper'/138, l='MpServer', x=162,09, y=30,00, z=252,34], EntitySheep['Sheep'/141, l='MpServer', x=163,03, y=65,00, z=262,47], EntitySheep['Sheep'/140, l='MpServer', x=161,29, y=68,00, z=261,61], EntityEnderman['Enderman'/143, l='MpServer', x=188,53, y=22,00, z=254,53], EntitySheep['Sheep'/129, l='MpServer', x=149,06, y=68,00, z=253,91], EntitySheep['Sheep'/128, l='MpServer', x=150,03, y=68,00, z=248,97], EntitySheep['Sheep'/131, l='MpServer', x=156,74, y=69,00, z=258,00], EntitySheep['Sheep'/130, l='MpServer', x=162,81, y=69,00, z=247,97], EntityCreeper['Creeper'/135, l='MpServer', x=169,50, y=17,00, z=185,50], EntityCreeper['Creeper'/134, l='MpServer', x=170,66, y=15,85, z=182,69], EntitySkeleton['Skeleton'/159, l='MpServer', x=199,96, y=19,00, z=132,53], EntityZombie['Zombie'/144, l='MpServer', x=184,79, y=31,00, z=277,30], EntitySquid['Squid'/147, l='MpServer', x=190,27, y=47,45, z=274,61], EntityCreeper['Creeper'/170, l='MpServer', x=198,87, y=24,00, z=257,24], EntityCreeper['Creeper'/169, l='MpServer', x=199,60, y=24,00, z=256,45], EntitySquid['Squid'/168, l='MpServer', x=202,81, y=47,13, z=235,40], EntityZombie['Zombie'/163, l='MpServer', x=204,53, y=20,00, z=215,59], EntityBat['Bat'/162, l='MpServer', x=198,32, y=13,41, z=216,07], EntityCow['Cow'/161, l='MpServer', x=207,81, y=63,00, z=205,56], EntityCreeper['Creeper'/160, l='MpServer', x=205,48, y=21,47, z=202,45], EntityZombie['Zombie'/167, l='MpServer', x=198,50, y=24,00, z=255,50], EntityZombie['Zombie'/166, l='MpServer', x=200,21, y=20,00, z=246,99], EntityZombie['Zombie'/165, l='MpServer', x=207,66, y=16,00, z=254,00], EntityBat['Bat'/164, l='MpServer', x=209,14, y=17,00, z=215,72], EntityCow['Cow'/186, l='MpServer', x=220,50, y=64,00, z=190,50], EntityBat['Bat'/50, l='MpServer', x=65,53, y=38,78, z=183,00], EntityChicken['Chicken'/187, l='MpServer', x=219,76, y=64,00, z=181,03], EntityBat['Bat'/185, l='MpServer', x=215,44, y=33,38, z=165,52], EntityBat['Bat'/55, l='MpServer', x=70,75, y=22,91, z=258,24], EntityChicken['Chicken'/190, l='MpServer', x=223,24, y=62,44, z=200,02], EntityBat['Bat'/54, l='MpServer', x=71,43, y=21,76, z=263,25], EntitySkeleton['Skeleton'/191, l='MpServer', x=209,50, y=15,00, z=220,09], EntityCreeper['Creeper'/53, l='MpServer', x=65,69, y=24,00, z=259,50], EntityChicken['Chicken'/188, l='MpServer', x=216,44, y=64,00, z=185,38], EntityZombie['Zombie'/52, l='MpServer', x=70,38, y=46,00, z=193,47], EntitySkeleton['Skeleton'/189, l='MpServer', x=208,50, y=21,00, z=206,50], EntityBat['Bat'/58, l='MpServer', x=66,21, y=59,00, z=276,77], EntityBat['Bat'/57, l='MpServer', x=76,67, y=58,16, z=270,69], EntityBat['Bat'/56, l='MpServer', x=68,90, y=19,00, z=272,55], EntityBat['Bat'/68, l='MpServer', x=89,74, y=18,00, z=161,19], EntitySquid['Squid'/69, l='MpServer', x=81,65, y=46,90, z=163,79], EntitySquid['Squid'/70, l='MpServer', x=92,92, y=50,29, z=162,75], EntityZombie['Zombie'/71, l='MpServer', x=80,63, y=20,00, z=180,94], EntityZombie['Zombie'/65, l='MpServer', x=90,31, y=18,00, z=157,69], EntityCreeper['Creeper'/66, l='MpServer', x=92,28, y=27,00, z=144,50], EntitySquid['Squid'/67, l='MpServer', x=81,38, y=53,29, z=152,74], EntitySpider['Spider'/76, l='MpServer', x=84,59, y=61,42, z=280,56], EntityZombie['Zombie'/77, l='MpServer', x=87,41, y=61,00, z=273,13], EntityZombie['Zombie'/78, l='MpServer', x=87,50, y=61,00, z=272,37], EntityCreeper['Creeper'/79, l='MpServer', x=87,97, y=61,00, z=290,41], EntityEnderman['Enderman'/72, l='MpServer', x=83,56, y=18,00, z=179,59], EntityCreeper['Creeper'/193, l='MpServer', x=222,31, y=14,00, z=225,44], EntitySheep['Sheep'/73, l='MpServer', x=95,56, y=65,00, z=208,66], EntityZombie['Zombie'/192, l='MpServer', x=216,10, y=24,00, z=208,41], EntityCreeper['Creeper'/74, l='MpServer', x=85,53, y=62,00, z=283,56], EntitySpider['Spider'/75, l='MpServer', x=89,28, y=61,00, z=274,47], EntitySheep['Sheep'/85, l='MpServer', x=104,79, y=64,00, z=212,22], EntitySheep['Sheep'/84, l='MpServer', x=102,72, y=64,00, z=204,25], EntityZombie['Zombie'/87, l='MpServer', x=107,56, y=24,00, z=231,09], EntityZombie['Zombie'/86, l='MpServer', x=104,28, y=15,00, z=226,91], EntityZombie['Zombie'/81, l='MpServer', x=103,00, y=22,00, z=153,41], EntityZombie['Zombie'/83, l='MpServer', x=111,53, y=17,00, z=204,25], EntitySkeleton['Skeleton'/93, l='MpServer', x=112,50, y=17,00, z=136,50], EntitySheep['Sheep'/92, l='MpServer', x=109,31, y=67,00, z=272,78], EntityCreeper['Creeper'/95, l='MpServer', x=126,50, y=42,00, z=172,50], EntityZombie['Zombie'/94, l='MpServer', x=118,47, y=20,00, z=144,09], EntitySheep['Sheep'/89, l='MpServer', x=111,81, y=65,00, z=233,31], EntityZombie['Zombie'/88, l='MpServer', x=106,44, y=26,00, z=231,97], EntitySheep['Sheep'/91, l='MpServer', x=108,94, y=67,00, z=280,72], EntitySheep['Sheep'/90, l='MpServer', x=108,03, y=67,00, z=273,63], EntityZombie['Zombie'/102, l='MpServer', x=113,25, y=19,00, z=242,25], EntitySheep['Sheep'/103, l='MpServer', x=122,66, y=68,00, z=283,47], EntitySkeleton['Skeleton'/100, l='MpServer', x=126,50, y=32,00, z=204,50], EntityZombie['Zombie'/101, l='MpServer', x=120,88, y=55,00, z=211,50], EntitySkeleton['Skeleton'/98, l='MpServer', x=120,03, y=43,00, z=187,88], EntitySkeleton['Skeleton'/99, l='MpServer', x=116,11, y=45,00, z=188,50], EntityZombie['Zombie'/96, l='MpServer', x=119,50, y=43,00, z=188,69], EntityCreeper['Creeper'/97, l='MpServer', x=118,31, y=43,00, z=186,31], EntityCreeper['Creeper'/111, l='MpServer', x=143,57, y=35,00, z=154,42], EntitySheep['Sheep'/104, l='MpServer', x=123,13, y=67,00, z=286,59], EntitySheep['Sheep'/105, l='MpServer', x=122,47, y=67,00, z=290,09], EntityZombie['Zombie'/116, l='MpServer', x=135,52, y=60,00, z=285,06], EntityClientPlayerMP['ForgeDevName'/252, l='MpServer', x=144,26, y=67,62, z=213,07], EntityZombie['Zombie'/115, l='MpServer', x=131,50, y=60,00, z=284,50], EntityBat['Bat'/114, l='MpServer', x=136,31, y=41,33, z=183,21], EntitySheep['Sheep'/113, l='MpServer', x=131,59, y=64,00, z=174,77], EntityZombie['Zombie'/112, l='MpServer', x=141,50, y=43,00, z=173,50], EntitySheep['Sheep'/127, l='MpServer', x=154,88, y=66,00, z=238,91], EntitySheep['Sheep'/126, l='MpServer', x=149,13, y=64,00, z=195,06], EntityBat['Bat'/125, l='MpServer', x=162,13, y=51,67, z=203,42], EntityBat['Bat'/124, l='MpServer', x=148,20, y=42,03, z=184,20], EntityCreeper['Creeper'/123, l='MpServer', x=149,97, y=43,00, z=181,72]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:412) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2523) at net.minecraft.client.Minecraft.run(Minecraft.java:941) at net.minecraft.client.main.Main.main(Main.java:112) 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:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) – System Details -- Details: Minecraft Version: 1.7.2 Operating System: Windows 7 (amd64) version 6.1 Java Version: 1.6.0_45, Sun Microsystems Inc. Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Sun Microsystems Inc. Memory: 884140456 bytes (843 MB) / 1065025536 bytes (1015 MB) up to 1065025536 bytes (1015 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 11942 (668752 bytes; 0 MB) allocated, 2 (112 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94 FML: MCP v9.03 FML v7.2.217.1147 Minecraft Forge 10.12.2.1147 4 mods loaded, 4 mods active mcp{9.03} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available FML{7.2.217.1147} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.2.1147.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Forge{10.12.2.1147} [Minecraft Forge] (forgeSrc-1.7.2-10.12.2.1147.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available myblock{0.1} [Minefield Block] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Launched Version: 1.7 LWJGL: 2.9.0 OpenGL: Intel(R) HD Graphics 3000 GL version 3.1.0 - Build 9.17.10.3347, Intel 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) Vec3 Pool Size: 2207 (123592 bytes; 0 MB) allocated, 22 (1232 bytes; 0 MB) used Anisotropic Filtering: Off (1)
Ça fait 3 jours que je cherche une solution donc je me tourne désormais vers vous afin d’obtenir de l’aide.
Classe DalleBuche :
package fr.khantyer.myblock.common; import java.util.List; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockSlab; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.World; public class DalleBuche extends BlockSlab { public static final String[] StepTypes = new String[] {"oak", "spruce", "birch", "jungle"}; public DalleBuche(boolean isdouble, Material material) { super(isdouble, material); if(!this.field_150004_a) { this.setLightOpacity(0); } } @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int metadata) { int k = metadata & 7; return k == 0 ? Blocks.log.getIcon(side, 0) : k == 1 ? Blocks.log.getIcon(side, 1) : k == 2 ? Blocks.log.getIcon(side, 2) : Blocks.log.getIcon(side, 3); } @SideOnly(Side.CLIENT) private static boolean func_150003_a(Block block) { return block == ModMyBlock.dalleBuche; } @SideOnly(Side.CLIENT) public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_) { return func_150003_a(this) ? Item.getItemFromBlock(ModMyBlock.dalleBuche) : Item.getItemFromBlock(ModMyBlock.doubleDalleBuche); } protected ItemStack createStackedBlock(int metadata) { return new ItemStack(ModMyBlock.dalleBuche, 2, metadata & 7); } @SideOnly(Side.CLIENT) public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) { if(item != Item.getItemFromBlock(ModMyBlock.doubleDalleBuche)) { for(int i = 0; i < StepTypes.length; i++) { list.add(new ItemStack(item, 1, i)); } } } @Override public String func_150002_b(int metadata) { if(metadata < 0 || metadata >= StepTypes.length) { metadata = 0; } return super.getUnlocalizedName() + "." + StepTypes[metadata]; } }
Classe ItemBlockDalleBuche
package fr.khantyer.myblock.common; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.World; public class ItemDalleBuche extends ItemBlock { private final boolean isFullBlock; private final Block theHalfSlab; private final Block doubleSlab; public ItemDalleBuche(Block block) { super(block); this.theHalfSlab = ModMyBlock.dalleBuche; this.doubleSlab = ModMyBlock.doubleDalleBuche; if(block == ModMyBlock.doubleDalleBuche) { this.isFullBlock = true; } else { this.isFullBlock = false; } this.setMaxDamage(0); this.setHasSubtypes(true); } @SideOnly(Side.CLIENT) public IIcon getIconFromDamage(int metadata) { return this.field_150939_a.getIcon(2, metadata); } public int getMetadata(int metadata) { return metadata; } public String getUnlocalizedName(ItemStack stack) { return ((DalleBuche)theHalfSlab).func_150002_b(stack.getItemDamage()); } public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10) { if (this.isFullBlock) { return super.onItemUse(stack, player, world, x, y, z, side, par8, par9, par10); } else if (stack.stackSize == 0) { return false; } else if (!player.canPlayerEdit(x, y, z, side, stack)) { return false; } else { Block i1 = world.getBlock(x, y, z); int j1 = world.getBlockMetadata(x, y, z); int k1 = j1 & 7; boolean flag = (j1 & 8) != 0; if ((side == 1 && !flag || side == 0 && flag) && i1 == this.theHalfSlab && k1 == stack.getItemDamage()) { if (world.checkNoEntityCollision(this.doubleSlab .getCollisionBoundingBoxFromPool(world, x, y, z)) && world.setBlock(x, y, z, this.doubleSlab, k1, 3)) { world.playSoundEffect( (double) ((float) x + 0.5F), (double) ((float) y + 0.5F), (double) ((float) z + 0.5F), this.doubleSlab.stepSound.getStepResourcePath(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getPitch() * 0.8F); –stack.stackSize; } return true; } else { return this.placeDoubleSlabFromTop(stack, player, world, x, y, z, side) ? true : super.onItemUse(stack, player, world, x, y, z, side, par8, par9, par10); } } } @SideOnly(Side.CLIENT) public boolean func_150936_a(World world, int x, int y, int z, int side, EntityPlayer player, ItemStack stack) { int i1 = x; int j1 = y; int k1 = z; Block id = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); int j2 = meta & 7; boolean flag = (meta & 8) != 0; if((side == 1 && !flag || side == 0 && flag) && id == this.theHalfSlab && j2 == stack.getItemDamage()) { return true; } else { if(side == 0) { --y; } if(side == 1) { ++y; } if(side == 2) { --z; } if(side == 3) { ++z; } if(side == 4) { --x; } if(side == 5) { ++x; } id = world.getBlock(x, y, z); meta = world.getBlockMetadata(x, y, z); j2 = meta & 7; flag = (meta & 8) != 0; return id == this.theHalfSlab && j2 == stack.getItemDamage() ? true : super.func_150936_a(world, i1, j1, k1, side, player, stack); } } private boolean placeDoubleSlabFromTop(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side) { if(side == 0) { --y; } if(side == 1) { ++y; } if(side == 2) { --z; } if(side == 3) { ++z; } if(side == 4) { --x; } if(side == 5) { ++x; } Block i1 = world.getBlock(x, y, z); int j1 = world.getBlockMetadata(x, y, z); int k1 = j1 & 7; if(i1 == this.theHalfSlab && k1 == stack.getItemDamage()) { if(world.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBoxFromPool(world, x, y, z)) && world.setBlock(x, y, z, this.doubleSlab, k1, 3)) { world.playSoundEffect((double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), this.doubleSlab.stepSound.getStepResourcePath(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getPitch() * 0.8F); --stack.stackSize; } return true; } else { return false; } } }
Merci par avance pour votre aide
-
Salut, dans le crash sur eclipse clic sur : java:79 à cette endroit : at fr.khantyer.myblock.common.ItemDalleBuche.onItemUse(ItemDalleBuche.java:79)
ça devrait te sélectionner une ligne du code, envoie-la -
Voici la ligne en question :
.getCollisionBoundingBoxFromPool(world, x, y, z))
Elle est incluse dans cette condition :
if (world.checkNoEntityCollision(this.doubleSlab .getCollisionBoundingBoxFromPool(world, x, y, z)) && world.setBlock(x, y, z, this.doubleSlab, k1, 3))
-
L’objet doubleSlab est null. Je peux avoir ta classe principale ?
-
public static Block dalleBuche, doubleDalleBuche; @EventHandler public void preInit(FMLPreInitializationEvent event) { dalleBuche = new DalleBuche(false, Material.wood).setBlockName("Dalle_Buche").setCreativeTab(CreativeTabs.tabBlock); GameRegistry.registerBlock(dalleBuche, ItemDalleBuche.class, "dalle_buche"); doubleDalleBuche = new DalleBuche(true, Material.wood).setBlockName("Double_Dalle_Buche"); GameRegistry.registerBlock(doubleDalleBuche, ItemDalleBuche.class, "double_dalle_buche"); }
Sachant que this.doubleSlab est initialisée dans le constructeur :
this.doubleSlab = ModMyBlock.doubleDalleBuche; -
Fait comme ça :
@EventHandler public void preInit(FMLPreInitializationEvent event) { dalleBuche = new DalleBuche(false, Material.wood).setBlockName("Dalle_Buche").setCreativeTab(CreativeTabs.tabBlock); doubleDalleBuche = new DalleBuche(true, Material.wood).setBlockName("Double_Dalle_Buche"); GameRegistry.registerBlock(dalleBuche, ItemDalleBuche.class, "dalle_buche"); GameRegistry.registerBlock(doubleDalleBuche, ItemDalleBuche.class, "double_dalle_buche"); }
L’ordre est important, sinon la classe ItemDalleBuche est initialisé alors que doubleDalleBuche est encore null.
-
Effectivement, ça fonctionne beaucoup mieux
Merci beaucoup
Problème résolu