SHARE
TWEET

Untitled

a guest Aug 16th, 2019 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.izako.HunterX.world;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import com.izako.HunterX.world.gen.generators.WorldGenStructure;
  7. import com.izako.HunterX.worlddata.StructureSpawning;
  8.  
  9. import net.minecraft.block.Block;
  10. import net.minecraft.client.Minecraft;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.nbt.NBTTagCompound;
  13. import net.minecraft.util.math.BlockPos;
  14. import net.minecraft.util.text.TextComponentString;
  15. import net.minecraft.world.World;
  16. import net.minecraft.world.WorldType;
  17. import net.minecraft.world.biome.Biome;
  18. import net.minecraft.world.biome.BiomeForest;
  19. import net.minecraft.world.biome.BiomePlains;
  20. import net.minecraft.world.chunk.IChunkProvider;
  21. import net.minecraft.world.gen.IChunkGenerator;
  22. import net.minecraft.world.gen.feature.WorldGenerator;
  23. import net.minecraftforge.fml.common.IWorldGenerator;
  24. import scala.actors.threadpool.Arrays;
  25.  
  26. public class WorldGenCustomStructures implements IWorldGenerator {
  27.    
  28.     NBTTagCompound nbt = new NBTTagCompound();
  29.    
  30.  
  31.     public static final WorldGenStructure BLIMP = new WorldGenStructure("blimp");
  32.    
  33.     @Override
  34.     public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,IChunkProvider chunkProvider) {
  35.         if(!world.isRemote) {
  36.         StructureSpawning data = StructureSpawning.get(world);
  37.         switch(world.provider.getDimension()) {
  38.         case 1:
  39.            
  40.         break;
  41.        
  42.         case 0:
  43.         if(data.getBlimpCount() < 1) {
  44.             generateStructure(BLIMP, world, random, chunkX, chunkZ, 10, Blocks.GRASS , BiomePlains.class);
  45.             generateStructure(BLIMP, world, random, chunkX, chunkZ, 10, Blocks.GRASS , BiomeForest.class);
  46.         }
  47.         break;
  48.        
  49.         case -1:
  50.            
  51.         }
  52.         }
  53.        
  54.     }
  55.     private void generateStructure(WorldGenerator generator, World world, Random random, int chunkX, int chunkZ, int chance, Block topBlock,  Class<?>... classes) {
  56.        
  57.        
  58.         ArrayList<Class<?>> classesList = new ArrayList<Class<?>>(Arrays.asList(classes));
  59.        
  60.         if(!world.isRemote) {
  61.            
  62.         StructureSpawning data = StructureSpawning.get(world);
  63.  
  64.            
  65.            
  66.        
  67.         int x = (chunkX * 16) + random.nextInt(15);
  68.         int z = (chunkZ * 16) + random.nextInt(15);
  69.         int y = calculateGenerationHeight(world, x, z, topBlock);
  70.         BlockPos pos = new BlockPos(x,y,z);
  71.        
  72.         Class<?> biome = world.provider.getBiomeForCoords(pos).getClass();
  73.        
  74.         if(world.getWorldType() != WorldType.FLAT) {
  75.            
  76.             if(classesList.contains(biome)) {
  77.                 if (random.nextInt(chance) == 0) {
  78.                     generator.generate(world, random, pos);
  79.                      data.setPos(pos.getX(), pos.getY(), pos.getZ());                  
  80.                    
  81.                    
  82.                     data.setBlimpCount(data.getBlimpCount() + 1);
  83.                    
  84.                    
  85.                 }
  86.                    
  87.            
  88.                 }
  89.             }
  90.            
  91.         }
  92.        
  93.     }
  94.    
  95.     private static int calculateGenerationHeight(World world, int x, int z, Block topBlock) {
  96.         int y = world.getHeight();
  97.         boolean foundground = false;
  98.        
  99.         while(!foundground && y-- >= 0) {
  100.             Block block = world.getBlockState(new BlockPos(x,y,z)).getBlock();
  101.             foundground = block == topBlock;
  102.         }
  103.        
  104.     return y;
  105.     }
  106.  
  107. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top