-
-
Notifications
You must be signed in to change notification settings - Fork 204
/
HeightBrush.java
94 lines (83 loc) · 3.29 KB
/
HeightBrush.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.fastasyncworldedit.core.command.tool.brush;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.internal.exception.FaweException;
import com.fastasyncworldedit.core.math.heightmap.HeightMap;
import com.fastasyncworldedit.core.math.heightmap.RotatableHeightMap;
import com.fastasyncworldedit.core.math.heightmap.ScalableHeightMap;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ThreadLocalRandom;
public class HeightBrush implements Brush {
private HeightMap heightMap;
private boolean randomRotate;
public final int rotation;
public final double yscale;
public final boolean layers;
public final boolean smooth;
public HeightBrush(
InputStream stream, int rotation, double yscale, boolean layers, boolean smooth, Clipboard clipboard,
int minY, int maxY
) {
this(stream, rotation, yscale, layers, smooth, clipboard, ScalableHeightMap.Shape.CONE, minY, maxY);
}
public HeightBrush(
InputStream stream,
int rotation,
double yscale,
boolean layers,
boolean smooth,
Clipboard clipboard,
ScalableHeightMap.Shape shape,
int minY,
int maxY
) {
this.rotation = (rotation / 90) % 4;
this.yscale = yscale;
this.layers = layers;
this.smooth = smooth;
if (stream != null) {
try {
heightMap = ScalableHeightMap.fromPNG(stream);
} catch (IOException e) {
throw new FaweException(Caption.of("fawe.worldedit.brush.brush.height.invalid", e.getMessage()));
}
} else if (clipboard != null) {
heightMap = ScalableHeightMap.fromClipboard(clipboard, minY, maxY);
} else {
heightMap = ScalableHeightMap.fromShape(shape);
}
}
public HeightMap getHeightMap() {
if (randomRotate) {
if (!(heightMap instanceof RotatableHeightMap)) {
heightMap = new RotatableHeightMap(heightMap);
}
RotatableHeightMap rotatable = (RotatableHeightMap) heightMap;
rotatable.rotate(ThreadLocalRandom.current().nextInt(360));
}
return heightMap;
}
public void setRandomRotate(boolean randomRotate) {
this.randomRotate = randomRotate;
}
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double sizeDouble) throws
MaxChangedBlocksException {
int size = (int) sizeDouble;
HeightMap map = getHeightMap();
map.setSize(size);
Mask mask = editSession.getMask();
if (mask == Masks.alwaysTrue() || mask == Masks.alwaysTrue2D()) {
mask = null;
}
map.perform(editSession, mask, position, size, rotation, yscale, smooth, false, layers);
}
}