added mobcaps to API
This commit is contained in:
1 parent
f5dd01cce8
commit
0fc71e97ef
4 files changed
+59
-2
No files matched your search
@@ -332,6 +332,13 @@ world-localized block, so not `block('stone')`, or a string representing a dimen
|
|||||||
### `view_distance()`
|
### `view_distance()`
|
||||||
Returns the view distance of the server.
|
Returns the view distance of the server.
|
||||||
|
|
||||||
|
### `mob_counts()`, `mob_counts(category)` 1.16+
|
||||||
|
|
||||||
|
Returns either a map of mob categories with its respective counts and capacities (a.k.a. mobcaps) or just a tuple
|
||||||
|
of count and limit for a specific category. If a category was not spawning for whatever reason it may not be
|
||||||
|
returned from `mob_counts()`, but could be retrieved for `mob_counts(category)`. Returned counts is what spawning
|
||||||
|
algorithm has taken in to account last time mobs spawned.
|
||||||
|
|
||||||
### `schedule(delay, function, args...)`
|
### `schedule(delay, function, args...)`
|
||||||
|
|
||||||
Schedules a user defined function to run with a specified `delay` ticks of delay. Scheduled functions run at the end
|
Schedules a user defined function to run with a specified `delay` ticks of delay. Scheduled functions run at the end
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class SpawnHelperInnerMixin implements SpawnHelperInnerInterface
|
|||||||
private void changeMobCaps(SpawnGroup entityCategory, CallbackInfoReturnable<Boolean> cir)
|
private void changeMobCaps(SpawnGroup entityCategory, CallbackInfoReturnable<Boolean> cir)
|
||||||
{
|
{
|
||||||
int newCap = (int) ((double)entityCategory.getCapacity()*(Math.pow(2.0,(SpawnReporter.mobcap_exponent/4))));
|
int newCap = (int) ((double)entityCategory.getCapacity()*(Math.pow(2.0,(SpawnReporter.mobcap_exponent/4))));
|
||||||
int i = newCap * spawningChunkCount / (int)Math.pow(17.0D, 2.0D);
|
int i = newCap * spawningChunkCount / SpawnReporter.MAGIC_NUMBER;
|
||||||
cir.setReturnValue(groupToCount.getInt(entityCategory) < i);
|
cir.setReturnValue(groupToCount.getInt(entityCategory) < i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,11 +38,13 @@ import carpet.script.value.ThreadValue;
|
|||||||
import carpet.script.value.Value;
|
import carpet.script.value.Value;
|
||||||
import carpet.utils.BlockInfo;
|
import carpet.utils.BlockInfo;
|
||||||
import carpet.utils.Messenger;
|
import carpet.utils.Messenger;
|
||||||
|
import carpet.utils.SpawnReporter;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.mojang.brigadier.StringReader;
|
import com.mojang.brigadier.StringReader;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
@@ -52,6 +54,7 @@ import net.minecraft.block.StructureBlock;
|
|||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.entity.FallingBlockEntity;
|
import net.minecraft.entity.FallingBlockEntity;
|
||||||
|
import net.minecraft.entity.SpawnGroup;
|
||||||
import net.minecraft.entity.ai.pathing.NavigationType;
|
import net.minecraft.entity.ai.pathing.NavigationType;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
@@ -3233,6 +3236,47 @@ public class CarpetExpression
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void API_GaemMonitoring()
|
||||||
|
{
|
||||||
|
// game processed snooper functions
|
||||||
|
this.expr.addLazyFunction("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;
|
||||||
|
Object2IntMap<SpawnGroup> mobcounts = info.getGroupToCount();
|
||||||
|
int chunks = info.getSpawningChunkCount();
|
||||||
|
Value retVal;
|
||||||
|
if (lv.size() == 0)
|
||||||
|
{
|
||||||
|
Map<Value, Value> retDict = new HashMap<>();
|
||||||
|
for (SpawnGroup category: mobcounts.keySet())
|
||||||
|
{
|
||||||
|
int currentCap = (int)(category.getCapacity() * chunks / SpawnReporter.currentMagicNumber()); // MAGIC_NUMBER
|
||||||
|
retDict.put(
|
||||||
|
new StringValue(category.asString().toLowerCase(Locale.ROOT)),
|
||||||
|
ListValue.of(
|
||||||
|
new NumericValue(mobcounts.getInt(category)),
|
||||||
|
new NumericValue(currentCap))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
retVal = MapValue.wrap(retDict);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String catString = lv.get(0).evalValue(c).getString();
|
||||||
|
SpawnGroup cat = SpawnGroup.method_28307(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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private <T> Stat<T> getStat(StatType<T> type, Identifier id)
|
private <T> Stat<T> getStat(StatType<T> type, Identifier id)
|
||||||
{
|
{
|
||||||
T key = type.getRegistry().get(id);
|
T key = type.getRegistry().get(id);
|
||||||
@@ -3263,6 +3307,7 @@ public class CarpetExpression
|
|||||||
API_AuxiliaryAspects();
|
API_AuxiliaryAspects();
|
||||||
API_Scoreboard();
|
API_Scoreboard();
|
||||||
API_Interapperability();
|
API_Interapperability();
|
||||||
|
API_GaemMonitoring();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean fillAndScanCommand(ScriptHost host, int x, int y, int z)
|
public boolean fillAndScanCommand(ScriptHost host, int x, int y, int z)
|
||||||
|
|||||||
@@ -82,6 +82,11 @@ public class SpawnReporter
|
|||||||
local_spawns.put(cat, local_spawns.get(cat)+1);
|
local_spawns.put(cat, local_spawns.get(cat)+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final int MAGIC_NUMBER = (int)Math.pow(17.0D, 2.0D);
|
||||||
|
public static double currentMagicNumber()
|
||||||
|
{
|
||||||
|
return MAGIC_NUMBER / (Math.pow(2.0,(SpawnReporter.mobcap_exponent/4)));
|
||||||
|
}
|
||||||
|
|
||||||
public static List<BaseText> printMobcapsForDimension(ServerWorld world, boolean multiline)
|
public static List<BaseText> printMobcapsForDimension(ServerWorld world, boolean multiline)
|
||||||
{
|
{
|
||||||
@@ -103,7 +108,7 @@ public class SpawnReporter
|
|||||||
for (SpawnGroup enumcreaturetype : SpawnGroup.values())
|
for (SpawnGroup enumcreaturetype : SpawnGroup.values())
|
||||||
{
|
{
|
||||||
int cur = dimCounts.getOrDefault(enumcreaturetype, -1);
|
int cur = dimCounts.getOrDefault(enumcreaturetype, -1);
|
||||||
int max = chunkcount * (int)((double)enumcreaturetype.getCapacity() * (Math.pow(2.0,(SpawnReporter.mobcap_exponent/4)))) / (int)Math.pow(17.0D, 2.0D); // from ServerChunkManager.CHUNKS_ELIGIBLE_FOR_SPAWNING
|
int max = chunkcount * (int)((double)enumcreaturetype.getCapacity() / currentMagicNumber()); // from ServerChunkManager.CHUNKS_ELIGIBLE_FOR_SPAWNING
|
||||||
String color = Messenger.heatmap_color(cur, max);
|
String color = Messenger.heatmap_color(cur, max);
|
||||||
String mobColor = Messenger.creatureTypeColor(enumcreaturetype);
|
String mobColor = Messenger.creatureTypeColor(enumcreaturetype);
|
||||||
if (multiline)
|
if (multiline)
|
||||||
|
|||||||
Reference in new issue
Block a user