mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Ensure more entity tasks are run on the player session
This commit is contained in:
parent
85404f0ed5
commit
ab540b1951
3 changed files with 36 additions and 43 deletions
|
@ -27,24 +27,19 @@ package org.geysermc.connector.entity;
|
|||
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
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.network.session.GeyserSession;
|
||||
import org.geysermc.connector.utils.PaintingType;
|
||||
|
||||
@Getter @Setter
|
||||
@Accessors(chain = true)
|
||||
public class PaintingEntity extends Entity {
|
||||
private static final double OFFSET = -0.46875;
|
||||
private PaintingType paintingName;
|
||||
private int direction;
|
||||
private final PaintingType paintingName;
|
||||
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);
|
||||
this.paintingName = paintingName;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,7 +48,7 @@ public class PaintingEntity extends Entity {
|
|||
addPaintingPacket.setUniqueEntityId(geyserId);
|
||||
addPaintingPacket.setRuntimeEntityId(geyserId);
|
||||
addPaintingPacket.setMotive(paintingName.getBedrockName());
|
||||
addPaintingPacket.setPosition(fixOffset(true));
|
||||
addPaintingPacket.setPosition(fixOffset());
|
||||
addPaintingPacket.setDirection(direction);
|
||||
session.sendUpstreamPacket(addPaintingPacket);
|
||||
|
||||
|
@ -67,19 +62,17 @@ public class PaintingEntity extends Entity {
|
|||
// Do nothing, as head look messes up paintings
|
||||
}
|
||||
|
||||
public Vector3f fixOffset(boolean toBedrock) {
|
||||
if (toBedrock) {
|
||||
Vector3f position = super.position;
|
||||
position = position.add(0.5, 0.5, 0.5);
|
||||
double widthOffset = paintingName.getWidth() > 1 ? 0.5 : 0;
|
||||
double heightOffset = paintingName.getHeight() > 1 && paintingName.getHeight() != 3 ? 0.5 : 0;
|
||||
private Vector3f fixOffset() {
|
||||
Vector3f position = super.position;
|
||||
position = position.add(0.5, 0.5, 0.5);
|
||||
double widthOffset = paintingName.getWidth() > 1 ? 0.5 : 0;
|
||||
double heightOffset = paintingName.getHeight() > 1 && paintingName.getHeight() != 3 ? 0.5 : 0;
|
||||
|
||||
switch (direction) {
|
||||
case 0: return position.add(widthOffset, heightOffset, OFFSET);
|
||||
case 1: return position.add(-OFFSET, heightOffset, widthOffset);
|
||||
case 2: return position.add(-widthOffset, heightOffset, -OFFSET);
|
||||
case 3: return position.add(OFFSET, heightOffset, -widthOffset);
|
||||
}
|
||||
switch (direction) {
|
||||
case 0: return position.add(widthOffset, heightOffset, OFFSET);
|
||||
case 1: return position.add(-OFFSET, heightOffset, widthOffset);
|
||||
case 2: return position.add(-widthOffset, heightOffset, -OFFSET);
|
||||
case 3: return position.add(OFFSET, heightOffset, -widthOffset);
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
|
|
@ -56,13 +56,21 @@ public class BedrockEmoteTranslator extends PacketTranslator<EmotePacket> {
|
|||
for (GeyserSession otherSession : session.getConnector().getPlayers()) {
|
||||
if (otherSession != session) {
|
||||
if (otherSession.isClosed()) continue;
|
||||
Entity otherEntity = otherSession.getEntityCache().getEntityByJavaId(javaId);
|
||||
if (otherEntity == null) continue;
|
||||
EmotePacket otherEmotePacket = new EmotePacket();
|
||||
otherEmotePacket.setEmoteId(packet.getEmoteId());
|
||||
otherEmotePacket.setRuntimeEntityId(otherEntity.getGeyserId());
|
||||
otherSession.sendUpstreamPacket(otherEmotePacket);
|
||||
if (otherSession.getEventLoop().inEventLoop()) {
|
||||
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();
|
||||
otherEmotePacket.setEmoteId(emoteId);
|
||||
otherEmotePacket.setRuntimeEntityId(otherEntity.getGeyserId());
|
||||
otherSession.sendUpstreamPacket(otherEmotePacket);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,16 +25,14 @@
|
|||
|
||||
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.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
import org.geysermc.connector.network.translators.Translator;
|
||||
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)
|
||||
public class JavaSpawnPaintingTranslator extends PacketTranslator<ServerSpawnPaintingPacket> {
|
||||
|
||||
|
@ -42,16 +40,10 @@ public class JavaSpawnPaintingTranslator extends PacketTranslator<ServerSpawnPai
|
|||
public void translate(ServerSpawnPaintingPacket packet, GeyserSession session) {
|
||||
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(),
|
||||
session.getEntityCache().getNextEntityId().incrementAndGet(),
|
||||
position
|
||||
)
|
||||
.setPaintingName(PaintingType.getByPaintingType(packet.getPaintingType()))
|
||||
.setDirection(packet.getDirection().ordinal());
|
||||
PaintingEntity entity = new PaintingEntity(packet.getEntityId(),
|
||||
session.getEntityCache().getNextEntityId().incrementAndGet(),
|
||||
position, PaintingType.getByPaintingType(packet.getPaintingType()), packet.getDirection().ordinal());
|
||||
|
||||
session.getEntityCache().spawnEntity(entity);
|
||||
});
|
||||
session.getEntityCache().spawnEntity(entity);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue