Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class OreTest extends Feature<OreFeatureConfig> {
- public OreTest(Codec<OreFeatureConfig> codec) {
- super(codec);
- }
- public static final class OreData {
- private static final HashSet<Long> seeds = new HashSet<Long>(); // Record set of all seeds test generated in for result set
- 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
- 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
- private static final HashMap<Integer, HashMap<Integer, Long>> veinSizeCounts = new HashMap<Integer, HashMap<Integer, Long>>(); // Count veins of all sizes per config size given
- private static void addOreVein(long seed, int veinConfigSize, int veinSize) {
- HashMap<Integer, Long> veinSizeCounter = veinSizeCounts.getOrDefault(veinConfigSize, new HashMap<Integer, Long>());
- Tuple<Integer, Integer> veinCounterData = oreVeins.get(veinConfigSize);
- Tuple<Long, Long> veinCountData = veinCount.getOrDefault(veinConfigSize, new Tuple<Long, Long>(0L, 0L));
- veinSizeCounter.put(veinSize, veinSizeCounter.get(veinSize) != null ? veinSizeCounter.get(veinSize) + 1 : 1);
- veinSizeCounts.put(veinConfigSize, veinSizeCounter);
- seeds.add(seed);
- long veinsTotal = veinCountData.getA() + 1;
- long totalOresTracked = veinCountData.getB() + veinSize;
- veinCount.put(veinConfigSize, new Tuple<Long, Long>(veinsTotal, totalOresTracked));
- int minVeinSize = Math.min(veinCounterData.getA(), veinSize);
- int maxVeinSize = Math.max(veinCounterData.getB(), veinSize);
- oreVeins.set(veinConfigSize, new Tuple<Integer, Integer>(minVeinSize, maxVeinSize));
- }
- public static void doResultsPrintout() {
- System.out.println("Printing out ore vein generation results");
- System.out.println("--~~--~~--");
- System.out.println();
- System.out.println("Counted veins from " + seeds.size() + " seeds total.");
- System.out.println("~~");
- System.out.println("Printed out:");
- veinCount.forEach((configSize, veinsCounted) -> {
- System.out.println(" " + veinsCounted.getA() + " total veins for input 'size' value of " + configSize);
- });
- System.out.println();
- System.out.println(" For config 'size' values: ");
- veinSizeCounts.forEach((configSize, veinSizesMap) -> {
- System.out.println(" " + configSize + " - Found: ");
- Tuple<Integer, Integer> minMaxSizes = oreVeins.get(configSize);
- Tuple<Long, Long> veinCountData = veinCount.get(configSize);
- double avg = veinCountData.getB() / (double)veinCountData.getA();
- avg = ((int)(avg * 1000) / 1000d); // Round to 3 significant digits
- System.out.println(" Min ores in vein: " + minMaxSizes.getA() + ". Max ores in vein: " + minMaxSizes.getB() + " (" + avg + " avg ores per generation attempt.)");
- veinSizesMap.forEach((veinSize, numVeins) -> {
- System.out.println(" " + numVeins + " veins with " + veinSize + " ores.");
- });
- });
- System.out.println();
- System.out.println("~~");
- }
- }
- public boolean generate(ISeedReader reader, ChunkGenerator generator, Random rand, BlockPos pos, OreFeatureConfig config) {
- boolean success = false;
- for (int configSize = 0; configSize <= 20; configSize++) {
- config = new OreFeatureConfig(config.target, config.state, configSize);
- oreGenLoop: // Yes a label. Sue me. :)
- for (int i3 = 0; i3 < 1000; i3++) {
- float f = rand.nextFloat() * (float)Math.PI;
- float f1 = (float)config.size / 8.0F;
- int i = MathHelper.ceil(((float)config.size / 16.0F * 2.0F + 1.0F) / 2.0F);
- double d0 = (double)pos.getX() + Math.sin((double)f) * (double)f1;
- double d1 = (double)pos.getX() - Math.sin((double)f) * (double)f1;
- double d2 = (double)pos.getZ() + Math.cos((double)f) * (double)f1;
- double d3 = (double)pos.getZ() - Math.cos((double)f) * (double)f1;
- int j = 2;
- double d4 = (double)(pos.getY() + rand.nextInt(3) - 2);
- double d5 = (double)(pos.getY() + rand.nextInt(3) - 2);
- int k = pos.getX() - MathHelper.ceil(f1) - i;
- int l = pos.getY() - 2 - i;
- int i1 = pos.getZ() - MathHelper.ceil(f1) - i;
- int j1 = 2 * (MathHelper.ceil(f1) + i);
- int k1 = 2 * (2 + i);
- for (int l1 = k; l1 <= k + j1; ++l1) {
- for (int i2 = i1; i2 <= i1 + j1; ++i2) {
- if (l <= reader.getHeight(Heightmap.Type.OCEAN_FLOOR_WG, l1, i2)) {
- success |= this.func_207803_a(reader, rand, config, d0, d1, d2, d3, d4, d5, k, l, i1, j1, k1);
- continue oreGenLoop;
- }
- }
- }
- OreData.addOreVein(reader.getSeed(), config.size, 0);
- }
- }
- return success;
- }
- 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_) {
- int i = 0;
- BitSet bitset = new BitSet(p_207803_19_ * p_207803_20_ * p_207803_19_);
- BlockPos.Mutable blockpos$mutable = new BlockPos.Mutable();
- int j = config.size;
- double[] adouble = new double[j * 4];
- for(int k = 0; k < j; ++k) {
- float f = (float)k / (float)j;
- double d0 = MathHelper.lerp((double)f, p_207803_4_, p_207803_6_);
- double d2 = MathHelper.lerp((double)f, p_207803_12_, p_207803_14_);
- double d4 = MathHelper.lerp((double)f, p_207803_8_, p_207803_10_);
- double d6 = random.nextDouble() * (double)j / 16.0D;
- double d7 = ((double)(MathHelper.sin((float)Math.PI * f) + 1.0F) * d6 + 1.0D) / 2.0D;
- adouble[k * 4 + 0] = d0;
- adouble[k * 4 + 1] = d2;
- adouble[k * 4 + 2] = d4;
- adouble[k * 4 + 3] = d7;
- }
- for(int i3 = 0; i3 < j - 1; ++i3) {
- if (!(adouble[i3 * 4 + 3] <= 0.0D)) {
- for(int k3 = i3 + 1; k3 < j; ++k3) {
- if (!(adouble[k3 * 4 + 3] <= 0.0D)) {
- double d12 = adouble[i3 * 4 + 0] - adouble[k3 * 4 + 0];
- double d13 = adouble[i3 * 4 + 1] - adouble[k3 * 4 + 1];
- double d14 = adouble[i3 * 4 + 2] - adouble[k3 * 4 + 2];
- double d15 = adouble[i3 * 4 + 3] - adouble[k3 * 4 + 3];
- if (d15 * d15 > d12 * d12 + d13 * d13 + d14 * d14) {
- if (d15 > 0.0D) {
- adouble[k3 * 4 + 3] = -1.0D;
- } else {
- adouble[i3 * 4 + 3] = -1.0D;
- }
- }
- }
- }
- }
- }
- for(int j3 = 0; j3 < j; ++j3) {
- double d11 = adouble[j3 * 4 + 3];
- if (!(d11 < 0.0D)) {
- double d1 = adouble[j3 * 4 + 0];
- double d3 = adouble[j3 * 4 + 1];
- double d5 = adouble[j3 * 4 + 2];
- int l = Math.max(MathHelper.floor(d1 - d11), p_207803_16_);
- int l3 = Math.max(MathHelper.floor(d3 - d11), p_207803_17_);
- int i1 = Math.max(MathHelper.floor(d5 - d11), p_207803_18_);
- int j1 = Math.max(MathHelper.floor(d1 + d11), l);
- int k1 = Math.max(MathHelper.floor(d3 + d11), l3);
- int l1 = Math.max(MathHelper.floor(d5 + d11), i1);
- for(int i2 = l; i2 <= j1; ++i2) {
- double d8 = ((double)i2 + 0.5D - d1) / d11;
- if (d8 * d8 < 1.0D) {
- for(int j2 = l3; j2 <= k1; ++j2) {
- double d9 = ((double)j2 + 0.5D - d3) / d11;
- if (d8 * d8 + d9 * d9 < 1.0D) {
- for(int k2 = i1; k2 <= l1; ++k2) {
- double d10 = ((double)k2 + 0.5D - d5) / d11;
- if (d8 * d8 + d9 * d9 + d10 * d10 < 1.0D) {
- int l2 = i2 - p_207803_16_ + (j2 - p_207803_17_) * p_207803_19_ + (k2 - p_207803_18_) * p_207803_19_ * p_207803_20_;
- if (!bitset.get(l2)) {
- bitset.set(l2);
- blockpos$mutable.setPos(i2, j2, k2);
- if (config.target.test(worldIn.getBlockState(blockpos$mutable), random)) {
- //worldIn.setBlockState(blockpos$mutable, config.state, 2); Remove block placement as it's not necessary
- ++i;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- OreData.addOreVein(((ISeedReader)worldIn).getSeed(), config.size, i);
- return i > 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement