Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2025-01-11 23:51:11 +01:00
Ensure more entity tasks are run on the player session
Dieser Commit ist enthalten in:
Ursprung
85404f0ed5
Commit
ab540b1951
@ -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,19 +62,17 @@ 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;
|
double heightOffset = paintingName.getHeight() > 1 && paintingName.getHeight() != 3 ? 0.5 : 0;
|
||||||
double heightOffset = paintingName.getHeight() > 1 && paintingName.getHeight() != 3 ? 0.5 : 0;
|
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case 0: return position.add(widthOffset, heightOffset, OFFSET);
|
case 0: return position.add(widthOffset, heightOffset, OFFSET);
|
||||||
case 1: return position.add(-OFFSET, heightOffset, widthOffset);
|
case 1: return position.add(-OFFSET, heightOffset, widthOffset);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
EmotePacket otherEmotePacket = new EmotePacket();
|
} else {
|
||||||
otherEmotePacket.setEmoteId(packet.getEmoteId());
|
session.executeInEventLoop(() -> playEmote(otherSession, javaId, packet.getEmoteId()));
|
||||||
otherEmotePacket.setRuntimeEntityId(otherEntity.getGeyserId());
|
}
|
||||||
otherSession.sendUpstreamPacket(otherEmotePacket);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
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(
|
session.getEntityCache().getNextEntityId().incrementAndGet(),
|
||||||
packet.getEntityId(),
|
position, PaintingType.getByPaintingType(packet.getPaintingType()), packet.getDirection().ordinal());
|
||||||
session.getEntityCache().getNextEntityId().incrementAndGet(),
|
|
||||||
position
|
|
||||||
)
|
|
||||||
.setPaintingName(PaintingType.getByPaintingType(packet.getPaintingType()))
|
|
||||||
.setDirection(packet.getDirection().ordinal());
|
|
||||||
|
|
||||||
session.getEntityCache().spawnEntity(entity);
|
session.getEntityCache().spawnEntity(entity);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren