feat: scales support entity saver & fix: on death reset all scales

This commit is contained in:
reider745
2026-07-23 11:55:50 +03:00
parent 2c5bb0a079
commit d1fdec02fa
@@ -5,6 +5,7 @@ import com.reider745.api.ClientOnly;
import com.zhekasmirnov.apparatus.multiplayer.Network; import com.zhekasmirnov.apparatus.multiplayer.Network;
import com.zhekasmirnov.apparatus.multiplayer.server.ConnectedClient; import com.zhekasmirnov.apparatus.multiplayer.server.ConnectedClient;
import com.zhekasmirnov.innercore.api.runtime.saver.world.WorldDataScopeRegistry; import com.zhekasmirnov.innercore.api.runtime.saver.world.WorldDataScopeRegistry;
import org.innercore.icstd.entity.EntityModule;
import org.innercore.icstd.serialization.*; import org.innercore.icstd.serialization.*;
import org.json.JSONObject; import org.json.JSONObject;
import org.mozilla.javascript.annotations.JSStaticFunction; import org.mozilla.javascript.annotations.JSStaticFunction;
@@ -79,10 +80,8 @@ public class NativeScales {
public static void onDeath(long deaths) { public static void onDeath(long deaths) {
for(String key : getAllScales()) { for(String key : getAllScales()) {
for(long mob : getAllMobs()) {
final ScaleDescription description = SCALES.get(key); final ScaleDescription description = SCALES.get(key);
setServerScaleValue(mob, key, description.defaultValue); setServerScaleValue(deaths, key, description.defaultValue);
}
} }
} }
@@ -94,6 +93,11 @@ public class NativeScales {
public static void setScaleValue(long player, String ptr, double value) { public static void setScaleValue(long player, String ptr, double value) {
final Map<String, Double> values = SCALE_VALUES.computeIfAbsent(player, (k) -> new ConcurrentHashMap<>()); final Map<String, Double> values = SCALE_VALUES.computeIfAbsent(player, (k) -> new ConcurrentHashMap<>());
values.put(ptr, value); values.put(ptr, value);
EntityModule.writeUserData(player, "ic_" + ptr)
.asArray()
.addDouble(value)
.endScope();
} }
public static double getScaleValue(long player, String ptr) { public static double getScaleValue(long player, String ptr) {
final Map<String, Double> values = SCALE_VALUES.computeIfAbsent(player, (k) -> new ConcurrentHashMap<>()); final Map<String, Double> values = SCALE_VALUES.computeIfAbsent(player, (k) -> new ConcurrentHashMap<>());