java - Why does this method not return whether the area is bigger than the parameter cubed? -
i'm working on minecraft plugin protect area. have area class created after player selects 3 blocks, , area class has method named "toobig
", used detecting if area bigger if "block^3
". problem method returns false
.
public boolean toobig(int i) { boolean bo1, bo2, bo3; bo1 = math.abs(b1.getx() - b2.getx()) > i; bo2 = math.abs(b1.getz() - b2.getz()) > i; bo3 = math.abs(b1.gety() - b3.gety()) > i; homecoming bo1 && bo2 && bo3; }
b1
, b2
, , b3
block
objects.
your utilize of variables inconsistent.
public boolean toobig(int i) { boolean bo1, bo2, bo3; bo1 = math.abs(b1.getx() - b2.getx()) > i; bo2 = math.abs(b1.getz() - b2.getz()) > i; bo3 = math.abs(b1.gety() - b3.gety()) > i; homecoming bo1 && bo2 && bo3; }
your algorithm wrong altogether. formula of calculating volume of rectangular cuboid region is
base (length * width) * height
where length, width , height of cuboid the distance maximum point through axis minimum point instead of randomly 2 points subtracting. right code getting area be:
public boolean toobig(int i) { int minx = math.min(math.min(b1.getblockx(), b2.getblockx()), b3.getblockx()); int maxx = math.max(math.max(b1.getblockx(), b2.getblockx()), b3.getblockx()); int miny = math.min(math.min(b1.getblocky(), b2.getblocky()), b3.getblocky()); int maxy = math.max(math.max(b1.getblocky(), b2.getblocky()), b3.getblocky()); int minz = math.min(math.min(b1.getblockz(), b2.getblockz()), b3.getblockz()); int maxz = math.max(math.max(b1.getblockz(), b2.getblockz()), b3.getblockz()); int area = (maxx - minx) * (maxy - miny) * (maxy - miny); }
to create work:
return area > math.pow(i, 3);
see also:
block.getblockx()
java minecraft bukkit
No comments:
Post a Comment