dont be lazy refactor
This commit is contained in:
1 parent
a65d16c9ba
commit
74bd0bb81e
31 files changed
+1078
-1383
No files matched your search
@@ -25,31 +25,29 @@ public class Monitoring {
|
||||
|
||||
public static void apply(Expression expression)
|
||||
{
|
||||
expression.addLazyFunction("system_info", -1, (c, t, lv) ->
|
||||
expression.addContextFunction("system_info", -1, (c, t, lv) ->
|
||||
{
|
||||
if (lv.size() == 0)
|
||||
{
|
||||
Value ret = SystemInfo.getAll((CarpetContext) c);
|
||||
return (cc, tt) -> ret;
|
||||
return SystemInfo.getAll((CarpetContext) c);
|
||||
}
|
||||
if (lv.size() == 1) {
|
||||
String what = lv.get(0).evalValue(c).getString();
|
||||
String what = lv.get(0).getString();
|
||||
Value res = SystemInfo.get(what, (CarpetContext) c);
|
||||
if (res == null) throw new InternalExpressionException("Unknown option for 'system_info': " + what);
|
||||
return (cc, tt) -> res;
|
||||
return res;
|
||||
}
|
||||
throw new InternalExpressionException("'system_info' requires one or no parameters");
|
||||
});
|
||||
// game processed snooper functions
|
||||
expression.addLazyFunction("get_mob_counts", -1, (c, t, lv) ->
|
||||
expression.addContextFunction("get_mob_counts", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
SpawnHelper.Info info = world.getChunkManager().getSpawnInfo();
|
||||
if (info == null) return LazyValue.NULL;
|
||||
if (info == null) return Value.NULL;
|
||||
Object2IntMap<SpawnGroup> mobcounts = info.getGroupToCount();
|
||||
int chunks = ((SpawnHelperInnerInterface)info).cmGetChunkCount();
|
||||
Value retVal;
|
||||
if (lv.size() == 0)
|
||||
{
|
||||
Map<Value, Value> retDict = new HashMap<>();
|
||||
@@ -63,19 +61,15 @@ public class Monitoring {
|
||||
new NumericValue(currentCap))
|
||||
);
|
||||
}
|
||||
retVal = MapValue.wrap(retDict);
|
||||
return MapValue.wrap(retDict);
|
||||
}
|
||||
else
|
||||
{
|
||||
String catString = lv.get(0).evalValue(c).getString();
|
||||
SpawnGroup cat = SpawnGroup.byName(catString.toLowerCase(Locale.ROOT));
|
||||
if (cat == null) throw new InternalExpressionException("Unreconized mob category: "+catString);
|
||||
retVal = ListValue.of(
|
||||
new NumericValue(mobcounts.getInt(cat)),
|
||||
new NumericValue((int)(cat.getCapacity() * chunks / SpawnReporter.currentMagicNumber()))
|
||||
);
|
||||
}
|
||||
return (_c, _t) -> retVal;
|
||||
String catString = lv.get(0).getString();
|
||||
SpawnGroup cat = SpawnGroup.byName(catString.toLowerCase(Locale.ROOT));
|
||||
if (cat == null) throw new InternalExpressionException("Unreconized mob category: "+catString);
|
||||
return ListValue.of(
|
||||
new NumericValue(mobcounts.getInt(cat)),
|
||||
new NumericValue((int)(cat.getCapacity() * chunks / SpawnReporter.currentMagicNumber()))
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user