Corrected some stuff

This commit is contained in:
Tim203 2019-09-17 00:45:39 +02:00
parent 1c74a6252a
commit 30b9caf5fa
4 changed files with 19 additions and 8 deletions

View file

@ -97,12 +97,11 @@ public class Entity {
valid = true; valid = true;
session.getUpstream().sendPacket(addEntityPacket); session.getUpstream().sendPacket(addEntityPacket);
GeyserLogger.DEFAULT.info("Spawned entity " + entityType + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); GeyserLogger.DEFAULT.debug("Spawned entity " + entityType + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")");
} }
public void despawnEntity(GeyserSession session) { public void despawnEntity(GeyserSession session) {
if (!valid) if (!valid) return;
return;
RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket(); RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket();
removeEntityPacket.setUniqueEntityId(geyserId); removeEntityPacket.setUniqueEntityId(geyserId);
@ -125,7 +124,7 @@ public class Entity {
} }
public void moveAbsolute(Vector3f position, float pitch, float yaw) { public void moveAbsolute(Vector3f position, float pitch, float yaw) {
moveAbsolute(position, new Vector3f(pitch, yaw, yaw)); moveAbsolute(position, new Vector3f(pitch, yaw, 0));
} }
public void moveAbsolute(Vector3f position, Vector3f rotation) { public void moveAbsolute(Vector3f position, Vector3f rotation) {

View file

@ -45,7 +45,7 @@ public class EntityCache {
@Getter @Getter
private Map<Long, Entity> entities = new HashMap<>(); private Map<Long, Entity> entities = new HashMap<>();
private Map<Long, Long> entityIdTranslations = new HashMap<>(); private Map<Long, Long> entityIdTranslations = new HashMap<>();
public Map<UUID, PlayerEntity> playerEntities = new HashMap<>(); private Map<UUID, PlayerEntity> playerEntities = new HashMap<>();
@Getter @Getter
private AtomicLong nextEntityId = new AtomicLong(2L); private AtomicLong nextEntityId = new AtomicLong(2L);
@ -75,4 +75,16 @@ public class EntityCache {
public Entity getEntityByJavaId(long javaId) { public Entity getEntityByJavaId(long javaId) {
return entities.get(entityIdTranslations.get(javaId)); return entities.get(entityIdTranslations.get(javaId));
} }
public void addPlayerEntity(PlayerEntity entity) {
playerEntities.put(entity.getUuid(), entity);
}
public PlayerEntity getPlayerEntity(UUID uuid) {
return playerEntities.get(uuid);
}
public void removePlayerEntity(UUID uuid) {
playerEntities.remove(uuid);
}
} }

View file

@ -29,7 +29,7 @@ public class JavaPlayerListEntryTranslator extends PacketTranslator<ServerPlayer
if (packet.getAction() == PlayerListEntryAction.ADD_PLAYER) { if (packet.getAction() == PlayerListEntryAction.ADD_PLAYER) {
long geyserId = session.getEntityCache().getNextEntityId().incrementAndGet(); long geyserId = session.getEntityCache().getNextEntityId().incrementAndGet();
session.getEntityCache().playerEntities.put(entry.getProfile().getId(), new PlayerEntity( session.getEntityCache().addPlayerEntity(new PlayerEntity(
entry.getProfile(), entry.getProfile(),
-1, -1,
geyserId, geyserId,
@ -49,7 +49,7 @@ public class JavaPlayerListEntryTranslator extends PacketTranslator<ServerPlayer
entry1.setXuid(""); entry1.setXuid("");
entry1.setPlatformChatId("WIN10"); entry1.setPlatformChatId("WIN10");
} else { } else {
session.getEntityCache().playerEntities.remove(entry.getProfile().getId()); session.getEntityCache().removePlayerEntity(entry.getProfile().getId());
} }
translate.getEntries().add(entry1); translate.getEntries().add(entry1);
} }

View file

@ -39,7 +39,7 @@ public class JavaSpawnPlayerTranslator extends PacketTranslator<ServerSpawnPlaye
Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ()); Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ());
Vector3f rotation = new Vector3f(packet.getPitch(), packet.getYaw(), packet.getYaw()); Vector3f rotation = new Vector3f(packet.getPitch(), packet.getYaw(), packet.getYaw());
PlayerEntity entity = session.getEntityCache().playerEntities.get(packet.getUUID()); PlayerEntity entity = session.getEntityCache().getPlayerEntity(packet.getUUID());
if (entity == null) { if (entity == null) {
Geyser.getLogger().error("Haven't received PlayerListEntry packet before spawning player! We ignore the player"); Geyser.getLogger().error("Haven't received PlayerListEntry packet before spawning player! We ignore the player");
return; return;