mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Small optimizations
This commit is contained in:
parent
3a18ca9d16
commit
4c95d52bd0
3 changed files with 36 additions and 15 deletions
|
@ -824,21 +824,28 @@ public class VehicleComponent<T extends LivingEntity & ClientVehicle> {
|
||||||
|
|
||||||
protected class VehicleContext {
|
protected class VehicleContext {
|
||||||
private Vector3d centerPos;
|
private Vector3d centerPos;
|
||||||
|
private Vector3d cachePos;
|
||||||
private BlockState centerBlock;
|
private BlockState centerBlock;
|
||||||
private Vector3i supportingBlockPos;
|
private Vector3i supportingBlockPos;
|
||||||
private BlockPositionIterator blockIter;
|
private BlockPositionIterator blockIter;
|
||||||
private int[] blocks;
|
private int[] blocks;
|
||||||
|
|
||||||
protected void loadSurroundingBlocks() {
|
protected void loadSurroundingBlocks() {
|
||||||
BoundingBox box = boundingBox.clone();
|
|
||||||
box.expand(2);
|
|
||||||
|
|
||||||
Vector3i min = box.getMin().toInt();
|
|
||||||
Vector3i max = box.getMax().toInt();
|
|
||||||
this.blockIter = BlockPositionIterator.fromMinMax(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ());
|
|
||||||
this.blocks = vehicle.getSession().getGeyser().getWorldManager().getBlocksAt(vehicle.getSession(), this.blockIter);
|
|
||||||
|
|
||||||
this.centerPos = boundingBox.getBottomCenter();
|
this.centerPos = boundingBox.getBottomCenter();
|
||||||
|
|
||||||
|
// Reuse block cache if vehicle moved less than 1 block
|
||||||
|
if (this.cachePos == null || this.cachePos.distanceSquared(this.centerPos) > 1) {
|
||||||
|
BoundingBox box = boundingBox.clone();
|
||||||
|
box.expand(2);
|
||||||
|
|
||||||
|
Vector3i min = box.getMin().toInt();
|
||||||
|
Vector3i max = box.getMax().toInt();
|
||||||
|
this.blockIter = BlockPositionIterator.fromMinMax(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ());
|
||||||
|
this.blocks = vehicle.getSession().getGeyser().getWorldManager().getBlocksAt(vehicle.getSession(), this.blockIter);
|
||||||
|
|
||||||
|
this.cachePos = this.centerPos;
|
||||||
|
}
|
||||||
|
|
||||||
this.centerBlock = getBlock(this.centerPos.toInt());
|
this.centerBlock = getBlock(this.centerPos.toInt());
|
||||||
this.supportingBlockPos = null;
|
this.supportingBlockPos = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,14 @@ public class BoundingBox implements Cloneable {
|
||||||
return Vector3d.from(x, y, z);
|
return Vector3d.from(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getMin(Axis axis) {
|
||||||
|
return switch (axis) {
|
||||||
|
case X -> middleX - sizeX / 2;
|
||||||
|
case Y -> middleY - sizeY / 2;
|
||||||
|
case Z -> middleZ - sizeZ / 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public Vector3d getMax() {
|
public Vector3d getMax() {
|
||||||
double x = middleX + sizeX / 2;
|
double x = middleX + sizeX / 2;
|
||||||
double y = middleY + sizeY / 2;
|
double y = middleY + sizeY / 2;
|
||||||
|
@ -101,6 +109,14 @@ public class BoundingBox implements Cloneable {
|
||||||
return Vector3d.from(x, y, z);
|
return Vector3d.from(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getMax(Axis axis) {
|
||||||
|
return switch (axis) {
|
||||||
|
case X -> middleX + sizeX / 2;
|
||||||
|
case Y -> middleY + sizeY / 2;
|
||||||
|
case Z -> middleZ + sizeZ / 2;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public Vector3d getBottomCenter() {
|
public Vector3d getBottomCenter() {
|
||||||
return Vector3d.from(middleX, middleY - sizeY / 2, middleZ);
|
return Vector3d.from(middleX, middleY - sizeY / 2, middleZ);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.geysermc.geyser.entity.EntityDefinitions;
|
import org.geysermc.geyser.entity.EntityDefinitions;
|
||||||
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
||||||
|
import org.geysermc.geyser.level.physics.Axis;
|
||||||
import org.geysermc.geyser.level.physics.BoundingBox;
|
import org.geysermc.geyser.level.physics.BoundingBox;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
|
|
||||||
|
@ -202,14 +203,11 @@ public class WorldBorder {
|
||||||
* @return the corrected movement
|
* @return the corrected movement
|
||||||
*/
|
*/
|
||||||
public Vector3d correctMovement(BoundingBox boundingBox, Vector3d movement) {
|
public Vector3d correctMovement(BoundingBox boundingBox, Vector3d movement) {
|
||||||
Vector3d bbMin = boundingBox.getMin();
|
|
||||||
Vector3d bbMax = boundingBox.getMax();
|
|
||||||
|
|
||||||
double correctedX;
|
double correctedX;
|
||||||
if (movement.getX() < 0) {
|
if (movement.getX() < 0) {
|
||||||
correctedX = -limitMovement(-movement.getX(), bbMin.getX() - GenericMath.floor(minX));
|
correctedX = -limitMovement(-movement.getX(), boundingBox.getMin(Axis.X) - GenericMath.floor(minX));
|
||||||
} else {
|
} else {
|
||||||
correctedX = limitMovement(movement.getX(), GenericMath.ceil(maxX) - bbMax.getX());
|
correctedX = limitMovement(movement.getX(), GenericMath.ceil(maxX) - boundingBox.getMax(Axis.X));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outside of border, don't adjust movement
|
// Outside of border, don't adjust movement
|
||||||
|
@ -219,9 +217,9 @@ public class WorldBorder {
|
||||||
|
|
||||||
double correctedZ;
|
double correctedZ;
|
||||||
if (movement.getZ() < 0) {
|
if (movement.getZ() < 0) {
|
||||||
correctedZ = -limitMovement(-movement.getZ(), bbMin.getZ() - GenericMath.floor(minZ));
|
correctedZ = -limitMovement(-movement.getZ(), boundingBox.getMin(Axis.Z) - GenericMath.floor(minZ));
|
||||||
} else {
|
} else {
|
||||||
correctedZ = limitMovement(movement.getZ(), GenericMath.ceil(maxZ) - bbMax.getZ());
|
correctedZ = limitMovement(movement.getZ(), GenericMath.ceil(maxZ) - boundingBox.getMax(Axis.Z));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Double.isNaN(correctedZ)) {
|
if (Double.isNaN(correctedZ)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue