-
-
Notifications
You must be signed in to change notification settings - Fork 204
/
TransformExtent.java
120 lines (102 loc) · 3.83 KB
/
TransformExtent.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.fastasyncworldedit.core.extent;
import com.fastasyncworldedit.core.math.MutableBlockVector3;
import com.fastasyncworldedit.core.math.MutableVector3;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
/**
* @deprecated Unused internal, will be removed in v3
*/
@Deprecated(forRemoval = true, since = "TODO")
public class TransformExtent extends BlockTransformExtent {
private final MutableVector3 mutable1 = new MutableVector3();
private final MutableBlockVector3 mutable2 = new MutableBlockVector3();
private BlockVector3 min;
public TransformExtent(Extent parent) {
super(parent);
}
@Override
public ResettableExtent setExtent(Extent extent) {
min = null;
return super.setExtent(extent);
}
@Override
public BlockVector3 getMinimumPoint() {
BlockVector3 pos1 = getPos(super.getMinimumPoint());
BlockVector3 pos2 = getPos(super.getMaximumPoint());
return pos1.getMinimum(pos2);
}
@Override
public BlockVector3 getMaximumPoint() {
BlockVector3 pos1 = getPos(super.getMinimumPoint());
BlockVector3 pos2 = getPos(super.getMaximumPoint());
return pos1.getMaximum(pos2);
}
@Override
public void setOrigin(BlockVector3 pos) {
this.min = pos;
}
public BlockVector3 getPos(BlockVector3 pos) {
if (min == null) {
min = pos;
}
mutable1.mutX(pos.getX() - min.getX());
mutable1.mutY(pos.getY() - min.getY());
mutable1.mutZ(pos.getZ() - min.getZ());
Vector3 tmp = getTransform().apply(mutable1);
mutable2.mutX(tmp.getX() + min.getX());
mutable2.mutY(tmp.getY() + min.getY());
mutable2.mutZ(tmp.getZ() + min.getZ());
return mutable2;
}
public BlockVector3 getPos(int x, int y, int z) {
if (min == null) {
min = BlockVector3.at(x, y, z);
}
mutable1.mutX(x - min.getX());
mutable1.mutY(y - min.getY());
mutable1.mutZ(z - min.getZ());
Vector3 tmp = getTransform().apply(mutable1);
mutable2.mutX(tmp.getX() + min.getX());
mutable2.mutY(tmp.getY() + min.getY());
mutable2.mutZ(tmp.getZ() + min.getZ());
return tmp.toBlockPoint();
}
@Override
public BlockState getBlock(int x, int y, int z) {
BlockVector3 p = getPos(x, y, z);
return transform(super.getBlock(p.getX(), p.getY(), p.getZ()));
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
return transform(super.getFullBlock(getPos(position)));
}
@Override
public BiomeType getBiomeType(int x, int y, int z) {
BlockVector3 p = getPos(x, y, z);
return super.getBiomeType(p.getX(), y, p.getZ());
}
@Override
@SuppressWarnings("unchecked")
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block)
throws WorldEditException {
return super.setBlock(getPos(x, y, z), transformInverse(block));
}
@Override
@SuppressWarnings("unchecked")
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block)
throws WorldEditException {
return super.setBlock(getPos(location), transformInverse(block));
}
@Override
public boolean setBiome(int x, int y, int z, BiomeType biome) {
BlockVector3 p = getPos(x, y, z);
return super.setBiome(p.getX(), p.getY(), p.getZ(), biome);
}
}