Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.34 KB | None | 0 0
  1. package sporeaoc.byg.world.tree;
  2.  
  3. import com.mojang.datafixers.Dynamic;
  4. import net.minecraft.block.BlockState;
  5. import net.minecraft.util.Direction;
  6. import net.minecraft.util.math.BlockPos;
  7. import net.minecraft.util.math.MutableBoundingBox;
  8. import net.minecraft.world.gen.IWorldGenerationBaseReader;
  9. import net.minecraft.world.gen.IWorldGenerationReader;
  10. import net.minecraft.world.gen.feature.AbstractTreeFeature;
  11. import net.minecraft.world.gen.feature.NoFeatureConfig;
  12. import sporeaoc.byg.catalogs.BlockCatalogs;
  13.  
  14. import java.util.Random;
  15. import java.util.Set;
  16. import java.util.function.Function;
  17.  
  18. import static net.minecraft.util.math.BlockPos.*;
  19.  
  20. //Copied and Pasted Dark Oak to try and undertstand the logic and math for tree creation.
  21. public class RealCypressTree extends AbstractTreeFeature<NoFeatureConfig> {
  22.     private static final BlockState LOG = BlockCatalogs.CYPRESS_LOG.getDefaultState();
  23.     private static final BlockState LEAVES = BlockCatalogs.CYPRESS_LEAVES.getDefaultState();
  24.  
  25.     public RealCypressTree(Function<Dynamic<?>, ? extends NoFeatureConfig> configIn, boolean doBlockNotifyIn) {
  26.         super(configIn, doBlockNotifyIn);
  27.         //setSapling((net.minecraftforge.common.IPlantable) Blocks.DARK_OAK_SAPLING);
  28.     }
  29.  
  30.     public RealCypressTree() {
  31.         super(null, true);
  32.     } //
  33.  
  34.     public boolean place(Set<BlockPos> changedBlocks, IWorldGenerationReader worldIn, Random rand, BlockPos position, MutableBoundingBox boundsIn) {
  35.         int randtreeheight = rand.nextInt(25) + rand.nextInt(2) + 6; //First value changes height of the trunk.
  36.         int posx = position.getX();
  37.         int posy = position.getY();
  38.         int posz = position.getZ();
  39.         if (posy >= 1 && posy + randtreeheight + 1 < 256) {
  40.             BlockPos blockpos = position.down();
  41.             if (!isSoil(worldIn, blockpos, getSapling())) {
  42.                 return false;
  43.             } else if (!this.func_214615_a(worldIn, position, randtreeheight)) {
  44.                 return false;
  45.             } else {
  46.                 this.setDirtAt(worldIn, blockpos, position);
  47.                 this.setDirtAt(worldIn, blockpos.east(), position);
  48.                 this.setDirtAt(worldIn, blockpos.south(), position);
  49.                 this.setDirtAt(worldIn, blockpos.south().east(), position);
  50.                 Direction direction = Direction.Plane.HORIZONTAL.random(rand);
  51.                 int random1 = randtreeheight - rand.nextInt(1);//Crashes on 0. Unknown use.
  52.                 int posy1 = 2 - rand.nextInt(1);//Crashes on 0. Unknown Use
  53.                 int posx1 = posx;
  54.                 int posz1 = posz;
  55.                 int posy2 = posy + randtreeheight - 1;
  56.  
  57.                 int z1 = posx;
  58.                 int z2 = posy;
  59.                 int z3 = posz;
  60.  
  61.                 for(int posx2 = 3; posx2 < randtreeheight; ++posx2) {//raising this value will remove log blocks from the ground up.
  62.                     if (posx2 >= random1 && posy1 > 0) { //Unknown
  63.                         posx1 += direction.getXOffset();
  64.                         posz1 += direction.getZOffset();
  65.                         --posy1;
  66.                     }
  67.                     int k2 = posy + posx2;
  68.                     BlockPos blockpos1 = new BlockPos(posx1, k2, posz1);
  69.                     if (isAirOrLeaves(worldIn, blockpos1)) {
  70.                         this.treelog(changedBlocks, worldIn, blockpos1, boundsIn);
  71.                         this.treelog(changedBlocks, worldIn, blockpos1.east(), boundsIn);
  72.                         this.treelog(changedBlocks, worldIn, blockpos1.south(), boundsIn);
  73.                         this.treelog(changedBlocks, worldIn, blockpos1.west(), boundsIn);
  74.                         this.treelog(changedBlocks, worldIn, blockpos1.north(), boundsIn);
  75.                     }
  76.  
  77.                 }
  78.  
  79.                 /*&BlockPos pos1;
  80.                 for (int z = 0; randtreeheight < 5; z++) {
  81.                     pos1 = new BlockPos(z1, z2 - 1, z3);
  82.                     z = (int) (z1 / 2.5);
  83.                     this.setBlockState(worldIn, pos1.add(-z1, 0, 0), LOG);
  84.                     this.setBlockState(worldIn, pos1.add(-z1, 0, -z3), LOG);
  85.                     this.setBlockState(worldIn, pos1.add(z1, 0, -z3), LOG);
  86.                     this.setBlockState(worldIn, pos1.add(z1, 0, -z3), LOG);
  87.                     this.setBlockState(worldIn, pos1.add(z1, 0, 0), LOG);
  88.                     this.setBlockState(worldIn, pos1.add(z1, 0, z3), LOG);
  89.                     this.setBlockState(worldIn, pos1.add(0, 0, z3), LOG);
  90.                     this.setBlockState(worldIn, pos1.add(-z1, 0, z3), LOG);
  91.                 }
  92.                 */
  93.                 for(int j3 = -2; j3 <= 0; ++j3) {//has to do with leaves
  94.                     for(int i4 = -2; i4 <= 0; ++i4) {
  95.                         int l4 = -100;//Unknown
  96.                         this.leafs(worldIn, posx1 + j3, posy2 + l4, posz1 + i4, boundsIn, changedBlocks);
  97.                         this.leafs(worldIn, 1 + posx1 - j3, posy2 + l4, posz1 + i4, boundsIn, changedBlocks);
  98.                         this.leafs(worldIn, posx1 + j3, posy2 + l4, 1 + posz1 - i4, boundsIn, changedBlocks);
  99.                         this.leafs(worldIn, 1 + posx1 - j3, posy2 + l4, 1 + posz1 - i4, boundsIn, changedBlocks);
  100.                         this.leafs(worldIn, posx1 + j3, posy2 + l4, posz1 + i4, boundsIn, changedBlocks);
  101.                         this.leafs(worldIn, 1 + posx1 - j3, posy2 + l4, posz1 + i4, boundsIn, changedBlocks);
  102.  
  103.  
  104.                         if ((j3 > -2 || i4 > -1) && (j3 != -1 || i4 != -2)) {
  105.                             l4 = 1;//sets leave height?
  106.                             this.leafs(worldIn, posx1 + j3, posy2 + l4, posz1 + i4, boundsIn, changedBlocks);
  107.                             this.leafs(worldIn, 1 + posx1 - j3, posy2 + l4, posz1 + i4, boundsIn, changedBlocks);
  108.                             this.leafs(worldIn, posx1 + j3, posy2 + l4, 1 + posz1 - i4, boundsIn, changedBlocks);
  109.                             this.leafs(worldIn, 1 + posx1 - j3, posy2 + l4, 1 + posz1 - i4, boundsIn, changedBlocks);
  110.                             this.leafs(worldIn, posx1 + j3, posy2 + l4, posz1 + i4, boundsIn, changedBlocks);
  111.                             this.leafs(worldIn, 1 + posx1 - j3, posy2 + l4, posz1 + i4, boundsIn, changedBlocks);
  112.  
  113.  
  114.  
  115.  
  116.                         }
  117.                     }
  118.                 }
  119.                 //Layer1
  120.                 if (rand.nextBoolean()) { //these are for the top 4 leaves on the top layer of the tree. these values change the x, y, and z values on them
  121.                     this.leafs(worldIn, posx1, posy2 + 2, posz1, boundsIn, changedBlocks);
  122.                     this.leafs(worldIn, posx1 + 1, posy2 + 2, posz1, boundsIn, changedBlocks);
  123.                     this.leafs(worldIn, posx1 + 1, posy2 + 2, posz1 + 1, boundsIn, changedBlocks);
  124.                     this.leafs(worldIn, posx1, posy2 + 2, posz1 + 1, boundsIn, changedBlocks);
  125.                 }
  126.                     //Layer2
  127.                 for(int k3 = -1; k3 <= 4; ++k3) { //Changes X
  128.                     for(int j4 = -3; j4 <= 4; ++j4) { //Changes Z
  129.                         if ((k3 != -3 || j4 != -3) && (k3 != -3 || j4 != 4) && (k3 != 4 || j4 != -3) && (k3 != 4 || j4 != 4) && (Math.abs(k3) < 3 || Math.abs(j4) < 3)) {
  130.                             this.leafs(worldIn, posx1 + k3, posy2, posz1 + j4, boundsIn, changedBlocks);
  131.                         }
  132.                     }
  133.                 }
  134.                 //Layer
  135.                 for(int l3 = -1; l3 <= 2; ++l3) { //changes the X width of the top tree area
  136.                     for(int k4 = -1; k4 <= 2; ++k4) { //changes the Z width of the top tree area
  137.                         if ((l3 < 0 || l3 > 1 || k4 < 0 || k4 > 1) && rand.nextInt(3) <= 0) { //makes the tree increase upwards
  138.                             int i5 = rand.nextInt(3) + 2; //makes the tree increase both upwards and downwards
  139.  
  140.                             /*for(int l2 = 0; l2 < i5; ++l2) { //does nothing
  141.                                 this.treelog(changedBlocks, worldIn, new BlockPos(posx + l3, posy2 - l2 - 2, posz + k4), boundsIn); //creates Branches, number value of 2 or lower does nothing 5 seems to be a good value
  142.                             }*/
  143.  
  144.                             /*for (int z2 = 5; z2 < i5;)
  145.                                 this.treelog(changedBlocks, worldIn, new BlockPos(j2 + l3, posy2 - z2 , posz + k4), boundsIn); //creates Base, number value of 2 or lower does nothing 5 seems to be a good value
  146. //LAYER 3 */
  147.                             for(int j5 = -1; j5 <= 1; ++j5) { //changes the x width of the leaves on row 3
  148.                                 for(int i3 = -1; i3 <= 1; ++i3) { //changes the z width of the leaves on row 3
  149.                                     this.leafs(worldIn, posx1 + l3 + j5, posy2, posz1 + k4 + i3, boundsIn, changedBlocks);
  150.                                 }
  151.                             }
  152. //LAYER 4
  153.                             for(int k5 = -2; k5 <= 2; ++k5) { //changes the X width of the leaves on row 4
  154.                                 for(int l5 = -2; l5 <= 2; ++l5) { //changes the Z width of the leaves on row 4
  155.                                     if (Math.abs(k5) != 2 || Math.abs(l5) != 2) { //does nothing
  156.                                         this.leafs(worldIn, posx1 + l3 + k5, posy2 - 1, posz1 + k4 + l5, boundsIn, changedBlocks); //posy2 -1 apears to have no change on the tree
  157.                                     }
  158.                                 }
  159.                             }
  160.                         }
  161.                     }
  162.                 }
  163.  
  164.                 return true;
  165.             }
  166.         } else {
  167.             return false;
  168.         }
  169.     }
  170.         //Tree Height Maybe?
  171.     private boolean func_214615_a(IWorldGenerationBaseReader p_214615_1_, BlockPos p_214615_2_, int p_214615_3_) {
  172.         int i = p_214615_2_.getX();
  173.         int j = p_214615_2_.getY();
  174.         int k = p_214615_2_.getZ();
  175.         MutableBlockPos blockpos$mutableblockpos = new MutableBlockPos();
  176.  
  177.         for(int l = 0; l <= p_214615_3_ + 1; ++l) {
  178.             int i1 = 1; //higher the value, lower the density of trees?
  179.             if (l == 0) { //does nothing?
  180.                 i1 = 0; //higher the value, lower the density of trees?
  181.             }
  182.  
  183.             if (l >= p_214615_3_ - 1) {
  184.                 i1 = 1; //higher the value, lower the density of trees?
  185.             }
  186.  
  187.             for(int j1 = -i1; j1 <= i1; ++j1) {
  188.                 for(int k1 = -i1; k1 <= i1; ++k1) {
  189.                     if (!func_214587_a(p_214615_1_, blockpos$mutableblockpos.setPos(i + j1, j + l, k + k1))) {
  190.                         return false;
  191.                     }
  192.                 }
  193.             }
  194.         }
  195.  
  196.         return true;
  197.     }
  198.     //Log Placement
  199.     private void treelog(Set<BlockPos> setlogblock, IWorldGenerationReader reader, BlockPos pos, MutableBoundingBox boundingBox) {
  200.         if (func_214587_a(reader, pos)) {
  201.             this.setLogState(setlogblock, reader, pos, LOG, boundingBox);
  202.         }
  203.  
  204.     }
  205.     //Leaves Placement
  206.     private void leafs(IWorldGenerationReader reader, int p_214617_2_, int p_214617_3_, int p_214617_4_, MutableBoundingBox p_214617_5_, Set<BlockPos> p_214617_6_) {
  207.         BlockPos blockpos = new BlockPos(p_214617_2_, p_214617_3_, p_214617_4_);
  208.         if (isAir(reader, blockpos)) {
  209.             this.setLogState(p_214617_6_, reader, blockpos, LEAVES, p_214617_5_);
  210.         }
  211.  
  212.     }
  213. }
  214. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement