Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passed down tile for carve to avoid lock hits when grabbing the tile … #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import static java.util.Collections.singleton;
import static org.pepsoft.minecraft.Constants.*;
import static org.pepsoft.minecraft.Material.*;
import static org.pepsoft.worldpainter.Constants.TILE_SIZE;
import static org.pepsoft.worldpainter.Constants.TILE_SIZE_BITS;
import static org.pepsoft.worldpainter.Constants.*;
import static org.pepsoft.worldpainter.Constants.TILE_SIZE_MASK;
import static org.pepsoft.worldpainter.exporting.SecondPassLayerExporter.Stage.ADD_FEATURES;
import static org.pepsoft.worldpainter.exporting.SecondPassLayerExporter.Stage.CARVE;
import static org.pepsoft.worldpainter.util.GeometryUtil.visitFilledAbsoluteSphere;
Expand Down Expand Up @@ -82,7 +82,7 @@ public List<Fixup> carve(Rectangle area, Rectangle exportedArea, MinecraftWorld
if (cavesValue > random.nextInt(CAVE_CHANCE)) {
caveSettings.start = new Point3i(x, y, z);
caveSettings.length = MathUtils.clamp(0, (int) Math.round((random.nextGaussian() + 2.0) * (MAX_CAVE_LENGTH / 3.0)), MAX_CAVE_LENGTH);
createTunnel(minecraftWorld, area, exportedArea, dimension, new Random(random.nextLong()), caveSettings, surfaceBreaking, minimumLevel);
createTunnel(minecraftWorld, tile, area, exportedArea, dimension, new Random(random.nextLong()), caveSettings, surfaceBreaking, minimumLevel);
}
}
}
Expand All @@ -105,7 +105,7 @@ public List<Fixup> addFeatures(Rectangle area, Rectangle exportedArea, Minecraft
return null;
}

private void createTunnel(MinecraftWorld world, Rectangle area, Rectangle exportedArea, Dimension dimension, Random random, CaveSettings tunnelSettings, boolean surfaceBreaking, int minimumLevel) {
private void createTunnel(MinecraftWorld world, Tile tile, Rectangle area, Rectangle exportedArea, Dimension dimension, Random random, CaveSettings tunnelSettings, boolean surfaceBreaking, int minimumLevel) {
Point3d location = new Point3d(tunnelSettings.start.x + random.nextDouble() - 0.5, tunnelSettings.start.y + random.nextDouble() - 0.5, tunnelSettings.start.z + random.nextDouble() - 0.5);
Vector3d direction = getRandomDirection(random);
final float minRadius = tunnelSettings.minRadius, maxRadius = tunnelSettings.maxRadius,
Expand All @@ -125,7 +125,7 @@ private void createTunnel(MinecraftWorld world, Rectangle area, Rectangle export
}
if (((location.x + radius) >= exportedArea.x) && ((location.x - radius) <= (exportedArea.x + exportedArea.width))
&& ((location.y + radius) >= exportedArea.y) && ((location.y - radius) <= (exportedArea.y + exportedArea.height))) {
excavate(world, area, dimension, new Random((long) (segmentSeed + length)), tunnelSettings, location, radius, surfaceBreaking);
excavate(world, tile, area, dimension, new Random((long) (segmentSeed + length)), tunnelSettings, location, radius, surfaceBreaking);
}
length += direction.length();
location.add(direction);
Expand All @@ -140,7 +140,7 @@ private void createTunnel(MinecraftWorld world, Rectangle area, Rectangle export
}
}

private void excavate(MinecraftWorld world, Rectangle area, Dimension dimension, Random random, CaveSettings settings, Point3d location, double radius, boolean surfaceBreaking) {
private void excavate(MinecraftWorld world, Tile tile, Rectangle area, Dimension dimension, Random random, CaveSettings settings, Point3d location, double radius, boolean surfaceBreaking) {

// TODOMC13: remove water above openings

Expand All @@ -156,7 +156,7 @@ private void excavate(MinecraftWorld world, Rectangle area, Dimension dimension,
}
// TODO: efficiently check maxZ per x,y:
if (z >= minZ) {
final int terrainHeight = dimension.getIntHeightAt(x, y);
final int terrainHeight = tile.getIntHeight(x & TILE_SIZE_MASK, y & TILE_SIZE_MASK);
final int maxZ = terrainHeight - (surfaceBreaking ? 0 : dimension.getTopLayerDepth(x, y, terrainHeight));
if ((z > maxZ) || (x < area.x) || (x >= (area.x + area.width)) || (y < area.y) || (y >= (area.y + area.height))) {
return true;
Expand Down