3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-10-05 09:20:07 +02:00

Ensure more entity tasks are run on the player session

Dieser Commit ist enthalten in:
Camotoy 2021-08-21 09:54:52 -04:00
Ursprung 85404f0ed5
Commit ab540b1951
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
3 geänderte Dateien mit 36 neuen und 43 gelöschten Zeilen

Datei anzeigen

@ -27,24 +27,19 @@ package org.geysermc.connector.entity;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.AddPaintingPacket; import com.nukkitx.protocol.bedrock.packet.AddPaintingPacket;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.PaintingType; import org.geysermc.connector.utils.PaintingType;
@Getter @Setter
@Accessors(chain = true)
public class PaintingEntity extends Entity { public class PaintingEntity extends Entity {
private static final double OFFSET = -0.46875; private static final double OFFSET = -0.46875;
private PaintingType paintingName; private final PaintingType paintingName;
private int direction; private final int direction;
public PaintingEntity(long entityId, long geyserId, Vector3f position) { public PaintingEntity(long entityId, long geyserId, Vector3f position, PaintingType paintingName, int direction) {
super(entityId, geyserId, EntityType.PAINTING, position, Vector3f.ZERO, Vector3f.ZERO); super(entityId, geyserId, EntityType.PAINTING, position, Vector3f.ZERO, Vector3f.ZERO);
this.paintingName = paintingName;
this.direction = direction;
} }
@Override @Override
@ -53,7 +48,7 @@ public class PaintingEntity extends Entity {
addPaintingPacket.setUniqueEntityId(geyserId); addPaintingPacket.setUniqueEntityId(geyserId);
addPaintingPacket.setRuntimeEntityId(geyserId); addPaintingPacket.setRuntimeEntityId(geyserId);
addPaintingPacket.setMotive(paintingName.getBedrockName()); addPaintingPacket.setMotive(paintingName.getBedrockName());
addPaintingPacket.setPosition(fixOffset(true)); addPaintingPacket.setPosition(fixOffset());
addPaintingPacket.setDirection(direction); addPaintingPacket.setDirection(direction);
session.sendUpstreamPacket(addPaintingPacket); session.sendUpstreamPacket(addPaintingPacket);
@ -67,8 +62,7 @@ public class PaintingEntity extends Entity {
// Do nothing, as head look messes up paintings // Do nothing, as head look messes up paintings
} }
public Vector3f fixOffset(boolean toBedrock) { private Vector3f fixOffset() {
if (toBedrock) {
Vector3f position = super.position; Vector3f position = super.position;
position = position.add(0.5, 0.5, 0.5); position = position.add(0.5, 0.5, 0.5);
double widthOffset = paintingName.getWidth() > 1 ? 0.5 : 0; double widthOffset = paintingName.getWidth() > 1 ? 0.5 : 0;
@ -80,7 +74,6 @@ public class PaintingEntity extends Entity {
case 2: return position.add(-widthOffset, heightOffset, -OFFSET); case 2: return position.add(-widthOffset, heightOffset, -OFFSET);
case 3: return position.add(OFFSET, heightOffset, -widthOffset); case 3: return position.add(OFFSET, heightOffset, -widthOffset);
} }
}
return position; return position;
} }
} }

Datei anzeigen

@ -56,13 +56,21 @@ public class BedrockEmoteTranslator extends PacketTranslator<EmotePacket> {
for (GeyserSession otherSession : session.getConnector().getPlayers()) { for (GeyserSession otherSession : session.getConnector().getPlayers()) {
if (otherSession != session) { if (otherSession != session) {
if (otherSession.isClosed()) continue; if (otherSession.isClosed()) continue;
Entity otherEntity = otherSession.getEntityCache().getEntityByJavaId(javaId); if (otherSession.getEventLoop().inEventLoop()) {
if (otherEntity == null) continue; playEmote(otherSession, javaId, packet.getEmoteId());
} else {
session.executeInEventLoop(() -> playEmote(otherSession, javaId, packet.getEmoteId()));
}
}
}
}
private void playEmote(GeyserSession otherSession, long javaId, String emoteId) {
Entity otherEntity = otherSession.getEntityCache().getEntityByJavaId(javaId); // Must be ran on same thread
if (otherEntity == null) return;
EmotePacket otherEmotePacket = new EmotePacket(); EmotePacket otherEmotePacket = new EmotePacket();
otherEmotePacket.setEmoteId(packet.getEmoteId()); otherEmotePacket.setEmoteId(emoteId);
otherEmotePacket.setRuntimeEntityId(otherEntity.getGeyserId()); otherEmotePacket.setRuntimeEntityId(otherEntity.getGeyserId());
otherSession.sendUpstreamPacket(otherEmotePacket); otherSession.sendUpstreamPacket(otherEmotePacket);
} }
} }
}
}

Datei anzeigen

@ -25,16 +25,14 @@
package org.geysermc.connector.network.translators.java.entity.spawn; package org.geysermc.connector.network.translators.java.entity.spawn;
import org.geysermc.connector.GeyserConnector; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket;
import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.entity.PaintingEntity; import org.geysermc.connector.entity.PaintingEntity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.PaintingType; import org.geysermc.connector.utils.PaintingType;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket;
import com.nukkitx.math.vector.Vector3f;
@Translator(packet = ServerSpawnPaintingPacket.class) @Translator(packet = ServerSpawnPaintingPacket.class)
public class JavaSpawnPaintingTranslator extends PacketTranslator<ServerSpawnPaintingPacket> { public class JavaSpawnPaintingTranslator extends PacketTranslator<ServerSpawnPaintingPacket> {
@ -42,16 +40,10 @@ public class JavaSpawnPaintingTranslator extends PacketTranslator<ServerSpawnPai
public void translate(ServerSpawnPaintingPacket packet, GeyserSession session) { public void translate(ServerSpawnPaintingPacket packet, GeyserSession session) {
Vector3f position = Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()); Vector3f position = Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ());
GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> { // #slowdownbrother, just don't execute it directly PaintingEntity entity = new PaintingEntity(packet.getEntityId(),
PaintingEntity entity = new PaintingEntity(
packet.getEntityId(),
session.getEntityCache().getNextEntityId().incrementAndGet(), session.getEntityCache().getNextEntityId().incrementAndGet(),
position position, PaintingType.getByPaintingType(packet.getPaintingType()), packet.getDirection().ordinal());
)
.setPaintingName(PaintingType.getByPaintingType(packet.getPaintingType()))
.setDirection(packet.getDirection().ordinal());
session.getEntityCache().spawnEntity(entity); session.getEntityCache().spawnEntity(entity);
});
} }
} }