Advertisement
Guest User

Untitled

a guest
Feb 25th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. package com.JohnnyMccrum.JohnnyBaseMod.Structure;
  2.  
  3.     import com.JohnnyMccrum.JohnnyBaseMod.init.ModBlocks;
  4.     import java.util.Random;
  5.     import net.minecraft.block.Block;
  6.     import net.minecraft.block.material.Material;
  7.     import net.minecraft.init.Blocks;
  8.     import net.minecraft.world.World;
  9.     import net.minecraft.world.gen.feature.WorldGenerator;
  10.  
  11. public class StructureJohnnyFaceCave extends WorldGenerator
  12. {
  13. protected Block[] GetValidSpawnBlocks()
  14.         {
  15. return new Block[]
  16.                     {
  17. Blocks.grass,
  18. Blocks.dirt,
  19. Blocks.stone,
  20. };
  21. }
  22.  
  23. public boolean LocationIsValidSpawn(World world, int x, int y, int z)
  24.         {
  25. int distanceToAir = 0;
  26. Block checkBlock = world.getBlock(x, y, z);
  27.  
  28.             while (checkBlock != Blocks.air)
  29.             {
  30. distanceToAir++;
  31. checkBlock = world.getBlock(x, y + distanceToAir, z);
  32. }
  33.  
  34. if (distanceToAir > 1)
  35.             {
  36. return false;
  37. }
  38.  
  39. y += distanceToAir - 1;
  40.  
  41. Block block = world.getBlock(x, y, z);
  42. Block blockAbove = world.getBlock(x, y + 1, z);
  43. Block blockBelow = world.getBlock(x, y - 1, z);
  44.  
  45.             for (Block i : GetValidSpawnBlocks())
  46.             {
  47. if (blockAbove != Blocks.air)
  48.                 {
  49. return false;
  50. }
  51. if (block == i)
  52.                 {
  53. return true;
  54. }
  55. else if (block == Blocks.snow_layer && blockBelow == i) {
  56. return true;
  57. }
  58. else if (block.getMaterial() == Material.plants && blockBelow == i)
  59.             {
  60. return true;
  61. }
  62.             }
  63. return false;
  64. }
  65.  
  66. public boolean generate(World world, Random rand, int x, int y, int z)
  67.         {
  68. if (!LocationIsValidSpawn(world, x, y, z) || !LocationIsValidSpawn(world, x + 12, y, z) || !LocationIsValidSpawn(world, x + 12, y, z + 20) || !LocationIsValidSpawn(world, x, y, z + 20)) {
  69. return false;
  70. }
  71.  
  72. world.setBlock(x + 0, y + 0, z + 0, Blocks.stone, 0, 3);
  73. world.setBlock(x + 1, y + 0, z + 0, Blocks.dirt, 0, 3);
  74. <snip>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement