Skip to content

Commit

Permalink
Misc Fixes
Browse files Browse the repository at this point in the history
Notes:
* Make use of the existing skin and player functions to deal with retrieving skins and spawning players
* Cache skull entities instead of just their ID's
* Store custom geometry on a PlayerEntity as this will also help with future geometry changes
* Check for initialization before spawning a skull and also spawn all skulls when a player initializes
  • Loading branch information
bundabrg committed Jun 2, 2020
1 parent a9bdde4 commit 61d929e
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.geysermc.connector.scoreboard.Team;
import org.geysermc.connector.utils.MessageUtils;
import org.geysermc.connector.network.session.cache.EntityEffectCache;
import org.geysermc.connector.utils.SkinProvider;
import org.geysermc.connector.utils.SkinUtils;

import java.util.ArrayList;
Expand All @@ -60,6 +61,8 @@ public class PlayerEntity extends LivingEntity {
private boolean onGround;
private final EntityEffectCache effectCache;

private SkinProvider.SkinGeometry geometry;

private Entity leftParrot;
private Entity rightParrot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class GeyserSession implements CommandSender {
private InventoryCache inventoryCache;
private ScoreboardCache scoreboardCache;
private WindowCache windowCache;
private Object2LongMap<Position> skullCache = new Object2LongOpenHashMap<Position>() {};
private Map<Position, PlayerEntity> skullCache = new HashMap<>();
@Setter
private TeleportCache teleportCache;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package org.geysermc.connector.network.translators.bedrock;

import com.nukkitx.protocol.bedrock.data.EntityFlag;
import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
Expand All @@ -33,6 +34,8 @@

import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket;

import java.util.concurrent.TimeUnit;

@Translator(packet = SetLocalPlayerAsInitializedPacket.class)
public class BedrockSetLocalPlayerAsInitializedTranslator extends PacketTranslator<SetLocalPlayerAsInitializedPacket> {
@Override
Expand All @@ -48,6 +51,18 @@ public void translate(SetLocalPlayerAsInitializedPacket packet, GeyserSession se
SkinUtils.requestAndHandleSkinAndCape(entity, session, skinAndCape -> entity.sendPlayer(session));
}
}

// Send Skulls
for (PlayerEntity entity : session.getSkullCache().values()) {
entity.spawnEntity(session);
SkinUtils.requestAndHandleSkinAndCape(entity, session, (skinAndCape) -> {
session.getConnector().getGeneralThreadPool().schedule(() -> {
entity.getMetadata().getFlags().setFlag(EntityFlag.INVISIBLE, false);
entity.updateBedrockMetadata(session);
}, 500, TimeUnit.MILLISECONDS); //Delay 500 milliseconds to give the model time to load in
});
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void translate(ServerPlayerListEntryPacket packet, GeyserSession session)
playerEntity.setPlayerList(true);
playerEntity.setValid(true);

PlayerListPacket.Entry playerListEntry = SkinUtils.buildCachedEntry(entry.getProfile(), playerEntity.getGeyserId());
PlayerListPacket.Entry playerListEntry = SkinUtils.buildCachedEntry(playerEntity);
if (self) {
// Copy the entry with our identity instead.
PlayerListPacket.Entry copy = new PlayerListPacket.Entry(session.getAuthData().getUUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void translate(ServerUnloadChunkPacket packet, GeyserSession session) {
while (iterator.hasNext()) {
Position position = iterator.next();
if (Math.floor(position.getX() / 16) == packet.getX() && Math.floor(position.getZ() / 16) == packet.getZ()) {
session.getEntityCache().getEntityByGeyserId(session.getSkullCache().get(position)).despawnEntity(session);
session.getSkullCache().get(position).despawnEntity(session);
iterator.remove();
}
}
Expand Down
Loading

0 comments on commit 61d929e

Please sign in to comment.