appease codacy

This commit is contained in:
Brady 2023-06-07 17:38:26 -05:00
parent 0d14bde583
commit 34abbfb5da
No known key found for this signature in database
GPG Key ID: 73A788379A197567
3 changed files with 30 additions and 22 deletions

View File

@ -24,27 +24,30 @@ import net.minecraft.block.state.IBlockState;
*/ */
public class CylinderSchematic extends MaskSchematic { public class CylinderSchematic extends MaskSchematic {
private final double cx, cz, rx, rz; private final double centerX;
private final double centerZ;
private final double radiusSqX;
private final double radiusSqZ;
private final boolean filled; private final boolean filled;
public CylinderSchematic(ISchematic schematic, boolean filled) { public CylinderSchematic(ISchematic schematic, boolean filled) {
super(schematic); super(schematic);
this.cx = schematic.widthX() / 2.0; this.centerX = schematic.widthX() / 2.0;
this.cz = schematic.lengthZ() / 2.0; this.centerZ = schematic.lengthZ() / 2.0;
this.rx = this.cx * this.cx; this.radiusSqX = this.centerX * this.centerX;
this.rz = this.cz * this.cz; this.radiusSqZ = this.centerZ * this.centerZ;
this.filled = filled; this.filled = filled;
} }
@Override @Override
protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { protected boolean partOfMask(int x, int y, int z, IBlockState currentState) {
double dx = Math.abs((x + 0.5) - this.cx); double dx = Math.abs((x + 0.5) - this.centerX);
double dz = Math.abs((z + 0.5) - this.cz); double dz = Math.abs((z + 0.5) - this.centerZ);
return !this.outside(dx, dz) return !this.outside(dx, dz)
&& (this.filled || outside(dx + 1, dz) || outside(dx, dz + 1)); && (this.filled || outside(dx + 1, dz) || outside(dx, dz + 1));
} }
private boolean outside(double dx, double dz) { private boolean outside(double dx, double dz) {
return dx * dx / this.rx + dz * dz / this.rz > 1; return dx * dx / this.radiusSqX + dz * dz / this.radiusSqZ > 1;
} }
} }

View File

@ -18,37 +18,41 @@
package baritone.api.schematic; package baritone.api.schematic;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.Vec3d;
/** /**
* @author Brady * @author Brady
*/ */
public class SphereSchematic extends MaskSchematic { public class SphereSchematic extends MaskSchematic {
private final double cx, cy, cz, rx, ry, rz; private final double centerX;
private final double centerY;
private final double centerZ;
private final double radiusSqX;
private final double radiusSqY;
private final double radiusSqZ;
private final boolean filled; private final boolean filled;
public SphereSchematic(ISchematic schematic, boolean filled) { public SphereSchematic(ISchematic schematic, boolean filled) {
super(schematic); super(schematic);
this.cx = schematic.widthX() / 2.0; this.centerX = schematic.widthX() / 2.0;
this.cy = schematic.heightY() / 2.0; this.centerY = schematic.heightY() / 2.0;
this.cz = schematic.lengthZ() / 2.0; this.centerZ = schematic.lengthZ() / 2.0;
this.rx = this.cx * this.cx; this.radiusSqX = this.centerX * this.centerX;
this.ry = this.cy * this.cy; this.radiusSqY = this.centerY * this.centerY;
this.rz = this.cz * this.cz; this.radiusSqZ = this.centerZ * this.centerZ;
this.filled = filled; this.filled = filled;
} }
@Override @Override
protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { protected boolean partOfMask(int x, int y, int z, IBlockState currentState) {
double dx = Math.abs((x + 0.5) - this.cx); double dx = Math.abs((x + 0.5) - this.centerX);
double dy = Math.abs((y + 0.5) - this.cy); double dy = Math.abs((y + 0.5) - this.centerY);
double dz = Math.abs((z + 0.5) - this.cz); double dz = Math.abs((z + 0.5) - this.centerZ);
return !this.outside(dx, dy, dz) return !this.outside(dx, dy, dz)
&& (this.filled || outside(dx + 1, dy, dz) || outside(dx, dy + 1, dz) || outside(dx, dy, dz + 1)); && (this.filled || outside(dx + 1, dy, dz) || outside(dx, dy + 1, dz) || outside(dx, dy, dz + 1));
} }
private boolean outside(double dx,double dy, double dz) { private boolean outside(double dx,double dy, double dz) {
return dx * dx / this.rx + dy * dy / this.ry + dz * dz / this.rz > 1; return dx * dx / this.radiusSqX + dy * dy / this.radiusSqY + dz * dz / this.radiusSqZ > 1;
} }
} }

View File

@ -388,9 +388,10 @@ public class SelCommand extends Command {
return new CylinderSchematic(fill, true); return new CylinderSchematic(fill, true);
case HCYLINDER: case HCYLINDER:
return new CylinderSchematic(fill, false); return new CylinderSchematic(fill, false);
default:
// Silent fail
return fill;
} }
// Silent fail
return fill;
} }
} }