Skip to content

Commit

Permalink
Adds mineshaft support for ancient versions of Minecraft
Browse files Browse the repository at this point in the history
(v1.3.2 all the way back to when mineshafts were first introduced)
  • Loading branch information
Treer committed Jul 24, 2015
1 parent 5021258 commit 9ebb54d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
62 changes: 39 additions & 23 deletions src/amidst/map/layers/MineshaftLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ public class MineshaftLayer extends IconLayer {
private final static double chancePerChunk_v1_7 = 0.004D;
private final static double chancePerChunk_v1_6 = 0.01D;

private Random random = new Random();
private double chancePerChunk;
private Random random = new Random();
private double chancePerChunk;
private boolean useOriginalAlogirithm = false;

public MineshaftLayer() {

if (MinecraftUtil.getVersion().isAtLeast(VersionInfo.V1_7_2)) {
// Mineshafts became less common from version 1.7.2 onward
chancePerChunk = chancePerChunk_v1_7;
if (MinecraftUtil.getVersion().isAtLeast(VersionInfo.V1_4_2)) {
// Use the current mineshaft algorithm

if (MinecraftUtil.getVersion().isAtLeast(VersionInfo.V1_7_2)) {
// Mineshafts became less common from version 1.7.2 onward
chancePerChunk = chancePerChunk_v1_7;
} else {
chancePerChunk = chancePerChunk_v1_6;
}
} else {
chancePerChunk = chancePerChunk_v1_6;
}
// Use the original mineshaft algorithm (retired in v1.4.2).
useOriginalAlogirithm = true;
}
}

@Override
Expand All @@ -33,26 +41,18 @@ public boolean isVisible() {
@Override
public void generateMapObjects(Fragment frag) {

if (MinecraftVersionIsSupported()) {

int size = Fragment.SIZE >> 4;
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
int chunkX = x + frag.getChunkX();
int chunkY = y + frag.getChunkY();
if (checkChunk(chunkX, chunkY)) {
frag.addObject(new MapObjectMineshaft((x << 4) + 8, (y << 4) + 8).setParent(this));
}
int size = Fragment.SIZE >> 4;
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
int chunkX = x + frag.getChunkX();
int chunkY = y + frag.getChunkY();
if (checkChunk(chunkX, chunkY)) {
frag.addObject(new MapObjectMineshaft((x << 4) + 8, (y << 4) + 8).setParent(this));
}
}
}
}

/** @return true if Minecraft is v1.4.2 or greater (earlier versions place mineshafts differently) */
public static boolean MinecraftVersionIsSupported() {
return MinecraftUtil.getVersion().isAtLeast(VersionInfo.V1_4_2);
}

public boolean checkChunk(int chunkX, int chunkY) {
random.setSeed(Options.instance.seed);
long var7 = random.nextLong();
Expand All @@ -63,6 +63,22 @@ public boolean checkChunk(int chunkX, int chunkY) {
random.setSeed(var13 ^ var15 ^ Options.instance.seed);
random.nextInt();

return (random.nextDouble() < chancePerChunk) && random.nextInt(80) < Math.max(Math.abs(chunkX), Math.abs(chunkY));
if (useOriginalAlogirithm) {
// Empirical testing suggests this version of the algorithm works all the way back to b1.8,
// and the Minecraft Wiki says b1.8 was when mineshafts were introduced, but since Amidst
// versions only go back as far as VersionInfo.Vbeta_1_8_1 I won't bother to check for
// pre-mineshaft versions.
//
// I've not decompiled the very early Minecraft versions, and TheMasterCaver points out that "for older
// versions it is possible that the second part of this code, nextInt(80) < (max of absolute value
// of chunk coordinates), may not have been present, resulting in mineshafts being equally as common
// near the origin as they currently are 80 or more chunks away."
// I've included TheMasterCaver's comment because my empirical testing that Amidst mineshafts do
// appear in the game can't tell us whether the very early versions have fewer mineshafts near the origin.
return (random.nextInt(100) == 0) && (random.nextInt(80) < Math.max(Math.abs(chunkX), Math.abs(chunkY)));
} else {
// As of v1.4.2 Minecraft switched to this version of the algorithm
return (random.nextDouble() < chancePerChunk) && random.nextInt(80) < Math.max(Math.abs(chunkX), Math.abs(chunkY));
}
}
}
2 changes: 1 addition & 1 deletion src/amidst/version/VersionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public enum VersionInfo {
V1_9pre3("to"),
V1_9pre2("sv"),
V1_9pre1("sq"),
Vbeta_1_8_1("[Bhwqpyrrviqswdbzdqurkhqrgviwbomnabjrxmafvoeacfer[J[Jaddmkbb"); // Had to rename from V1_8_1 - should it just be removed?
Vbeta_1_8_1("[Bhwqpyrrviqswdbzdqurkhqrgviwbomnabjrxmafvoeacfer[J[Jaddmkbb"); // Includes b1.8 (had to rename this enum from V1_8_1)

public final String versionId;

Expand Down

0 comments on commit 9ebb54d

Please sign in to comment.