Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-25 15:50:14 +01:00
Chunk cache improvements (#2053)
- Check for minimum and maximum Y values to fix stack traces - Don't run half of the villager sleeping code unless they're actually sleeping
Dieser Commit ist enthalten in:
Ursprung
10c77a3214
Commit
86397ef483
@ -96,7 +96,6 @@ public class FishingHookEntity extends ThrowableEntity {
|
||||
boolean touchingWater = false;
|
||||
boolean collided = false;
|
||||
for (Vector3i blockPos : collidableBlocks) {
|
||||
if (0 <= blockPos.getY() && blockPos.getY() <= 255) {
|
||||
int blockID = session.getConnector().getWorldManager().getBlockAt(session, blockPos);
|
||||
BlockCollision blockCollision = CollisionTranslator.getCollision(blockID, blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
||||
if (blockCollision != null && blockCollision.checkIntersection(boundingBox)) {
|
||||
@ -119,7 +118,6 @@ public class FishingHookEntity extends ThrowableEntity {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!inWater && touchingWater) {
|
||||
sendSplashSound(session);
|
||||
@ -177,11 +175,9 @@ public class FishingHookEntity extends ThrowableEntity {
|
||||
*/
|
||||
protected boolean isInAir(GeyserSession session) {
|
||||
if (session.getConnector().getConfig().isCacheChunks()) {
|
||||
if (0 <= position.getFloorY() && position.getFloorY() <= 255) {
|
||||
int block = session.getConnector().getWorldManager().getBlockAt(session, position.toInt());
|
||||
return block == BlockTranslator.JAVA_AIR_ID;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@
|
||||
package org.geysermc.connector.entity.living.merchant;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.VillagerData;
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
@ -101,11 +100,17 @@ public class VillagerEntity extends AbstractMerchantEntity {
|
||||
|
||||
@Override
|
||||
public void moveRelative(GeyserSession session, double relX, double relY, double relZ, Vector3f rotation, boolean isOnGround) {
|
||||
if (!metadata.getFlags().getFlag(EntityFlag.SLEEPING)) {
|
||||
// No need to worry about extra processing to compensate for sleeping
|
||||
super.moveRelative(session, relX, relY, relZ, rotation, isOnGround);
|
||||
return;
|
||||
}
|
||||
|
||||
int z = 0;
|
||||
int bedId = 0;
|
||||
float bedPositionSubtractorW = 0;
|
||||
float bedPositionSubtractorN = 0;
|
||||
Vector3i bedPosition = metadata.getPos(EntityData.BED_POSITION);
|
||||
Vector3i bedPosition = metadata.getPos(EntityData.BED_POSITION, null);
|
||||
if (session.getConnector().getConfig().isCacheChunks() && bedPosition != null) {
|
||||
bedId = session.getConnector().getWorldManager().getBlockAt(session, bedPosition);
|
||||
}
|
||||
@ -117,11 +122,6 @@ public class VillagerEntity extends AbstractMerchantEntity {
|
||||
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
||||
moveEntityPacket.setRuntimeEntityId(geyserId);
|
||||
//Sets Villager position and rotation when sleeping
|
||||
if (!metadata.getFlags().getFlag(EntityFlag.SLEEPING)) {
|
||||
moveEntityPacket.setPosition(position);
|
||||
moveEntityPacket.setRotation(getBedrockRotation());
|
||||
} else {
|
||||
//String Setup
|
||||
Pattern r = Pattern.compile("facing=([a-z]+)");
|
||||
Matcher m = r.matcher(bedRotationZ);
|
||||
if (m.find()) {
|
||||
@ -149,7 +149,6 @@ public class VillagerEntity extends AbstractMerchantEntity {
|
||||
}
|
||||
moveEntityPacket.setRotation(Vector3f.from(0, 0, z));
|
||||
moveEntityPacket.setPosition(Vector3f.from(position.getX() + bedPositionSubtractorW, position.getY(), position.getZ() + bedPositionSubtractorN));
|
||||
}
|
||||
moveEntityPacket.setOnGround(isOnGround);
|
||||
moveEntityPacket.setTeleported(false);
|
||||
session.sendUpstreamPacket(moveEntityPacket);
|
||||
|
@ -34,6 +34,7 @@ import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||
import org.geysermc.connector.utils.MathUtils;
|
||||
|
||||
public class ChunkCache {
|
||||
private static final int MINIMUM_WORLD_HEIGHT = 0;
|
||||
|
||||
private final boolean cache;
|
||||
|
||||
@ -86,6 +87,11 @@ public class ChunkCache {
|
||||
return;
|
||||
}
|
||||
|
||||
if (y < MINIMUM_WORLD_HEIGHT || (y >> 4) > column.getChunks().length - 1) {
|
||||
// Y likely goes above or below the height limit of this world
|
||||
return;
|
||||
}
|
||||
|
||||
Chunk chunk = column.getChunks()[y >> 4];
|
||||
if (chunk != null) {
|
||||
chunk.set(x & 0xF, y & 0xF, z & 0xF, block);
|
||||
@ -102,6 +108,11 @@ public class ChunkCache {
|
||||
return BlockTranslator.JAVA_AIR_ID;
|
||||
}
|
||||
|
||||
if (y < MINIMUM_WORLD_HEIGHT || (y >> 4) > column.getChunks().length - 1) {
|
||||
// Y likely goes above or below the height limit of this world
|
||||
return BlockTranslator.JAVA_AIR_ID;
|
||||
}
|
||||
|
||||
Chunk chunk = column.getChunks()[y >> 4];
|
||||
if (chunk != null) {
|
||||
return chunk.get(x & 0xF, y & 0xF, z & 0xF);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren