Advertisement
Guest User

MC 1.16.4 Ore Feature Gen Code

a guest
Jan 4th, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.05 KB | None | 0 0
  1. public class OreTest extends Feature<OreFeatureConfig> {
  2.     public OreTest(Codec<OreFeatureConfig> codec) {
  3.         super(codec);
  4.     }
  5.  
  6.     public static final class OreData {
  7.         private static final HashSet<Long> seeds = new HashSet<Long>(); // Record set of all seeds test generated in for result set
  8.         private static final HashMap<Integer, Tuple<Long, Long>> veinCount = new HashMap<Integer, Tuple<Long, Long>>(); // Count all veins recorded per config size given & sum of all ores tracked
  9.         private static final NonNullList<Tuple<Integer, Integer>> oreVeins = NonNullList.withSize(21, new Tuple<Integer, Integer>(0, 0)); // Count min/max vein sizes per config size given
  10.         private static final HashMap<Integer, HashMap<Integer, Long>> veinSizeCounts = new HashMap<Integer, HashMap<Integer, Long>>(); // Count veins of all sizes per config size given
  11.  
  12.         private static void addOreVein(long seed, int veinConfigSize, int veinSize) {
  13.             HashMap<Integer, Long> veinSizeCounter = veinSizeCounts.getOrDefault(veinConfigSize, new HashMap<Integer, Long>());
  14.             Tuple<Integer, Integer> veinCounterData = oreVeins.get(veinConfigSize);
  15.             Tuple<Long, Long> veinCountData = veinCount.getOrDefault(veinConfigSize, new Tuple<Long, Long>(0L, 0L));
  16.  
  17.             veinSizeCounter.put(veinSize, veinSizeCounter.get(veinSize) != null ? veinSizeCounter.get(veinSize) + 1 : 1);
  18.             veinSizeCounts.put(veinConfigSize, veinSizeCounter);
  19.             seeds.add(seed);
  20.  
  21.             long veinsTotal = veinCountData.getA() + 1;
  22.             long totalOresTracked = veinCountData.getB() + veinSize;
  23.  
  24.             veinCount.put(veinConfigSize, new Tuple<Long, Long>(veinsTotal, totalOresTracked));
  25.  
  26.             int minVeinSize = Math.min(veinCounterData.getA(), veinSize);
  27.             int maxVeinSize = Math.max(veinCounterData.getB(), veinSize);
  28.  
  29.             oreVeins.set(veinConfigSize, new Tuple<Integer, Integer>(minVeinSize, maxVeinSize));
  30.         }
  31.  
  32.         public static void doResultsPrintout() {
  33.             System.out.println("Printing out ore vein generation results");
  34.             System.out.println("--~~--~~--");
  35.             System.out.println();
  36.             System.out.println("Counted veins from " + seeds.size() + " seeds total.");
  37.             System.out.println("~~");
  38.             System.out.println("Printed out:");
  39.  
  40.             veinCount.forEach((configSize, veinsCounted) -> {
  41.                 System.out.println("    " + veinsCounted.getA() + " total veins for input 'size' value of " + configSize);
  42.             });
  43.  
  44.             System.out.println();
  45.             System.out.println("    For config 'size' values: ");
  46.  
  47.             veinSizeCounts.forEach((configSize, veinSizesMap) -> {
  48.                 System.out.println("        " + configSize + " - Found: ");
  49.  
  50.                 Tuple<Integer, Integer> minMaxSizes = oreVeins.get(configSize);
  51.                 Tuple<Long, Long> veinCountData = veinCount.get(configSize);
  52.  
  53.                 double avg = veinCountData.getB() / (double)veinCountData.getA();
  54.                 avg = ((int)(avg * 1000) / 1000d); // Round to 3 significant digits
  55.  
  56.                 System.out.println("            Min ores in vein: " + minMaxSizes.getA() + ". Max ores in vein: " + minMaxSizes.getB() + " (" + avg + " avg ores per generation attempt.)");
  57.  
  58.                 veinSizesMap.forEach((veinSize, numVeins) -> {
  59.                     System.out.println("            " + numVeins + " veins with " + veinSize + " ores.");
  60.                 });
  61.             });
  62.  
  63.             System.out.println();
  64.             System.out.println("~~");
  65.         }
  66.     }
  67.  
  68.     public boolean generate(ISeedReader reader, ChunkGenerator generator, Random rand, BlockPos pos, OreFeatureConfig config) {
  69.         boolean success = false;
  70.  
  71.         for (int configSize = 0; configSize <= 20; configSize++) {
  72.             config = new OreFeatureConfig(config.target, config.state, configSize);
  73.  
  74.             oreGenLoop: // Yes a label. Sue me. :)
  75.             for (int i3 = 0; i3 < 1000; i3++) {
  76.                 float f = rand.nextFloat() * (float)Math.PI;
  77.                 float f1 = (float)config.size / 8.0F;
  78.                 int i = MathHelper.ceil(((float)config.size / 16.0F * 2.0F + 1.0F) / 2.0F);
  79.                 double d0 = (double)pos.getX() + Math.sin((double)f) * (double)f1;
  80.                 double d1 = (double)pos.getX() - Math.sin((double)f) * (double)f1;
  81.                 double d2 = (double)pos.getZ() + Math.cos((double)f) * (double)f1;
  82.                 double d3 = (double)pos.getZ() - Math.cos((double)f) * (double)f1;
  83.                 int j = 2;
  84.                 double d4 = (double)(pos.getY() + rand.nextInt(3) - 2);
  85.                 double d5 = (double)(pos.getY() + rand.nextInt(3) - 2);
  86.                 int k = pos.getX() - MathHelper.ceil(f1) - i;
  87.                 int l = pos.getY() - 2 - i;
  88.                 int i1 = pos.getZ() - MathHelper.ceil(f1) - i;
  89.                 int j1 = 2 * (MathHelper.ceil(f1) + i);
  90.                 int k1 = 2 * (2 + i);
  91.  
  92.                 for (int l1 = k; l1 <= k + j1; ++l1) {
  93.                     for (int i2 = i1; i2 <= i1 + j1; ++i2) {
  94.                         if (l <= reader.getHeight(Heightmap.Type.OCEAN_FLOOR_WG, l1, i2)) {
  95.                             success |= this.func_207803_a(reader, rand, config, d0, d1, d2, d3, d4, d5, k, l, i1, j1, k1);
  96.                             continue oreGenLoop;
  97.                         }
  98.                     }
  99.                 }
  100.  
  101.                 OreData.addOreVein(reader.getSeed(), config.size, 0);
  102.             }
  103.         }
  104.  
  105.         return success;
  106.     }
  107.  
  108.     protected boolean func_207803_a(IWorld worldIn, Random random, OreFeatureConfig config, double p_207803_4_, double p_207803_6_, double p_207803_8_, double p_207803_10_, double p_207803_12_, double p_207803_14_, int p_207803_16_, int p_207803_17_, int p_207803_18_, int p_207803_19_, int p_207803_20_) {
  109.         int i = 0;
  110.         BitSet bitset = new BitSet(p_207803_19_ * p_207803_20_ * p_207803_19_);
  111.         BlockPos.Mutable blockpos$mutable = new BlockPos.Mutable();
  112.         int j = config.size;
  113.         double[] adouble = new double[j * 4];
  114.  
  115.         for(int k = 0; k < j; ++k) {
  116.             float f = (float)k / (float)j;
  117.             double d0 = MathHelper.lerp((double)f, p_207803_4_, p_207803_6_);
  118.             double d2 = MathHelper.lerp((double)f, p_207803_12_, p_207803_14_);
  119.             double d4 = MathHelper.lerp((double)f, p_207803_8_, p_207803_10_);
  120.             double d6 = random.nextDouble() * (double)j / 16.0D;
  121.             double d7 = ((double)(MathHelper.sin((float)Math.PI * f) + 1.0F) * d6 + 1.0D) / 2.0D;
  122.             adouble[k * 4 + 0] = d0;
  123.             adouble[k * 4 + 1] = d2;
  124.             adouble[k * 4 + 2] = d4;
  125.             adouble[k * 4 + 3] = d7;
  126.         }
  127.  
  128.         for(int i3 = 0; i3 < j - 1; ++i3) {
  129.             if (!(adouble[i3 * 4 + 3] <= 0.0D)) {
  130.                 for(int k3 = i3 + 1; k3 < j; ++k3) {
  131.                     if (!(adouble[k3 * 4 + 3] <= 0.0D)) {
  132.                         double d12 = adouble[i3 * 4 + 0] - adouble[k3 * 4 + 0];
  133.                         double d13 = adouble[i3 * 4 + 1] - adouble[k3 * 4 + 1];
  134.                         double d14 = adouble[i3 * 4 + 2] - adouble[k3 * 4 + 2];
  135.                         double d15 = adouble[i3 * 4 + 3] - adouble[k3 * 4 + 3];
  136.                         if (d15 * d15 > d12 * d12 + d13 * d13 + d14 * d14) {
  137.                             if (d15 > 0.0D) {
  138.                                 adouble[k3 * 4 + 3] = -1.0D;
  139.                             } else {
  140.                                 adouble[i3 * 4 + 3] = -1.0D;
  141.                             }
  142.                         }
  143.                     }
  144.                 }
  145.             }
  146.         }
  147.  
  148.         for(int j3 = 0; j3 < j; ++j3) {
  149.             double d11 = adouble[j3 * 4 + 3];
  150.             if (!(d11 < 0.0D)) {
  151.                 double d1 = adouble[j3 * 4 + 0];
  152.                 double d3 = adouble[j3 * 4 + 1];
  153.                 double d5 = adouble[j3 * 4 + 2];
  154.                 int l = Math.max(MathHelper.floor(d1 - d11), p_207803_16_);
  155.                 int l3 = Math.max(MathHelper.floor(d3 - d11), p_207803_17_);
  156.                 int i1 = Math.max(MathHelper.floor(d5 - d11), p_207803_18_);
  157.                 int j1 = Math.max(MathHelper.floor(d1 + d11), l);
  158.                 int k1 = Math.max(MathHelper.floor(d3 + d11), l3);
  159.                 int l1 = Math.max(MathHelper.floor(d5 + d11), i1);
  160.  
  161.                 for(int i2 = l; i2 <= j1; ++i2) {
  162.                     double d8 = ((double)i2 + 0.5D - d1) / d11;
  163.                     if (d8 * d8 < 1.0D) {
  164.                         for(int j2 = l3; j2 <= k1; ++j2) {
  165.                             double d9 = ((double)j2 + 0.5D - d3) / d11;
  166.                             if (d8 * d8 + d9 * d9 < 1.0D) {
  167.                                 for(int k2 = i1; k2 <= l1; ++k2) {
  168.                                     double d10 = ((double)k2 + 0.5D - d5) / d11;
  169.                                     if (d8 * d8 + d9 * d9 + d10 * d10 < 1.0D) {
  170.                                         int l2 = i2 - p_207803_16_ + (j2 - p_207803_17_) * p_207803_19_ + (k2 - p_207803_18_) * p_207803_19_ * p_207803_20_;
  171.                                         if (!bitset.get(l2)) {
  172.                                             bitset.set(l2);
  173.                                             blockpos$mutable.setPos(i2, j2, k2);
  174.                                             if (config.target.test(worldIn.getBlockState(blockpos$mutable), random)) {
  175.                                                 //worldIn.setBlockState(blockpos$mutable, config.state, 2); Remove block placement as it's not necessary
  176.                                                 ++i;
  177.                                             }
  178.                                         }
  179.                                     }
  180.                                 }
  181.                             }
  182.                         }
  183.                     }
  184.                 }
  185.             }
  186.         }
  187.  
  188.         OreData.addOreVein(((ISeedReader)worldIn).getSeed(), config.size, i);
  189.  
  190.         return i > 0;
  191.     }
  192. }
  193.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement