demdem2

nethergenmineable

Oct 26th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. package dem.tutorialmod.init.worldgen;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.google.common.base.Predicate;
  6.  
  7. import net.minecraft.block.state.IBlockState;
  8. import net.minecraft.block.state.pattern.BlockMatcher;
  9. import net.minecraft.init.Blocks;
  10. import net.minecraft.util.math.BlockPos;
  11. import net.minecraft.util.math.MathHelper;
  12. import net.minecraft.world.World;
  13. import net.minecraft.world.gen.feature.WorldGenerator;
  14.  
  15. public class TutorialNetherGenMineable extends WorldGenerator
  16. {
  17. private final IBlockState oreBlock;
  18. /** The number of blocks to generate. */
  19. private final int numberOfBlocks;
  20. private final Predicate<IBlockState> predicate;
  21.  
  22. public TutorialNetherGenMineable(IBlockState state, int blockCount)
  23. {
  24. this(state, blockCount, BlockMatcher.forBlock(Blocks.NETHERRACK)); //IF NETHERRACK IS NEAR THEN SPAWN ORES NEAR WHEN LOADING NEW CHUNK
  25. //EG. TO MAKE SKY ORES MAKE NEW GENMINEABLE AND SET THIS TO BLOCKS.AIR (MIGHT BE WEIRD)
  26. }
  27.  
  28. public TutorialNetherGenMineable(IBlockState state, int blockCount, Predicate<IBlockState> p_i45631_3_)
  29. {
  30. this.oreBlock = state;
  31. this.numberOfBlocks = blockCount;
  32. this.predicate = p_i45631_3_;
  33. }
  34.  
  35. public boolean generate(World worldIn, Random rand, BlockPos position)
  36. {
  37. float f = rand.nextFloat() * (float)Math.PI;
  38. double d0 = (double)((float)(position.getX() + 8) + MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);
  39. double d1 = (double)((float)(position.getX() + 8) - MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);
  40. double d2 = (double)((float)(position.getZ() + 8) + MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);
  41. double d3 = (double)((float)(position.getZ() + 8) - MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);
  42. double d4 = (double)(position.getY() + rand.nextInt(3) - 2);
  43. double d5 = (double)(position.getY() + rand.nextInt(3) - 2);
  44.  
  45. for (int i = 0; i < this.numberOfBlocks; ++i)
  46. {
  47. float f1 = (float)i / (float)this.numberOfBlocks;
  48. double d6 = d0 + (d1 - d0) * (double)f1;
  49. double d7 = d4 + (d5 - d4) * (double)f1;
  50. double d8 = d2 + (d3 - d2) * (double)f1;
  51. double d9 = rand.nextDouble() * (double)this.numberOfBlocks / 16.0D;
  52. double d10 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;
  53. double d11 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;
  54. int j = MathHelper.floor_double(d6 - d10 / 2.0D);
  55. int k = MathHelper.floor_double(d7 - d11 / 2.0D);
  56. int l = MathHelper.floor_double(d8 - d10 / 2.0D);
  57. int i1 = MathHelper.floor_double(d6 + d10 / 2.0D);
  58. int j1 = MathHelper.floor_double(d7 + d11 / 2.0D);
  59. int k1 = MathHelper.floor_double(d8 + d10 / 2.0D);
  60.  
  61. for (int l1 = j; l1 <= i1; ++l1)
  62. {
  63. double d12 = ((double)l1 + 0.5D - d6) / (d10 / 2.0D);
  64.  
  65. if (d12 * d12 < 1.0D)
  66. {
  67. for (int i2 = k; i2 <= j1; ++i2)
  68. {
  69. double d13 = ((double)i2 + 0.5D - d7) / (d11 / 2.0D);
  70.  
  71. if (d12 * d12 + d13 * d13 < 1.0D)
  72. {
  73. for (int j2 = l; j2 <= k1; ++j2)
  74. {
  75. double d14 = ((double)j2 + 0.5D - d8) / (d10 / 2.0D);
  76.  
  77. if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D)
  78. {
  79. BlockPos blockpos = new BlockPos(l1, i2, j2);
  80.  
  81. IBlockState state = worldIn.getBlockState(blockpos);
  82. if (state.getBlock().isReplaceableOreGen(state, worldIn, blockpos, this.predicate))
  83. {
  84. worldIn.setBlockState(blockpos, this.oreBlock, 2);
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93.  
  94. return true;
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment