Remove a load of soft errors in EditSession.

This commit is contained in:
dordsor21 2020-04-23 17:07:01 +01:00
parent c714e26f68
commit 29b82d4e51

View File

@ -180,7 +180,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
FAST("fast"), FAST("fast"),
NONE("none"); NONE("none");
private String displayName; private final String displayName;
ReorderMode(String displayName) { ReorderMode(String displayName) {
this.displayName = displayName; this.displayName = displayName;
@ -204,7 +204,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
private int changes = -1; private int changes = -1;
private final BlockBag blockBag; private final BlockBag blockBag;
private Extent bypassHistory; private final Extent bypassHistory;
private Extent bypassAll; private Extent bypassAll;
private final int maxY; private final int maxY;
@ -250,7 +250,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
/** /**
* The limit for this specific edit (blocks etc) * The limit for this specific edit (blocks etc)
* *
* @return * @return The limit
*/ */
public FaweLimit getLimit() { public FaweLimit getLimit() {
return originalLimit; return originalLimit;
@ -267,7 +267,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
/** /**
* Returns a new limit representing how much of this edit's limit has been used so far * Returns a new limit representing how much of this edit's limit has been used so far
* *
* @return * @return Limit remaining
*/ */
public FaweLimit getLimitUsed() { public FaweLimit getLimitUsed() {
FaweLimit newLimit = new FaweLimit(); FaweLimit newLimit = new FaweLimit();
@ -285,7 +285,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
/** /**
* Returns the remaining limits * Returns the remaining limits
* *
* @return * @return remaining limits
*/ */
public FaweLimit getLimitLeft() { public FaweLimit getLimitLeft() {
return limit; return limit;
@ -388,7 +388,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
/** /**
* Set the ChangeSet without hooking into any recording mechanism or triggering any actions.<br/> * Set the ChangeSet without hooking into any recording mechanism or triggering any actions.<br/>
* Used internally to set the ChangeSet during completion to record custom changes which aren't normally recorded * Used internally to set the ChangeSet during completion to record custom changes which aren't normally recorded
* @param set * @param set The ChangeSet to set
*/ */
public void setRawChangeSet(@Nullable AbstractChangeSet set) { public void setRawChangeSet(@Nullable AbstractChangeSet set) {
changeSet = set; changeSet = set;
@ -575,7 +575,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
/** /**
* Disable history (or re-enable) * Disable history (or re-enable)
* *
* @param disableHistory * @param disableHistory whether to enable or disable.
*/ */
@Deprecated @Deprecated
public void disableHistory(boolean disableHistory) { public void disableHistory(boolean disableHistory) {
@ -803,6 +803,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @return whether the block changed * @return whether the block changed
* @throws WorldEditException thrown on a set error * @throws WorldEditException thrown on a set error
*/ */
@Deprecated
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, Stage stage) throws WorldEditException { public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, Stage stage) throws WorldEditException {
if (position.getBlockY() < 0 || position.getBlockY() > 255) { if (position.getBlockY() < 0 || position.getBlockY() > 255) {
return false; return false;
@ -828,6 +829,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @param block the block * @param block the block
* @return whether the block changed * @return whether the block changed
*/ */
@Deprecated
public <B extends BlockStateHolder<B>> boolean rawSetBlock(BlockVector3 position, B block) { public <B extends BlockStateHolder<B>> boolean rawSetBlock(BlockVector3 position, B block) {
if (position.getBlockY() < 0 || position.getBlockY() > 255) { if (position.getBlockY() < 0 || position.getBlockY() > 255) {
return false; return false;
@ -861,7 +863,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
} }
} }
@Override @Override @Deprecated
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws MaxChangedBlocksException { public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws MaxChangedBlocksException {
if (position.getBlockY() < 0 || position.getBlockY() > 255) { if (position.getBlockY() < 0 || position.getBlockY() > 255) {
return false; return false;
@ -1028,7 +1030,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
((AbstractChangeSet) getChangeSet()).closeAsync(); ((AbstractChangeSet) getChangeSet()).closeAsync();
} else { } else {
try { try {
((AbstractChangeSet) getChangeSet()).close(); getChangeSet().close();
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -1041,9 +1043,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
final int startPerformY = region.getMinimumPoint().getBlockY(); final int startPerformY = region.getMinimumPoint().getBlockY();
final int startCheckY = fullHeight ? 0 : startPerformY; final int startCheckY = fullHeight ? 0 : startPerformY;
final int endY = region.getMaximumPoint().getBlockY(); final int endY = region.getMaximumPoint().getBlockY();
RegionVisitor visitor = new RegionVisitor(flat, new RegionFunction() { RegionVisitor visitor = new RegionVisitor(flat, pos -> {
@Override
public boolean apply(BlockVector3 pos) throws WorldEditException {
int x = pos.getX(); int x = pos.getX();
int z = pos.getZ(); int z = pos.getZ();
int freeSpot = startCheckY; int freeSpot = startCheckY;
@ -1064,7 +1064,6 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
} }
} }
return true; return true;
}
}); });
Operations.completeBlindly(visitor); Operations.completeBlindly(visitor);
return this.changes; return this.changes;
@ -1355,13 +1354,9 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
@Override @Override
public boolean test(Extent extent, BlockVector3 position) { public boolean test(Extent extent, BlockVector3 position) {
int x = position.getBlockX(); int x = position.getBlockX();
int y = position.getBlockY();
int z = position.getBlockZ(); int z = position.getBlockZ();
if (!region.contains(x, z + 1) || !region.contains(x, z - 1) || !region.contains(x + 1, z) || !region.contains(x - 1, z)) { return !region.contains(x, z + 1) || !region.contains(x, z - 1) || !region
return true; .contains(x + 1, z) || !region.contains(x - 1, z);
}
return false;
} }
}, pattern); }, pattern);
} }
@ -1696,8 +1691,6 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
} }
private int makeCylinder(BlockVector3 pos, Pattern block, double radiusX, double radiusZ, int height, double thickness, boolean filled) throws MaxChangedBlocksException { private int makeCylinder(BlockVector3 pos, Pattern block, double radiusX, double radiusZ, int height, double thickness, boolean filled) throws MaxChangedBlocksException {
int affected = 0;
radiusX += 0.5; radiusX += 0.5;
radiusZ += 0.5; radiusZ += 0.5;
@ -1934,8 +1927,6 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int makeSphere(BlockVector3 pos, Pattern block, double radiusX, double radiusY, double radiusZ, boolean filled) throws MaxChangedBlocksException { public int makeSphere(BlockVector3 pos, Pattern block, double radiusX, double radiusY, double radiusZ, boolean filled) throws MaxChangedBlocksException {
int affected = 0;
radiusX += 0.5; radiusX += 0.5;
radiusY += 0.5; radiusY += 0.5;
radiusZ += 0.5; radiusZ += 0.5;
@ -2094,7 +2085,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
} }
} }
return changes; return changes = affected;
} }
/** /**
@ -2161,7 +2152,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
} }
} }
return changes; return changes = affected;
} }
/** /**
@ -2175,11 +2166,9 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
*/ */
public int green(BlockVector3 position, double radius, boolean onlyNormalDirt) public int green(BlockVector3 position, double radius, boolean onlyNormalDirt)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
int affected = 0;
final double radiusSq = radius * radius; final double radiusSq = radius * radius;
final int ox = position.getBlockX(); final int ox = position.getBlockX();
final int oy = position.getBlockY();
final int oz = position.getBlockZ(); final int oz = position.getBlockZ();
final BlockState grass = BlockTypes.GRASS_BLOCK.getDefaultState(); final BlockState grass = BlockTypes.GRASS_BLOCK.getDefaultState();
@ -2305,8 +2294,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @param expressionString the expression defining the shape * @param expressionString the expression defining the shape
* @param hollow whether the shape should be hollow * @param hollow whether the shape should be hollow
* @return number of blocks changed * @return number of blocks changed
* @throws ExpressionException * @throws ExpressionException Thrown when there's a problem during any stage of the expression compilation or evaluation.
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException Thrown when the block limit has been reached
*/ */
public int makeShape(final Region region, final Vector3 zero, final Vector3 unit, public int makeShape(final Region region, final Vector3 zero, final Vector3 unit,
final Pattern pattern, final String expressionString, final boolean hollow) final Pattern pattern, final String expressionString, final boolean hollow)
@ -2325,8 +2314,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @param hollow whether the shape should be hollow * @param hollow whether the shape should be hollow
* @param timeout the time, in milliseconds, to wait for each expression evaluation before halting it. -1 to disable * @param timeout the time, in milliseconds, to wait for each expression evaluation before halting it. -1 to disable
* @return number of blocks changed * @return number of blocks changed
* @throws ExpressionException * @throws ExpressionException Thrown when there's a problem during any stage of the expression compilation or evaluation.
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException Thrown when the block limit has been reached
*/ */
public int makeShape(final Region region, final Vector3 zero, final Vector3 unit, public int makeShape(final Region region, final Vector3 zero, final Vector3 unit,
final Pattern pattern, final String expressionString, final boolean hollow, final int timeout) final Pattern pattern, final String expressionString, final boolean hollow, final int timeout)
@ -2411,7 +2400,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
final Vector3 zero2 = zero.add(0.5, 0.5, 0.5); final Vector3 zero2 = zero.add(0.5, 0.5, 0.5);
RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() { RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() {
private MutableBlockVector3 mutable = new MutableBlockVector3(); private final MutableBlockVector3 mutable = new MutableBlockVector3();
@Override @Override
public boolean apply(BlockVector3 position) throws WorldEditException { public boolean apply(BlockVector3 position) throws WorldEditException {