Dwarf_Killer

Worldgenminable.java

Mar 26th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. package com.Dwarf_Puncher.TitanTurtles.BlocksAndItems;
  2.  
  3.  
  4. import com.google.common.base.Predicate;
  5. import java.util.Random;
  6.  
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.state.IBlockState;
  9. import net.minecraft.block.state.pattern.BlockMatcher;
  10. import net.minecraft.init.Blocks;
  11. import net.minecraft.util.math.BlockPos;
  12. import net.minecraft.util.math.MathHelper;
  13. import net.minecraft.world.World;
  14. import net.minecraft.world.gen.feature.WorldGenerator;
  15.  
  16.  
  17. public class CustomBlockWorldGenMinable extends WorldGenerator
  18. {
  19. private final IBlockState oreBlock;
  20. private final int numberOfBlocks;
  21. private final Block[] genIn;
  22. private final Block[] genNear;
  23. private final int genDistance;
  24.  
  25. public CustomBlockWorldGenMinable(IBlockState block,int veinSize,Block[] generateIn,Block[] generateNear,int generateInDistance)
  26. {
  27. this.oreBlock = block;
  28. this.numberOfBlocks = veinSize;
  29. this.genIn = generateIn;
  30. this.genNear = generateNear;
  31. this.genDistance = generateInDistance;
  32. }
  33. public CustomBlockWorldGenMinable(IBlockState block,int veinSize)
  34. {
  35. this(block, veinSize, new Block[]{Blocks.stone});
  36. }
  37. public CustomBlockWorldGenMinable(IBlockState block,int veinSize, Block[] generateIn)
  38. {
  39. this(block, veinSize, generateIn, null, 1);
  40. }
  41.  
  42. private boolean isReplaceable(World worldIn, BlockPos blockpos, Block[] genIn)
  43. {
  44. for(Block block : genIn)
  45. {
  46. if(worldIn.getBlockState(blockpos).getBlock() == block)
  47. {
  48. return true;
  49. }
  50. }
  51.  
  52. return false;
  53. }
  54. private boolean isNear(BlockPos blockpos, Block[] near, int distance, World worldIn)
  55. {
  56. for (int x = (blockpos.getX()-distance); x <= (blockpos.getX()+distance); ++x)
  57. {
  58. for (int y = (blockpos.getY()-distance); y <= (blockpos.getY()+distance); ++y)
  59. {
  60. for (int z = (blockpos.getZ()-distance); z <= (blockpos.getZ()+distance); ++z)
  61. {
  62. BlockPos Nearblockpos = new BlockPos(x, y, z);
  63.  
  64. for(Block nearblock : near)
  65. {
  66. if(worldIn.getBlockState(Nearblockpos).getBlock() == nearblock && Nearblockpos != blockpos)
  67. {
  68. return true;
  69. }
  70. }
  71. }
  72. }
  73. }
  74. return false;
  75. }
  76. public boolean generate(World worldIn, Random rand, BlockPos position)
  77. {
  78. float f = rand.nextFloat() * (float)Math.PI;
  79. double d0 = (double)((float)(position.getX() + 8) + MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);
  80. double d1 = (double)((float)(position.getX() + 8) - MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);
  81. double d2 = (double)((float)(position.getZ() + 8) + MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);
  82. double d3 = (double)((float)(position.getZ() + 8) - MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);
  83. double d4 = (double)(position.getY() + rand.nextInt(3) - 2);
  84. double d5 = (double)(position.getY() + rand.nextInt(3) - 2);
  85.  
  86. for (int i = 0; i < this.numberOfBlocks; ++i)
  87. {
  88. float f1 = (float)i / (float)this.numberOfBlocks;
  89. double d6 = d0 + (d1 - d0) * (double)f1;
  90. double d7 = d4 + (d5 - d4) * (double)f1;
  91. double d8 = d2 + (d3 - d2) * (double)f1;
  92. double d9 = rand.nextDouble() * (double)this.numberOfBlocks / 16.0D;
  93. double d10 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;
  94. double d11 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;
  95. int j = MathHelper.floor_double(d6 - d10 / 2.0D);
  96. int k = MathHelper.floor_double(d7 - d11 / 2.0D);
  97. int l = MathHelper.floor_double(d8 - d10 / 2.0D);
  98. int i1 = MathHelper.floor_double(d6 + d10 / 2.0D);
  99. int j1 = MathHelper.floor_double(d7 + d11 / 2.0D);
  100. int k1 = MathHelper.floor_double(d8 + d10 / 2.0D);
  101.  
  102. for (int l1 = j; l1 <= i1; ++l1)
  103. {
  104. double d12 = ((double)l1 + 0.5D - d6) / (d10 / 2.0D);
  105.  
  106. if (d12 * d12 < 1.0D)
  107. {
  108. for (int i2 = k; i2 <= j1; ++i2)
  109. {
  110. double d13 = ((double)i2 + 0.5D - d7) / (d11 / 2.0D);
  111.  
  112. if (d12 * d12 + d13 * d13 < 1.0D)
  113. {
  114. for (int j2 = l; j2 <= k1; ++j2)
  115. {
  116. double d14 = ((double)j2 + 0.5D - d8) / (d10 / 2.0D);
  117.  
  118. if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D)
  119. {
  120. BlockPos blockpos = new BlockPos(l1, i2, j2);
  121.  
  122. IBlockState state = worldIn.getBlockState(blockpos);
  123.  
  124. if (this.isReplaceable(worldIn, blockpos, this.genIn))
  125. {
  126. if (this.genNear == null)
  127. {
  128. worldIn.setBlockState(blockpos, this.oreBlock, 2);
  129. }
  130. else
  131. {
  132. if(this.isNear(blockpos, this.genNear, this.genDistance, worldIn))
  133. {
  134. worldIn.setBlockState(blockpos, this.oreBlock, 2);
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145.  
  146. return true;
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment