Created
September 6, 2020 14:10
-
-
Save PG85/a8e9231cbe04311b09f2c3bc809e01ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected BlockPos findNearestStructurePosBySpacing(World worldIn, BlockPos startPos, int distanceStep, int stepOffset, int randomSeedZ, boolean addExtraRandomness, int maxAttempts, boolean findUnexplored) | |
{ | |
int i = startPos.getX() >> 4; | |
int j = startPos.getZ() >> 4; | |
int k = 0; | |
for (Random random = new Random(); k <= maxAttempts; ++k) | |
{ | |
for (int l = -k; l <= k; ++l) | |
{ | |
boolean flag = l == -k || l == k; | |
for (int i1 = -k; i1 <= k; ++i1) | |
{ | |
boolean flag1 = i1 == -k || i1 == k; | |
if (flag || flag1) | |
{ | |
int j1 = i + distanceStep * l; | |
int k1 = j + distanceStep * i1; | |
if (j1 < 0) | |
{ | |
j1 -= distanceStep - 1; | |
} | |
if (k1 < 0) | |
{ | |
k1 -= distanceStep - 1; | |
} | |
int l1 = j1 / distanceStep; | |
int i2 = k1 / distanceStep; | |
Random random1 = worldIn.setRandomSeed(l1, i2, randomSeedZ); | |
l1 = l1 * distanceStep; | |
i2 = i2 * distanceStep; | |
if (addExtraRandomness) | |
{ | |
l1 = l1 + (random1.nextInt(distanceStep - stepOffset) + random1.nextInt(distanceStep - stepOffset)) / 2; | |
i2 = i2 + (random1.nextInt(distanceStep - stepOffset) + random1.nextInt(distanceStep - stepOffset)) / 2; | |
} | |
else | |
{ | |
l1 = l1 + random1.nextInt(distanceStep - stepOffset); | |
i2 = i2 + random1.nextInt(distanceStep - stepOffset); | |
} | |
MapGenBase.setupChunkSeed(worldIn.getSeed(), random, l1, i2); | |
random.nextInt(); | |
if (canSpawnStructureAtCoords(l1, i2)) | |
{ | |
if (!findUnexplored || !worldIn.isChunkGeneratedAt(l1, i2)) | |
{ | |
return new BlockPos((l1 << 4) + 8, 64, (i2 << 4) + 8); | |
} | |
} | |
else if (k == 0) | |
{ | |
break; | |
} | |
} | |
} | |
if (k == 0) | |
{ | |
break; | |
} | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment