Advertisement
HalestormXV

Untitled

Apr 20th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.18 KB | None | 0 0
  1. package halestormxv.world.gen;
  2. import java.util.Random;
  3.  
  4.  
  5. import halestormxv.utility.HighQualityRandom;
  6. import halestormxv.world.gen.generators.AdvancedStructureGen;
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.BlockBush;
  9. import net.minecraft.block.BlockVine;
  10. import net.minecraft.block.material.Material;
  11. import net.minecraft.block.properties.PropertyBool;
  12. import net.minecraft.block.state.IBlockState;
  13. import net.minecraft.init.Blocks;
  14. import net.minecraft.util.math.BlockPos;
  15. import net.minecraft.world.World;
  16. import net.minecraft.world.chunk.IChunkProvider;
  17. import net.minecraft.world.gen.IChunkGenerator;
  18. import net.minecraft.world.gen.feature.WorldGenBigMushroom;
  19. import net.minecraft.world.gen.feature.WorldGenBush;
  20. import net.minecraft.world.gen.feature.WorldGenLakes;
  21. import net.minecraft.world.gen.feature.WorldGenMinable;
  22. import net.minecraft.world.gen.feature.WorldGenVines;
  23. import net.minecraft.world.gen.feature.WorldGenWaterlily;
  24. import net.minecraft.world.gen.feature.WorldGenerator;
  25. import net.minecraft.world.gen.structure.template.Template;
  26. import net.minecraftforge.fml.common.IWorldGenerator;
  27.  
  28. public class WorldGenAdvanced extends WorldGenerator implements IWorldGenerator {
  29.  
  30.  
  31.     static Random rand2 = new HighQualityRandom();
  32.     @Override
  33.     public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,
  34.                          IChunkProvider chunkProvider) {
  35.         int blockX = chunkX * 16;
  36.         int blockZ = chunkZ * 16;
  37.  
  38.         switch (world.provider.getDimension())
  39.         {
  40.             case -1:
  41.                 generateNether(world, rand, blockX + 8, blockZ + 8);
  42.                 break;
  43.             case 0:
  44.                 //Higher Number = Less Chance to Spawn
  45.                 generateOverworld(world, rand, 160, blockX + 8, blockZ + 8);
  46.                 break;
  47.             case 1:
  48.                 generateEnd(world, rand, blockX + 8, blockZ + 8);
  49.                 break;
  50.  
  51.         }
  52.  
  53.     }
  54.  
  55.     private void generateOverworld(World world, Random rand, int chance, int blockX, int blockZ)
  56.     {
  57.         if ((int) (Math.random() * chance) == 0)
  58.             {
  59.         int y = getGroundFromAbove(world, blockX, blockZ);
  60.         BlockPos pos = new BlockPos(blockX, y, blockZ);
  61.         WorldGenerator structure = new AdvancedStructureGen("cultist_hut");
  62.         structure.generate(world, rand, pos);
  63.         }
  64.     }
  65.  
  66.     private void generateNether(World world, Random rand, int chunkX, int chunkZ) {}
  67.     private void generateEnd(World world, Random rand, int chunkX, int chunkZ) {}
  68.  
  69.  
  70.     private void addOreSpawn(IBlockState block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY)
  71.     {
  72.         for (int i = 0; i < chanceToSpawn; i++)
  73.         {
  74.             int posX = blockXPos + random.nextInt(maxX);
  75.             int posY = minY + random.nextInt(maxY - minY);
  76.             int posZ = blockZPos + random.nextInt(maxZ);
  77.             new WorldGenMinable(block, maxVeinSize).generate(world, random, new BlockPos(posX, posY, posZ));
  78.         }
  79.     }
  80.  
  81.     public static int getGroundFromAbove(World world, int x, int z)
  82.     {
  83.         int y = 255;
  84.         boolean foundGround = false;
  85.         while(!foundGround && y-- >= 31)
  86.         {
  87.             Block blockAt = world.getBlockState(new BlockPos(x,y,z)).getBlock();
  88.             foundGround =  blockAt == Blocks.WATER||blockAt == Blocks.FLOWING_WATER||blockAt == Blocks.GRASS || blockAt == Blocks.SAND || blockAt == Blocks.SNOW || blockAt == Blocks.SNOW_LAYER || blockAt == Blocks.GLASS||blockAt == Blocks.MYCELIUM;
  89.         }
  90.  
  91.         return y;
  92.     }
  93.     public static int getLakeFromAbove(World world, int x, int z)
  94.     {
  95.         int y = 255;
  96.         boolean foundGround = false;
  97.         while(!foundGround && y-- >= 31)
  98.         {
  99.             Block blockAt = world.getBlockState(new BlockPos(x,y,z)).getBlock();
  100.             foundGround =  blockAt == Blocks.WATER||blockAt == Blocks.FLOWING_WATER;
  101.         }
  102.  
  103.         return y;
  104.     }
  105.  
  106.     public  void vineGen(World world, int x, int z)
  107.     {
  108.  
  109.  
  110.         int y = 255;
  111.  
  112.         Block blockAt;
  113.         BlockPos pos =new BlockPos(x,y,z);
  114.         boolean foundGround = false;
  115.         boolean foundSide = false;
  116.         int r =rand2.nextInt(4);
  117.  
  118.         int i =0;
  119.         int drop = 1;
  120.         while(!foundGround && y-- >= 31)
  121.         {
  122.  
  123.             blockAt = world.getBlockState(new BlockPos(x,y,z)).getBlock();
  124.             foundGround =  blockAt == Blocks.WATER||blockAt == Blocks.FLOWING_WATER||blockAt == Blocks.GRASS || blockAt == Blocks.SAND || blockAt == Blocks.SNOW || blockAt == Blocks.SNOW_LAYER || blockAt == Blocks.GLASS||blockAt == Blocks.MYCELIUM;
  125.  
  126.  
  127.         }
  128.  
  129.  
  130.  
  131.  
  132.         while(!foundSide && ++i <= 48)
  133.         {
  134.  
  135.  
  136.             switch(r) {
  137.                 case 0:x++;
  138.                 case 1:x--;
  139.                 case 2:z++;
  140.                 case 3:z--;
  141.             }
  142.             //  System.out.println(r);
  143.             //System.out.println(new BlockPos(x,y,z));
  144.             blockAt = world.getBlockState(new BlockPos(x,y,z)).getBlock();
  145.             foundSide =   blockAt == Blocks.AIR&& world.getBlockState(new BlockPos(x,y-drop,z)).getBlock() == Blocks.AIR;
  146.  
  147.         }
  148.  
  149.  
  150.  
  151.         i = 0;
  152.         BlockPos blockpos$mutableblockpos1 = new BlockPos(x,y,z);
  153.  
  154.  
  155.  
  156.  
  157.  
  158.         //  System.out.println(world.getBlockState(blockpos$mutableblockpos1).getMaterial() == Material.AIR);
  159.  
  160.  
  161.         if ((world.getBlockState(new BlockPos(x,y,z)).getBlock() == Blocks.AIR))
  162.         {
  163.             BlockPos blockpos3 = blockpos$mutableblockpos1.west();
  164.             BlockPos blockpos4 = blockpos$mutableblockpos1.east();
  165.             BlockPos blockpos1 = blockpos$mutableblockpos1.north();
  166.             BlockPos blockpos2 = blockpos$mutableblockpos1.south();
  167.  
  168.  
  169.  
  170.             if ( (world.isAirBlock(blockpos3)))
  171.             {
  172.                 //System.out.println("EAST");
  173.                 addVine(world, blockpos3, BlockVine.EAST);
  174.  
  175.             }
  176.  
  177.             if ( world.isAirBlock(blockpos4))
  178.             {
  179.                 addVine(world, blockpos4, BlockVine.WEST);
  180.                 //System.out.println("WEST");
  181.             }
  182.  
  183.             if ( world.isAirBlock(blockpos1))
  184.             {
  185.                 addVine(world, blockpos1, BlockVine.SOUTH);
  186.                 // System.out.println("SOUTH");
  187.             }
  188.  
  189.             if ( world.isAirBlock(blockpos2))
  190.             {
  191.                 addVine(world, blockpos2, BlockVine.NORTH);
  192.                 //  System.out.println("NORTH");
  193.             }
  194.  
  195.         }
  196.  
  197.  
  198.     }
  199.     private  void addVine(World worldIn, BlockPos pos, PropertyBool prop)
  200.     {
  201.         IBlockState iblockstate = Blocks.VINE.getDefaultState().withProperty(prop, Boolean.valueOf(true));
  202.         this.setBlockAndNotifyAdequately(worldIn, pos, iblockstate);
  203.         int i = 15+rand2.nextInt(15);;
  204.  
  205.         for (BlockPos blockpos = pos.down(); worldIn.isAirBlock(blockpos) && i > 0; --i)
  206.         {
  207.             setBlockAndNotifyAdequately(worldIn, blockpos, iblockstate);
  208.             blockpos = blockpos.down();
  209.         }
  210.     }
  211.     public static boolean canSpawnHere(Template template, World world, BlockPos posAboveGround)
  212.     {
  213.         int zwidth = template.getSize().getZ();
  214.         int xwidth = template.getSize().getX();
  215.  
  216.         // check all the corners to see which ones are replaceable
  217.         boolean corner1 = isCornerValid(world, posAboveGround);
  218.         boolean corner2 = isCornerValid(world, posAboveGround.add(xwidth, 0, zwidth));
  219.  
  220.         // if Y > 20 and all corners pass the test, it's okay to spawn the structure
  221.         return posAboveGround.getY() > 31 && corner1 && corner2;
  222.     }
  223.  
  224.     public static boolean isCornerValid(World world, BlockPos pos)
  225.     {
  226.         int variation = 3;
  227.         int highestBlock = getGroundFromAbove(world, pos.getX(), pos.getZ());
  228.  
  229.         if (highestBlock > pos.getY() - variation && highestBlock < pos.getY() + variation)
  230.             return true;
  231.  
  232.         return false;
  233.     }
  234.  
  235.     @Override
  236.     public boolean generate(World worldIn, Random rand, BlockPos position) {
  237.         // TODO Auto-generated method stub
  238.         return false;
  239.     }
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement