mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 03:16:41 +00:00
BaseBlock changes
- Changed up EditSession.replaceBlocks to make BaseBlock.inIterable unnecessary. - Returned BaseBlock.inIterable to its old state and deprecated it. - Renamed the old BaseBlock.equals to equalsFuzzy, changed the parameter type and took the casts and type checks out. - Made a new BaseBlock.equals that is consistent with the rules java prescribes.
This commit is contained in:
@ -1244,8 +1244,18 @@ public class EditSession {
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public int replaceBlocks(Region region, Set<BaseBlock> fromBlockTypes,
|
||||
BaseBlock toBlock) throws MaxChangedBlocksException {
|
||||
public int replaceBlocks(Region region, Set<BaseBlock> fromBlockTypes, BaseBlock toBlock) throws MaxChangedBlocksException {
|
||||
Set<BaseBlock> definiteBlockTypes = new HashSet<BaseBlock>();
|
||||
Set<Integer> fuzzyBlockTypes = new HashSet<Integer>();
|
||||
|
||||
for (BaseBlock block : fromBlockTypes) {
|
||||
if (block.getData() == -1) {
|
||||
fuzzyBlockTypes.add(block.getType());
|
||||
} else {
|
||||
definiteBlockTypes.add(block);
|
||||
}
|
||||
}
|
||||
|
||||
int affected = 0;
|
||||
|
||||
if (region instanceof CuboidRegion) {
|
||||
@ -1266,11 +1276,20 @@ public class EditSession {
|
||||
Vector pt = new Vector(x, y, z);
|
||||
BaseBlock curBlockType = getBlock(pt);
|
||||
|
||||
if ((fromBlockTypes == null && !curBlockType.isAir())
|
||||
|| (fromBlockTypes != null && curBlockType.inIterable(fromBlockTypes))) { // Probably faster if someone adds a proper hashCode to BaseBlock
|
||||
if (setBlock(pt, toBlock)) {
|
||||
++affected;
|
||||
if (definiteBlockTypes == null) {
|
||||
//replace <to-block>
|
||||
if (curBlockType.isAir()) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
//replace <from-block> <to-block>
|
||||
if (!definiteBlockTypes.contains(curBlockType) && fuzzyBlockTypes.contains(curBlockType.getType())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (setBlock(pt, toBlock)) {
|
||||
++affected;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1279,11 +1298,20 @@ public class EditSession {
|
||||
for (Vector pt : region) {
|
||||
BaseBlock curBlockType = getBlock(pt);
|
||||
|
||||
if (fromBlockTypes == null && !curBlockType.isAir()
|
||||
|| fromBlockTypes != null && curBlockType.inIterable(fromBlockTypes)) {
|
||||
if (setBlock(pt, toBlock)) {
|
||||
++affected;
|
||||
if (definiteBlockTypes == null) {
|
||||
//replace <to-block>
|
||||
if (curBlockType.isAir()) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
//replace <from-block> <to-block>
|
||||
if (!definiteBlockTypes.contains(curBlockType) && fuzzyBlockTypes.contains(curBlockType.getType())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (setBlock(pt, toBlock)) {
|
||||
++affected;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1300,8 +1328,18 @@ public class EditSession {
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException
|
||||
*/
|
||||
public int replaceBlocks(Region region, Set<BaseBlock> fromBlockTypes,
|
||||
Pattern pattern) throws MaxChangedBlocksException {
|
||||
public int replaceBlocks(Region region, Set<BaseBlock> fromBlockTypes, Pattern pattern) throws MaxChangedBlocksException {
|
||||
Set<BaseBlock> definiteBlockTypes = new HashSet<BaseBlock>();
|
||||
Set<Integer> fuzzyBlockTypes = new HashSet<Integer>();
|
||||
|
||||
for (BaseBlock block : fromBlockTypes) {
|
||||
if (block.getData() == -1) {
|
||||
fuzzyBlockTypes.add(block.getType());
|
||||
} else {
|
||||
definiteBlockTypes.add(block);
|
||||
}
|
||||
}
|
||||
|
||||
int affected = 0;
|
||||
|
||||
if (region instanceof CuboidRegion) {
|
||||
@ -1322,11 +1360,20 @@ public class EditSession {
|
||||
Vector pt = new Vector(x, y, z);
|
||||
BaseBlock curBlockType = getBlock(pt);
|
||||
|
||||
if ((fromBlockTypes == null && !curBlockType.isAir())
|
||||
|| (fromBlockTypes != null && curBlockType.inIterable(fromBlockTypes))) { // Probably faster if someone adds a proper hashCode to BaseBlock
|
||||
if (setBlock(pt, pattern.next(pt))) {
|
||||
++affected;
|
||||
if (definiteBlockTypes == null) {
|
||||
//replace <to-block>
|
||||
if (curBlockType.isAir()) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
//replace <from-block> <to-block>
|
||||
if (!definiteBlockTypes.contains(curBlockType) && fuzzyBlockTypes.contains(curBlockType.getType())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (setBlock(pt, pattern.next(pt))) {
|
||||
++affected;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1335,11 +1382,20 @@ public class EditSession {
|
||||
for (Vector pt : region) {
|
||||
BaseBlock curBlockType = getBlock(pt);
|
||||
|
||||
if (fromBlockTypes == null && !curBlockType.isAir()
|
||||
|| curBlockType.inIterable(fromBlockTypes)) {
|
||||
if (setBlock(pt, pattern.next(pt))) {
|
||||
++affected;
|
||||
if (definiteBlockTypes == null) {
|
||||
//replace <to-block>
|
||||
if (curBlockType.isAir()) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
//replace <from-block> <to-block>
|
||||
if (!definiteBlockTypes.contains(curBlockType) && fuzzyBlockTypes.contains(curBlockType.getType())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (setBlock(pt, pattern.next(pt))) {
|
||||
++affected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user