geforkt von Mirrors/Paper
[Bleeding] Optimized locToBlock. Addresses BUKKIT-815
By: Wesley Wolfe <weswolf@aol.com>
Dieser Commit ist enthalten in:
Ursprung
43002d0cbb
Commit
fa6a95bc3f
@ -1,6 +1,7 @@
|
||||
package org.bukkit;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
@ -485,6 +486,6 @@ public class Location implements Cloneable {
|
||||
* @return Block coordinate
|
||||
*/
|
||||
public static int locToBlock(double loc) {
|
||||
return (int) Math.floor(loc);
|
||||
return NumberConversions.floor(loc);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.bukkit.util;
|
||||
|
||||
import static org.bukkit.util.NumberConversions.*;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
@ -66,7 +68,7 @@ public class BlockIterator implements Iterator<Block> {
|
||||
double secondPosition = 0;
|
||||
double thirdPosition = 0;
|
||||
|
||||
Block startBlock = this.world.getBlockAt((int) Math.floor(startClone.getX()), (int) Math.floor(startClone.getY()), (int) Math.floor(startClone.getZ()));
|
||||
Block startBlock = this.world.getBlockAt(floor(startClone.getX()), floor(startClone.getY()), floor(startClone.getZ()));
|
||||
|
||||
if (getXLength(direction) > mainDirection) {
|
||||
mainFace = getXFace(direction);
|
||||
@ -117,10 +119,10 @@ public class BlockIterator implements Iterator<Block> {
|
||||
// Guarantee that the ray will pass though the start block.
|
||||
// It is possible that it would miss due to rounding
|
||||
// This should only move the ray by 1 grid position
|
||||
secondError = (int) (Math.floor(secondd * gridSize));
|
||||
secondStep = (int) (Math.round(secondDirection / mainDirection * gridSize));
|
||||
thirdError = (int) (Math.floor(thirdd * gridSize));
|
||||
thirdStep = (int) (Math.round(thirdDirection / mainDirection * gridSize));
|
||||
secondError = floor(secondd * gridSize);
|
||||
secondStep = round(secondDirection / mainDirection * gridSize);
|
||||
thirdError = floor(thirdd * gridSize);
|
||||
thirdStep = round(thirdDirection / mainDirection * gridSize);
|
||||
|
||||
if (secondError + secondStep <= 0) {
|
||||
secondError = -secondStep + 1;
|
||||
@ -168,7 +170,7 @@ public class BlockIterator implements Iterator<Block> {
|
||||
}
|
||||
|
||||
// Calculate the number of planes passed to give max distance
|
||||
maxDistanceInt = (int) Math.round(maxDistance / (Math.sqrt(mainDirection * mainDirection + secondDirection * secondDirection + thirdDirection * thirdDirection) / mainDirection));
|
||||
maxDistanceInt = round(maxDistance / (Math.sqrt(mainDirection * mainDirection + secondDirection * secondDirection + thirdDirection * thirdDirection) / mainDirection));
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,15 @@ package org.bukkit.util;
|
||||
public final class NumberConversions {
|
||||
private NumberConversions() {}
|
||||
|
||||
public static int floor(double num) {
|
||||
final int floor = (int) num;
|
||||
return floor == num ? floor : floor - (int) (Double.doubleToRawLongBits(num) >>> 63);
|
||||
}
|
||||
|
||||
public static int round(double num) {
|
||||
return floor(num + 0.5d);
|
||||
}
|
||||
|
||||
public static int toInt(Object object) {
|
||||
if (object instanceof Number) {
|
||||
return ((Number) object).intValue();
|
||||
|
@ -365,7 +365,7 @@ public class Vector implements Cloneable, ConfigurationSerializable {
|
||||
* @return block X
|
||||
*/
|
||||
public int getBlockX() {
|
||||
return (int) Math.floor(x);
|
||||
return NumberConversions.floor(x);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -384,7 +384,7 @@ public class Vector implements Cloneable, ConfigurationSerializable {
|
||||
* @return block y
|
||||
*/
|
||||
public int getBlockY() {
|
||||
return (int) Math.floor(y);
|
||||
return NumberConversions.floor(y);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -403,7 +403,7 @@ public class Vector implements Cloneable, ConfigurationSerializable {
|
||||
* @return block z
|
||||
*/
|
||||
public int getBlockZ() {
|
||||
return (int) Math.floor(z);
|
||||
return NumberConversions.floor(z);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren