Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-19 13:00:06 +01:00
Provide a faster way to get a location. Adds BUKKIT-3120
Currently when a plugin wants to get the location of something it calls getLocation() which returns a new Location object. In some scenarios this can cause enough object creation/destruction churn to be a significant overhead. For this cases we add a method that updates a provided Location object so there is no object creation done. This allows well written code to work on several locations with only a single Location object getting created. Providing a more efficient way to set a location was also looked at but the current solution is the fastest we can provide. You are not required to create a new Location object every time you want to set something's location so, with proper design, you can set locations with only a single Location object being created.
Dieser Commit ist enthalten in:
Ursprung
c74fd4196f
Commit
846a22304c
@ -48,6 +48,19 @@ public class CraftBlock implements Block {
|
||||
return new Location(getWorld(), x, y, z);
|
||||
}
|
||||
|
||||
public Location getLocation(Location loc) {
|
||||
if (loc != null) {
|
||||
loc.setWorld(getWorld());
|
||||
loc.setX(x);
|
||||
loc.setY(y);
|
||||
loc.setZ(z);
|
||||
loc.setYaw(0);
|
||||
loc.setPitch(0);
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
public BlockVector getVector() {
|
||||
return new BlockVector(x, y, z);
|
||||
}
|
||||
|
@ -148,6 +148,19 @@ public class CraftBlockState implements BlockState {
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
public Location getLocation(Location loc) {
|
||||
if (loc != null) {
|
||||
loc.setWorld(world);
|
||||
loc.setX(x);
|
||||
loc.setY(y);
|
||||
loc.setZ(z);
|
||||
loc.setYaw(0);
|
||||
loc.setPitch(0);
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
public void setRawData(byte data) {
|
||||
this.data.setData(data);
|
||||
}
|
||||
|
@ -156,6 +156,19 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
return new Location(getWorld(), entity.locX, entity.locY, entity.locZ, entity.yaw, entity.pitch);
|
||||
}
|
||||
|
||||
public Location getLocation(Location loc) {
|
||||
if (loc != null) {
|
||||
loc.setWorld(getWorld());
|
||||
loc.setX(entity.locX);
|
||||
loc.setY(entity.locY);
|
||||
loc.setZ(entity.locZ);
|
||||
loc.setYaw(entity.yaw);
|
||||
loc.setPitch(entity.pitch);
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
public Vector getVelocity() {
|
||||
return new Vector(entity.motX, entity.motY, entity.motZ);
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren