Skip to content

Commit 6294692

Browse files
author
david
committed
recovered original functionality
1 parent 55f33fe commit 6294692

File tree

2 files changed

+59
-21
lines changed

2 files changed

+59
-21
lines changed

src/main/java/net/onelitefeather/bettergopaint/objects/brush/FractureBrush.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ public void paint(
4646
) {
4747
performEdit(player, session -> {
4848
Stream<Block> blocks = Sphere.getBlocksInRadius(location, brushSettings.size(), null, false);
49-
blocks.filter(block -> passesDefaultChecks(brushSettings, player, block))
49+
blocks.filter(block -> passesMaskCheck(brushSettings, block))
5050
.filter(block -> Height.getAverageHeightDiffFracture(
5151
block.getLocation(),
52-
Height.getHeight(block.getLocation()),
52+
Height.getNearestNonEmptyBlock(block.getLocation()),
5353
1
5454
) >= 0.1)
5555
.filter(block -> Height.getAverageHeightDiffFracture(
5656
block.getLocation(),
57-
Height.getHeight(block.getLocation()),
57+
Height.getNearestNonEmptyBlock(block.getLocation()),
5858
brushSettings.fractureDistance()
5959
) >= 0.1)
6060
.forEach(block -> setBlock(session, block, brushSettings.randomBlock()));

src/main/java/net/onelitefeather/bettergopaint/utils/Height.java

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,88 @@
1919
package net.onelitefeather.bettergopaint.utils;
2020

2121
import org.bukkit.Location;
22+
import org.bukkit.block.Block;
2223
import org.jetbrains.annotations.NotNull;
2324

2425
public class Height {
2526

26-
public static int getHeight(@NotNull Location location) {
27-
return location.getWorld().getHighestBlockYAt(location);
27+
/**
28+
* Gets the height of the nearest non-empty block at a given location.
29+
*
30+
* @param location the location to check
31+
* @return the height of the nearest non-empty block at the location
32+
*/
33+
public static int getNearestNonEmptyBlock(@NotNull Location location) {
34+
if (location.getBlock().getType().isEmpty()) {
35+
for (int y = location.getBlockY(); y >= location.getWorld().getMinHeight(); y--) {
36+
Block block = location.getWorld().getBlockAt(location.getBlockX(), y, location.getBlockZ());
37+
if (!block.isEmpty()) {
38+
return y + 1;
39+
}
40+
}
41+
return location.getWorld().getMinHeight();
42+
} else {
43+
for (int y = location.getBlockY(); y <= location.getWorld().getMaxHeight(); y++) {
44+
Block block = location.getWorld().getBlockAt(location.getBlockX(), y, location.getBlockZ());
45+
if (block.isEmpty()) {
46+
return y;
47+
}
48+
}
49+
return location.getWorld().getMaxHeight();
50+
}
2851
}
2952

53+
/**
54+
* Calculates the average height difference of the surrounding blocks from a given location, within a specified distance.
55+
*
56+
* @param location the location to calculate the average height difference from
57+
* @param height the reference height of the nearest non-empty block
58+
* @param distance the distance at which to calculate the average height difference
59+
* @return the average height difference of the surrounding blocks within the specified distance
60+
*/
3061
public static double getAverageHeightDiffFracture(@NotNull Location location, int height, int distance) {
3162
double totalHeight = 0;
32-
totalHeight += Math.abs(getHeight(location.clone().add(distance, 0, -distance))) - height;
33-
totalHeight += Math.abs(getHeight(location.clone().add(distance, 0, distance))) - height;
34-
totalHeight += Math.abs(getHeight(location.clone().add(-distance, 0, distance))) - height;
35-
totalHeight += Math.abs(getHeight(location.clone().add(-distance, 0, -distance))) - height;
36-
totalHeight += Math.abs(getHeight(location.clone().add(0, 0, -distance))) - height;
37-
totalHeight += Math.abs(getHeight(location.clone().add(0, 0, distance))) - height;
38-
totalHeight += Math.abs(getHeight(location.clone().add(-distance, 0, 0))) - height;
39-
totalHeight += Math.abs(getHeight(location.clone().add(distance, 0, 0))) - height;
63+
totalHeight += Math.abs(getNearestNonEmptyBlock(location.clone().add(distance, 0, -distance))) - height;
64+
totalHeight += Math.abs(getNearestNonEmptyBlock(location.clone().add(distance, 0, distance))) - height;
65+
totalHeight += Math.abs(getNearestNonEmptyBlock(location.clone().add(-distance, 0, distance))) - height;
66+
totalHeight += Math.abs(getNearestNonEmptyBlock(location.clone().add(-distance, 0, -distance))) - height;
67+
totalHeight += Math.abs(getNearestNonEmptyBlock(location.clone().add(0, 0, -distance))) - height;
68+
totalHeight += Math.abs(getNearestNonEmptyBlock(location.clone().add(0, 0, distance))) - height;
69+
totalHeight += Math.abs(getNearestNonEmptyBlock(location.clone().add(-distance, 0, 0))) - height;
70+
totalHeight += Math.abs(getNearestNonEmptyBlock(location.clone().add(distance, 0, 0))) - height;
4071
return (totalHeight / 8d) / distance;
4172
}
4273

74+
/**
75+
* Calculates the average height difference angle of the surrounding blocks from a given location within a specified distance.
76+
*
77+
* @param location the location to calculate the average height difference angle from
78+
* @param distance the distance at which to calculate the average height difference angle
79+
* @return the average height difference angle of the surrounding blocks within the specified distance
80+
*/
4381
public static double getAverageHeightDiffAngle(@NotNull Location location, int distance) {
4482
double maxHeightDiff = 0;
4583
double maxHeightDiff2 = 0;
46-
double diff = Math.abs(getHeight(location.clone().add(distance, 0, -distance)) - getHeight(location.clone()
47-
.add(-distance, 0, distance)));
84+
double diff = Math.abs(getNearestNonEmptyBlock(location.clone().add(distance, 0, -distance))
85+
- getNearestNonEmptyBlock(location.clone().add(-distance, 0, distance)));
4886
if (diff >= maxHeightDiff) {
4987
maxHeightDiff = diff;
5088
maxHeightDiff2 = maxHeightDiff;
5189
}
52-
diff = Math.abs(getHeight(location.clone().add(distance, 0, distance)) - getHeight(location.clone()
53-
.add(-distance, 0, -distance)));
90+
diff = Math.abs(getNearestNonEmptyBlock(location.clone().add(distance, 0, distance))
91+
- getNearestNonEmptyBlock(location.clone().add(-distance, 0, -distance)));
5492
if (diff > maxHeightDiff) {
5593
maxHeightDiff = diff;
5694
maxHeightDiff2 = maxHeightDiff;
5795
}
58-
diff = Math.abs(getHeight(location.clone().add(distance, 0, 0)) - getHeight(location.clone()
59-
.add(-distance, 0, 0)));
96+
diff = Math.abs(getNearestNonEmptyBlock(location.clone().add(distance, 0, 0))
97+
- getNearestNonEmptyBlock(location.clone().add(-distance, 0, 0)));
6098
if (diff > maxHeightDiff) {
6199
maxHeightDiff = diff;
62100
maxHeightDiff2 = maxHeightDiff;
63101
}
64-
diff = Math.abs(getHeight(location.clone().add(0, 0, -distance)) - getHeight(location.clone()
65-
.add(0, 0, distance)));
102+
diff = Math.abs(getNearestNonEmptyBlock(location.clone().add(0, 0, -distance))
103+
- getNearestNonEmptyBlock(location.clone().add(0, 0, distance)));
66104
if (diff > maxHeightDiff) {
67105
maxHeightDiff = diff;
68106
maxHeightDiff2 = maxHeightDiff;

0 commit comments

Comments
 (0)