Générer des minerais
-
C’est marrant mais pendant que je cherchais j’ai pensé à ça et c’est après avoir trouvé comment faire que je suis revenue pour montrer la solution et j’ai vu ton message robin ^^’
Du coup pour ceux qui ont la flemme d’aller chercher voilà le code à mettre dans la classe du bloc de minerai (il faut le faire si votre minerai drop un item, pas quand il drop le bloc) :
private Random rand = new Random(); @Override public int getExpDrop(IBlockAccess p_149690_1_, int p_149690_5_, int p_149690_7_) { if (this.getItemDropped(p_149690_5_, rand, p_149690_7_) != Item.getItemFromBlock(this)) { int j1 = 0; if (this == NomDeLaClassePrincipale.NomDeVotreMinerai) { j1 = MathHelper.getRandomIntegerInRange(rand, X, Y); } return j1; } return 0; }X et Y sont à remplacé par des nombres, il représente le nombre d’xp que gagne le joueur en minant le minerais par exemple si je met 0 à X et 2 à Y (comme le charbon) le joueur recevra entre 0 et 2 xp.
-
En fait c’est que je suis un peu perdu dans le code de générations de minerais, pourrait tu nous donné le même code mais avec les donnés remplacée par des blocks et montrez ce qu’il faut modifier.
Cordialement.
-
Il y a un exemple, regarde :
this.addOreSpawn(ModTutoriel.RubyOre, world, random, x, z, 16, 16, 2 + random.nextInt(4), 15, 16, 64);ModTutoriel.RubyOre -> le bloc en question
2 + random.nextInt(4) -> taille du filon
15 -> rateté
16 -> position Y minimum
64 -> position Y maximum. -
Je parle pas de ça ^^
Moi je suis plus perdu dans ce code :public void addOreSpawn(Block block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chancesToSpawn, int minY, int maxY) { assert maxY > minY : "La position Y maximum doit être supérieure à la position Y minimum."; assert maxX > 0 && maxX <= 16 : "X doit se trouver entre 0 et 16."; assert minY > 0 : "La position Y minimum doit être supérieure à 0."; assert maxY < 256 && maxY > 0 : "La position Y maximum doit se trouver entre 0 et 256."; assert maxZ > 0 && maxZ <= 16 : "Z doit se trouver entre 0 et 16."; int diffBtwnMinMaxY = maxY - minY; for (int x = 0; x < chancesToSpawn; x++) { int posX = blockXPos + random.nextInt(maxX); int posY = minY + random.nextInt(diffBtwnMinMaxY); int posZ = blockZPos + random.nextInt(maxZ); (new WorldGenMinable(block, maxVeinSize)).generate(world, random, posX, posY, posZ); } } -
Tu n’a rien à changé dans cette méthode.
-
Ah… xD
Je cours tester le code et si ça marche… Merci à vous tous ^^
Et si ça marche pas bah… Merci quand même ^^EDIT : Ah bah ça marche pas… J’aimerais que mon block soit générer dans le Nether, donc j’ai mis le this… etc. et je trouve pas mon bloc.

Vous mettez en général combien dans le poids de la génération ? -
Tu peux donné tes codes?
-
Ok, les voici :
La classe WorldGeneration :
package fr.redcobble.mod.common; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.feature.WorldGenMinable; import cpw.mods.fml.common.IWorldGenerator; public class WorldGeneration implements IWorldGenerator { public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { switch (world.provider.dimensionId) { case -1: generateNether(world, random, chunkX * 16, chunkZ * 16); case 0: generateSurface(world, random, chunkX * 16, chunkZ * 16); case 1: generateEnd(world, random, chunkX * 16, chunkZ * 16); } } private void generateEnd(World world, Random random, int x, int z) { } private void generateSurface(World world, Random random, int x, int z) { } private void generateNether(World world, Random random, int x, int z) { this.addOreSpawn(ModRedcobble.blockRedcobble, world, random, x, z, 16, 16, 2 + random.nextInt(3), 15, 4, 64); } public void addOreSpawn(Block block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chancesToSpawn, int minY, int maxY) { assert maxY > minY : "La position Y maximum doit être supérieure à la position Y minimum."; assert maxX > 0 && maxX <= 16 : "X doit se trouver entre 0 et 16."; assert minY > 0 : "La position Y minimum doit être supérieure à 0."; assert maxY < 256 && maxY > 0 : "La position Y maximum doit se trouver entre 0 et 256."; assert maxZ > 0 && maxZ <= 16 : "Z doit se trouver entre 0 et 16."; int diffBtwnMinMaxY = maxY - minY; for (int x = 0; x < chancesToSpawn; x++) { int posX = blockXPos + random.nextInt(maxX); int posY = minY + random.nextInt(diffBtwnMinMaxY); int posZ = blockZPos + random.nextInt(maxZ); (new WorldGenMinable(block, maxVeinSize)).generate(world, random, posX, posY, posZ); } } }La classe principale (J’ai mis que les codes utiles pour la génération) :
WorldGeneration worldgeneration = new WorldGeneration(); // Dans les variables GameRegistry.registerWorldGenerator(worldgeneration, 0); // Dans le pre-initPour le block à générer, je l’ai ai bien ajouter, mais je pense pas que ça a dus causer problème à la génération.
-
La génération du monde se fais dans le init si je ne me trompe pas.
-
Nan ça ne marche toujours pas

-
Essayes comme ceci:
private void generateNether(World world, Random random, int blockX, int blockZ) { for(int i=4;i<64;i++) { int Xcoord = blockX + random.nextInt(16); int Ycoord = random.nextInt(15); int Zcoord = blockZ + random.nextInt(16); (new WorldGenMinable(ModRedcobble.blockRedcobble, 2 + random.nextInt(3))).generate(world, random, Xcoord, Ycoord, Zcoord); } } -
Nan, ça ne marche toujours pas

Mais merci d’avoir essayé m’aidé
EDIT : Quelqu’un pourrait me donner ses sources afin de remédier à mon problème ?
-
Bon, ben le tutoriel me semble vraiment largement assez complet, dommage que je ne puisse pas comprendre le code

Je me suis permis de faire la correction [ même si il n’y avait pas grand-chose à faire
] et d’ajouter les crédits, maintenant si Robin ou l’un des autres Admins peut vérifier le code et en faire une vidéo, je pense que le tutoriel peut être validé et ajouté aux autres ^^EDIT : Donc j’en ai parlé avec Robin, et il attend juste que tu rajoutes une partie sur la possibilité de les faire apparaitre dans les autres mondes, et ensuite peut-être que ton tuto sera alors ajouté aux tutoriels validés, en complément de celui fait par les admins plus tard

EDIT2 : Si besoin tu peux te servir du code donné ici : http://www.minecraftforgefrance.fr/showthread.php?tid=833

-
la generation dans le nether ne fonctionne pas, même quand je met la rareté a 50 je trouve rien.
-
Envoie tes codes ?
-
package shaarfight.worldgen; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.feature.WorldGenMinable; import shaarfight.common.ShaarMod; import cpw.mods.fml.common.IWorldGenerator { public class IlluveWorldGeneration implements IWorldGenerator { public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider){ swich (world.provider.dimensionId) { case -1: generateNether(world, random, chunkX * 16, chunkZ * 16); case 0: generateSurface(world, random, chunkX * 16, chunkZ * 16); case 1: generateEnd(world, random, chunkX * 16, chunkZ * 16); } } private void generateSurface(World world, Random random, int x, int z) { } private void generateNether(World world, Random random, int x, int z) { this.addOreSpawn(ShaarMod.oreIlluve, world, random, x, z, 16, 16, 1 + random.netInt(4), 50, 5, ); } public void addOreSpawn(Block block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chancesToSpawn, int minY, int maxY){ assert maxY > minY : "La position Y maximum doit être supérieure à la position Y minimum."; assert maX > 0 && maxX <= 16 : "X doit se trouver entre 0 et 16."; assert minY > 0 : "La position Y minimum doit être supérieure à 0."; assert maxY < 256 && maxY > 0 : "La position Y maximum doit se trouver entre 0 et 256."; assert maxZ > 0 && maxZ <= 16 : "Z doit se trouver entre 0 et 16."; int diffBtwnMinMaxY = maxY - minY; for (int x = 0; x < chancesToSpawn; x++) { int posX = blockXPos + random.nextInt(maxX); int posY = minY + random.nextInt(diffBtwnMinMaxY); int posZ = blockZPos + random.nextInt(maxZ); (new WorldGenMinable(ShaarMod.oreIlluve, 1 + random.nextInt(4))).generate(world, random, posX, posY, posZ); } } }Voilà mon code de ma classe IlluveWorldGeneration.
-
@ryken vas voir le tutoriel 1.6 de robin, c’est la même chose sauf que tu enleves le blockID
-
En effet, sur ce tutoriel ça ne risque pas de fonctionner car il essaye de remplacer la stone, or il n’y a pas de stone dans le nether.
-
package shaarfight.worldgen; import java.util.Random; import shaarfight.common.ShaarMod; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.feature.WorldGenMinable; import cpw.mods.fml.common.IWorldGenerator; public class IlluveWorldGeneration implements IWorldGenerator { @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { } { switch(world.provider.dimensionID) { case -1: this.generateNether(world, chunkX * 16, chunkZ * 16, random); break; } private void generateNether(World world, int x, int z, Random rand) { for(int i = 0; i < 1; i++) { (new WorldGenMinable(ShaarMod.oreIlluve, 0, 5, Blocks.netherrack)).generate(world, rand, x + rand.nextInt(16), rand.nextInt(120), z + rand.nextInt(16)); } { } } } } -
Comme ça, ça devrait être bon oui.
