Skip to content

Commit

Permalink
Store experience inside LocalPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Dec 13, 2024
1 parent 17424a4 commit 8b202b2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,6 @@ private static void syncBotAndUser(BotConnection botConnection, Session clientSe
borderState.warningTime()));
}

var experienceData = dataManager.experienceData();
if (experienceData != null) {
clientSession.send(
new ClientboundSetExperiencePacket(
experienceData.experience(),
experienceData.level(),
experienceData.totalExperience()));
}

// Give initial coordinates to the client
clientSession.send(
new ClientboundPlayerPositionPacket(
Expand Down Expand Up @@ -688,6 +679,11 @@ private static void syncBotAndUser(BotConnection botConnection, Session clientSe
"Unexpected value: "
+ localPlayer.permissionLevel());
}));
clientSession.send(
new ClientboundSetExperiencePacket(
localPlayer.experienceProgress,
localPlayer.experienceLevel,
localPlayer.totalExperience));
clientSession.send(
new ClientboundEntityEventPacket(
localPlayer.entityId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ private void tickLoop() {
}

public void tick(int ticks) {
if (ticks <= 0) {
return;
}

try {
session.tick(); // Ensure all packets are handled before ticking

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.soulfiremc.server.protocol.bot.container.SFItemStack;
import com.soulfiremc.server.protocol.bot.container.WindowContainer;
import com.soulfiremc.server.protocol.bot.model.ChunkKey;
import com.soulfiremc.server.protocol.bot.model.ExperienceData;
import com.soulfiremc.server.protocol.bot.model.ServerPlayData;
import com.soulfiremc.server.protocol.bot.state.*;
import com.soulfiremc.server.protocol.bot.state.entity.EntityFactory;
Expand Down Expand Up @@ -142,7 +141,6 @@ public final class SessionDataManager {
private int serverChunkRadius = 3;
private int serverSimulationDistance = 3;
private boolean serverEnforcesSecureChat;
private @Nullable ExperienceData experienceData;
private @Nullable ChunkKey centerChunk;
private boolean joinedWorld = false;
private String serverBrand;
Expand Down Expand Up @@ -587,8 +585,7 @@ public void onHealth(ClientboundSetHealthPacket packet) {

@EventHandler
public void onExperience(ClientboundSetExperiencePacket packet) {
experienceData =
new ExperienceData(packet.getExperience(), packet.getLevel(), packet.getTotalExperience());
localPlayer.setExperienceValues(packet.getExperience(), packet.getTotalExperience(), packet.getLevel());
}

@EventHandler
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ public void aiStep() {
}
}

public void setExperienceValues(float currentXP, int maxXP, int level) {
this.experienceProgress = currentXP;
this.totalExperience = maxXP;
this.experienceLevel = level;
}

public void resetPos() {
this.setPose(Pose.STANDING);
if (this.level() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public abstract class Player extends LivingEntity {
.put(Pose.DYING, EntityDimensions.fixed(0.2F, 0.2F).withEyeHeight(DEFAULT_EYE_HEIGHT))
.build();
public static final int CLIENT_LOADED_TIMEOUT_TIME = 60;
public int experienceLevel;
public int totalExperience;
public float experienceProgress;
protected final GameProfile gameProfile;
protected boolean wasUnderwater = false;
private boolean reducedDebugInfo;
Expand Down

0 comments on commit 8b202b2

Please sign in to comment.