Skip to content

Commit af743bb

Browse files
authored
fix: don't bypass history with //ores (#3258)
* fix: don't bypass history with //ores - also add copper and update limits - also restrict ores spawning to region - also fix caves out of region error - fixes #3108 * Bring ores closer in line with vanilla generation * Add nullable annotation * fix javadoc
1 parent 4c8b9d5 commit af743bb

File tree

7 files changed

+343
-33
lines changed

7 files changed

+343
-33
lines changed

worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/FaweRegionExtent.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@
2626

2727
public abstract class FaweRegionExtent extends ResettableExtent implements IBatchProcessor {
2828

29+
@Nullable
2930
private final FaweLimit limit;
31+
private final boolean hasLimit;
3032

3133
/**
3234
* Create a new instance.
3335
*
3436
* @param extent the extent
3537
*/
36-
public FaweRegionExtent(Extent extent, FaweLimit limit) {
38+
public FaweRegionExtent(Extent extent, @Nullable FaweLimit limit) {
3739
super(extent);
3840
this.limit = limit;
41+
this.hasLimit = limit != null;
3942
}
4043

4144
@Override
@@ -75,7 +78,7 @@ public final boolean contains(BlockVector2 p) {
7578
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block)
7679
throws WorldEditException {
7780
if (!contains(x, y, z)) {
78-
if (!limit.MAX_FAILS()) {
81+
if (hasLimit && !limit.MAX_FAILS()) {
7982
WEManager.weManager().cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
8083
}
8184
return false;
@@ -86,7 +89,7 @@ public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B b
8689
@Override
8790
public boolean setBiome(int x, int y, int z, BiomeType biome) {
8891
if (!contains(x, y, z)) {
89-
if (!limit.MAX_FAILS()) {
92+
if (hasLimit && !limit.MAX_FAILS()) {
9093
WEManager.weManager().cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
9194
}
9295
return false;
@@ -102,7 +105,7 @@ public BiomeType getBiome(BlockVector3 position) {
102105
@Override
103106
public BiomeType getBiomeType(int x, int y, int z) {
104107
if (!contains(x, y, z)) {
105-
if (!limit.MAX_FAILS()) {
108+
if (hasLimit && !limit.MAX_FAILS()) {
106109
WEManager.weManager().cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
107110
}
108111
return null;
@@ -118,7 +121,7 @@ public BaseBlock getFullBlock(BlockVector3 position) {
118121
@Override
119122
public BaseBlock getFullBlock(int x, int y, int z) {
120123
if (!contains(x, y, z)) {
121-
if (!limit.MAX_FAILS()) {
124+
if (hasLimit && !limit.MAX_FAILS()) {
122125
WEManager.weManager().cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
123126
}
124127
return BlockTypes.AIR.getDefaultState().toBaseBlock();
@@ -134,7 +137,7 @@ public BlockState getBlock(BlockVector3 position) {
134137
@Override
135138
public BlockState getBlock(int x, int y, int z) {
136139
if (!contains(x, y, z)) {
137-
if (!limit.MAX_FAILS()) {
140+
if (hasLimit && !limit.MAX_FAILS()) {
138141
WEManager.weManager().cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
139142
}
140143
return BlockTypes.AIR.getDefaultState();
@@ -146,7 +149,7 @@ public BlockState getBlock(int x, int y, int z) {
146149
@Override
147150
public Entity createEntity(Location location, BaseEntity entity) {
148151
if (!contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
149-
if (!limit.MAX_FAILS()) {
152+
if (hasLimit && !limit.MAX_FAILS()) {
150153
WEManager.weManager().cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
151154
}
152155
return null;
@@ -158,7 +161,7 @@ public Entity createEntity(Location location, BaseEntity entity) {
158161
@Override
159162
public Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
160163
if (!contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
161-
if (!limit.MAX_FAILS()) {
164+
if (hasLimit && !limit.MAX_FAILS()) {
162165
WEManager.weManager().cancelEditSafe(this, FaweCache.OUTSIDE_REGION);
163166
}
164167
return null;

worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/PassthroughExtent.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ public void addOre(Region region, Mask mask, Pattern material, int size, int fre
126126
getExtent().addOre(region, mask, material, size, frequency, rarity, minY, maxY);
127127
}
128128

129-
@Override
130-
public void addOres(Region region, Mask mask) throws WorldEditException {
131-
getExtent().addOres(region, mask);
132-
}
133-
134129
@Override
135130
public List<Countable<BlockType>> getBlockDistribution(Region region) {
136131
return getExtent().getBlockDistribution(region);

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 flat)
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/EditSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4119,7 +4119,7 @@ public void removeEntity(int x, int y, int z, UUID uuid) {
41194119
@Override
41204120
public void generate(Region region, GenBase gen) throws WorldEditException {
41214121
for (BlockVector2 chunkPos : region.getChunks()) {
4122-
gen.generate(chunkPos, new SingleRegionExtent(this, getLimit(), region));
4122+
gen.generate(chunkPos, new SingleRegionExtent(this, null, region));
41234123
}
41244124
}
41254125

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
@@ -671,10 +671,12 @@ public void ores(
671671
LocalSession session,
672672
EditSession editSession,
673673
@Selection Region region,
674-
@Arg(desc = "Mask") Mask mask
674+
@Arg(desc = "Mask") Mask mask,
675+
@Switch(name = 'b', desc = "Make all ores deepslate equivalent for y<0") boolean deepslateBelowZero,
676+
@Switch(name = 'd', desc = "Make all ores deepslate equivalent when placed into deepslate, tuff, etc.") boolean deepslateWhereDeepslate
675677
) throws WorldEditException {
676678
new MaskTraverser(mask).setNewExtent(editSession);
677-
editSession.addOres(region, mask);
679+
editSession.addOres(region, mask, deepslateBelowZero, deepslateWhereDeepslate);
678680
actor.print(Caption.of("fawe.worldedit.visitor.visitor.block", editSession.getBlockChangeCount()));
679681
}
680682

0 commit comments

Comments
 (0)