-
-
Notifications
You must be signed in to change notification settings - Fork 204
/
OffsetPattern.java
68 lines (60 loc) · 2.23 KB
/
OffsetPattern.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
package com.fastasyncworldedit.core.function.pattern;
import com.fastasyncworldedit.core.math.MutableBlockVector3;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
public class OffsetPattern extends AbstractPattern {
private final int dx;
private final int dy;
private final int dz;
private final int minY;
private final int maxY;
private final transient MutableBlockVector3 mutable = new MutableBlockVector3();
private final Pattern pattern;
/**
* Create a new {@link Pattern} instance
*
* @param pattern pattern to apply
* @param dx offset x
* @param dy offset y
* @param dz offset z
* @param minY min applicable y (inclusive
* @param maxY max applicable y (inclusive
*/
public OffsetPattern(Pattern pattern, int dx, int dy, int dz, int minY, int maxY) {
this.dx = dx;
this.dy = dy;
this.dz = dz;
this.minY = minY;
this.maxY = maxY;
this.pattern = pattern;
}
@Override
public BaseBlock applyBlock(BlockVector3 position) {
mutable.mutX(position.getX() + dx);
mutable.mutY(position.getY() + dy);
mutable.mutZ(position.getZ() + dz);
if (mutable.getY() < minY || mutable.getY() > maxY) {
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
return pattern.applyBlock(mutable);
}
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
mutable.mutX(get.getX() + dx);
mutable.mutY(get.getY() + dy);
mutable.mutZ(get.getZ() + dz);
if (mutable.getY() < extent.getMinY() || mutable.getY() > extent.getMaxY()) {
return false;
}
return pattern.apply(extent, get, mutable);
}
@Override
public Pattern fork() {
return new OffsetPattern(this.pattern.fork(), this.dx, this.dy, this.dz, this.minY, this.maxY);
}
}