Résolu Génération de minerais
-
Bonjour,
J’ai un problème et une question :
problème :
Je n’arrives pas à générer mon block même dans l’overworldquestion :
Comment on fait comment pour choisir dans quel block notre minerai spawn pour que ça marche dans les différantes dimensions ?public class OreGeneration implements IWorldGenerator { @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator generator, IChunkProvider provider) { switch (world.provider.getDimension()) { case 1: generateEnd(random, chunkX, chunkZ, world, generator, provider); case 0: generateOverworld(random, chunkX, chunkZ, world, generator, provider); case -1: generateNether(random, chunkX, chunkZ, world, generator, provider); } } private void generateEnd(Random random, int chunkX, int chunkZ, World world, IChunkGenerator generator, IChunkProvider provider) { generateOre(ModBlocks.RUBY_ORE.getDefaultState(), world, random, chunkX * 16, chunkZ * 16, 1, 256, 1, 1, 200); } private void generateOverworld(Random random, int chunkX, int chunkZ, World world, IChunkGenerator generator, IChunkProvider provider) { } private void generateNether(Random random, int chunkX, int chunkZ, World world, IChunkGenerator generator, IChunkProvider provider) { } private void generateOre(IBlockState ore, World world, Random random, int x, int z, int minY, int maxY, int minSize, int maxSize, int chances) { int deltaY = maxY - minY; for (int i = 0; i < chances; i++) { BlockPos pos = new BlockPos(x + random.nextInt(16), minY + random.nextInt(deltaY), z + random.nextInt(16)); WorldGenMinable generator = new WorldGenMinable(ore, random.nextInt(maxSize) + minSize); generator.generate(world, random, pos); } } }
Classe principal :
@Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { proxy.preInit(); GameRegistry.registerWorldGenerator(new OreGeneration(), 3); }
-
C’est bon, j’ai régler mon problème :
public class OreGeneration implements IWorldGenerator { @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator generator, IChunkProvider provider) { switch (world.provider.getDimension()) { case 1: runGenerator(ModBlocks.RUBY_ORE, Blocks.END_STONE, 8, 200, 0, 256, random, chunkX, chunkZ, world); break; } } private void runGenerator(Block block, Block blockIn, int maxSize, int chance, int minHeight, int maxHeight, Random random, int chunkX, int chunkZ, World world) { if (minHeight > maxHeight || minHeight < 0 || minHeight > 256) throw new IllegalArgumentException("Ore Generated out of bounds"); int heightDiff = maxHeight - minHeight + 1; for (int i = 0; i < chance; i++) { int x = chunkX * 16 + random.nextInt(16); int y = minHeight + random.nextInt(heightDiff); int z = chunkZ * 16 + random.nextInt(16); WorldGenerator generator = new WorldGenMinable(block.getDefaultState(), maxSize, BlockMatcher.forBlock(blockIn)); generator.generate(world, random, new BlockPos(x, y, z)); } } }
-
Salut,
Si ton minerai ne spawn pas dans l’overworld, c’est parce que tu l’a mis dans generateEnd au lieu de ta méthode generateOverworld.
Et je ne comprend pas ta question : dans quel block ton minerai spawn ?
Ton minerai spawn aléatoirement dans n’importe quel block. Je ne comprends donc pas ta question.PS : Zom’ le meilleur x)
-
Mdrrrrrr bv
-
C’est bon, j’ai régler mon problème :
public class OreGeneration implements IWorldGenerator { @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator generator, IChunkProvider provider) { switch (world.provider.getDimension()) { case 1: runGenerator(ModBlocks.RUBY_ORE, Blocks.END_STONE, 8, 200, 0, 256, random, chunkX, chunkZ, world); break; } } private void runGenerator(Block block, Block blockIn, int maxSize, int chance, int minHeight, int maxHeight, Random random, int chunkX, int chunkZ, World world) { if (minHeight > maxHeight || minHeight < 0 || minHeight > 256) throw new IllegalArgumentException("Ore Generated out of bounds"); int heightDiff = maxHeight - minHeight + 1; for (int i = 0; i < chance; i++) { int x = chunkX * 16 + random.nextInt(16); int y = minHeight + random.nextInt(heightDiff); int z = chunkZ * 16 + random.nextInt(16); WorldGenerator generator = new WorldGenMinable(block.getDefaultState(), maxSize, BlockMatcher.forBlock(blockIn)); generator.generate(world, random, new BlockPos(x, y, z)); } } }