added mobcaps to API

This commit is contained in:
gnembon committed 2020-06-07 16:55:32 -03:00
1 parent f5dd01cce8
commit 0fc71e97ef
4 files changed
+59 -2

No files matched your search

@@ -29,7 +29,7 @@ public class SpawnHelperInnerMixin implements SpawnHelperInnerInterface
private void changeMobCaps(SpawnGroup entityCategory, CallbackInfoReturnable<Boolean> cir)
{
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);
}
@@ -38,11 +38,13 @@ import carpet.script.value.ThreadValue;
import carpet.script.value.Value;
import carpet.utils.BlockInfo;
import carpet.utils.Messenger;
import carpet.utils.SpawnReporter;
import com.google.common.collect.Sets;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongSet;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@@ -52,6 +54,7 @@ import net.minecraft.block.StructureBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.FallingBlockEntity;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.item.BlockItem;
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)
{
T key = type.getRegistry().get(id);
@@ -3263,6 +3307,7 @@ public class CarpetExpression
API_AuxiliaryAspects();
API_Scoreboard();
API_Interapperability();
API_GaemMonitoring();
}
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);
}
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)
{
@@ -103,7 +108,7 @@ public class SpawnReporter
for (SpawnGroup enumcreaturetype : SpawnGroup.values())
{
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 mobColor = Messenger.creatureTypeColor(enumcreaturetype);
if (multiline)