Skip to content

Commit 2477534

Browse files
committed
Bring ores closer in line with vanilla generation
1 parent b2247fe commit 2477534

File tree

3 files changed

+327
-19
lines changed

3 files changed

+327
-19
lines changed

worldedit-core/src/main/java/com/fastasyncworldedit/core/function/generator/OreGen.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,38 @@ public class OreGen implements Resource {
2121
private final Extent extent;
2222
private final Mask mask;
2323
private final MutableBlockVector3 mutable = new MutableBlockVector3();
24+
private final boolean triangular;
2425

2526
private final double ONE_2 = 1 / 2F;
2627
private final double ONE_8 = 1 / 8F;
2728
private final double ONE_16 = 1 / 16F;
2829

2930
public OreGen(Extent extent, Mask mask, Pattern pattern, int size, int minY, int maxY) {
31+
this(extent, mask, pattern, size, minY, maxY, false);
32+
}
33+
34+
/**
35+
* Generate ore-like deposits with the given pattern and settings
36+
*
37+
* @param extent Extent to write to
38+
* @param mask mask of where to place
39+
* @param pattern pattern to place
40+
* @param size maximum size of deposits
41+
* @param minY min Y to consider generation from (important for triangular generation)
42+
* @param maxY max Y to consider generation from (important for triangular generation)
43+
* @param triangular if a triangular distribution of ores should be used (rather than
44+
* @throws WorldEditException on error
45+
* @since TODO
46+
*/
47+
public OreGen(
48+
Extent extent,
49+
Mask mask,
50+
Pattern pattern,
51+
int size,
52+
int minY,
53+
int maxY,
54+
boolean triangular
55+
) {
3056
this.maxSize = size;
3157
this.maxSizeO8 = size * ONE_8;
3258
this.maxSizeO16 = size * ONE_16;
@@ -36,11 +62,20 @@ public OreGen(Extent extent, Mask mask, Pattern pattern, int size, int minY, int
3662
this.mask = mask;
3763
this.pattern = pattern;
3864
this.extent = extent;
65+
this.triangular = triangular;
3966
}
4067

4168
@Override
4269
public boolean spawn(Random rand, int x, int z) throws WorldEditException {
43-
int y = rand.nextInt(maxY - minY) + minY;
70+
int y;
71+
if (this.triangular) {
72+
int range = maxY - minY;
73+
int mid = range / 2;
74+
int upperMid = range - mid;
75+
y = minY + rand.nextInt(mid) + rand.nextInt(upperMid);
76+
} else {
77+
y = rand.nextInt(maxY - minY) + minY;
78+
}
4479
if (!mask.test(mutable.setComponents(x, y, z))) {
4580
return false;
4681
}

worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,12 @@ public void ores(
622622
LocalSession session,
623623
EditSession editSession,
624624
@Selection Region region,
625-
@Arg(desc = "Mask") Mask mask
625+
@Arg(desc = "Mask") Mask mask,
626+
@Switch(name = 'b', desc = "Make all ores deepslate equivalent for y<0") boolean deepslateBelowZero,
627+
@Switch(name = 'd', desc = "Make all ores deepslate equivalent when placed into deepslate, tuff, etc.") boolean deepslateWhereDeepslate
626628
) throws WorldEditException {
627629
new MaskTraverser(mask).setNewExtent(editSession);
628-
editSession.addOres(region, mask);
630+
editSession.addOres(region, mask, deepslateBelowZero, deepslateWhereDeepslate);
629631
actor.print(Caption.of("fawe.worldedit.visitor.visitor.block", editSession.getBlockChangeCount()));
630632
}
631633

0 commit comments

Comments
 (0)