You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class PlayerEcoHelperData implements IPlayerEcoHelperData, AutoSyncedComponent {
private final Player provider;
private Double playerMoney;
private Boolean playerIsFirstJoin = true;
public PlayerEcoHelperData(Player provider) {
this.provider = provider;
}
@Override
public Double getMoney() {
this.provider.syncComponent(CapabilityRegister.PLAYER_DATA);
CapabilityRegister.PLAYER_DATA.sync(this.provider);
return playerMoney;
}
@Override
public Boolean getIsFirstJoin() {
this.provider.syncComponent(CapabilityRegister.PLAYER_DATA);
CapabilityRegister.PLAYER_DATA.sync(this.provider);
return playerIsFirstJoin;
}
@Override
public void setMoney(Double money) {
this.playerMoney = money;
this.provider.syncComponent(CapabilityRegister.PLAYER_DATA);
CapabilityRegister.PLAYER_DATA.sync(this.provider);
}
@Override
public void setIsFirstJoin(Boolean isFirstJoin) {
this.playerIsFirstJoin = isFirstJoin;
this.provider.syncComponent(CapabilityRegister.PLAYER_DATA);
CapabilityRegister.PLAYER_DATA.sync(this.provider);
}
@Override
public void readFromNbt(CompoundTag tag) {
playerMoney = tag.getDouble("money");
playerIsFirstJoin = tag.getBoolean("isFirstJoin");
}
@Override
public void writeToNbt(CompoundTag tag) {
tag.putDouble("money", playerMoney);
tag.putBoolean("isFirstJoin", playerIsFirstJoin);
}
@Override
public void tick() {
this.provider.syncComponent(CapabilityRegister.PLAYER_DATA);
CapabilityRegister.PLAYER_DATA.sync(this.provider);
}
}
Registry class:
public class CapabilityRegister implements EntityComponentInitializer {
public static final ComponentKey<IPlayerEcoHelperData> PLAYER_DATA = ComponentRegistry.getOrCreate(new ResourceLocation(EcoHelper.MODID, "player_eco_helper_data"), IPlayerEcoHelperData.class);
@Override
public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) {
// registry.beginRegistration(Player.class, PLAYER_DATA).impl(PlayerEcoHelperData.class).end(PlayerEcoHelperData::new);
registry.registerForPlayers(PLAYER_DATA, PlayerEcoHelperData::new, RespawnCopyStrategy.ALWAYS_COPY);
}
}
I tried the registry.beginRegistration and the registry.registerForPlayers, but everything not change too much.
For now, when player join the server, the client-side tells me "Null" for player's balance. But on server-side (run a command on console), then returns correct balance. And then, client-side "Null" changes into the correct balance. (The same as when player dead or exit and re-join)
The text was updated successfully, but these errors were encountered:
#172
I changed my code, but nothing worked.
First, is my interface (I add CommonTickingComponent, AutoSyncedComponent into this):
And this is my subclass:
Registry class:
I tried the
registry.beginRegistration
and theregistry.registerForPlayers
, but everything not change too much.For now, when player join the server, the client-side tells me "Null" for player's balance. But on server-side (run a command on console), then returns correct balance. And then, client-side "Null" changes into the correct balance. (The same as when player dead or exit and re-join)
The text was updated successfully, but these errors were encountered: