1 parent
efddb904a0
commit
fbe37017c5
7 files changed
+203
-235
No files matched your search
@@ -32,6 +32,7 @@ import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.entity.EntityTypeTest;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
import net.minecraft.world.level.levelgen.structure.structures.NetherFortressStructure;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -42,59 +43,48 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class SpawnReporter
|
||||
{
|
||||
public static boolean mock_spawns = false;
|
||||
|
||||
public static Long track_spawns = 0L;
|
||||
private static final MobCategory[] CACHED_MOBCATEGORY_VALUES = MobCategory.values();
|
||||
public static boolean mockSpawns = false;
|
||||
|
||||
public static final HashMap<ResourceKey<Level>, Integer> chunkCounts = new HashMap<>();
|
||||
|
||||
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Object2LongMap<EntityType<?>>> spawn_stats = new HashMap<>();
|
||||
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Object2LongOpenHashMap<EntityType<?>>> spawn_stats = new HashMap<>();
|
||||
public static double mobcap_exponent = 0.0D;
|
||||
|
||||
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_attempts = new HashMap<>();
|
||||
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> overall_spawn_ticks = new HashMap<>();
|
||||
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_ticks_full = new HashMap<>();
|
||||
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_ticks_fail = new HashMap<>();
|
||||
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_ticks_succ = new HashMap<>();
|
||||
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_ticks_spawns = new HashMap<>();
|
||||
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, Long> spawn_cap_count = new HashMap<>();
|
||||
public static final Object2LongOpenHashMap<Pair<ResourceKey<Level>, MobCategory>> spawn_attempts = new Object2LongOpenHashMap<>();
|
||||
public static final Object2LongOpenHashMap<Pair<ResourceKey<Level>, MobCategory>> overall_spawn_ticks = new Object2LongOpenHashMap<>();
|
||||
public static final Object2LongOpenHashMap<Pair<ResourceKey<Level>, MobCategory>> spawn_ticks_full = new Object2LongOpenHashMap<>();
|
||||
public static final Object2LongOpenHashMap<Pair<ResourceKey<Level>, MobCategory>> spawn_ticks_fail = new Object2LongOpenHashMap<>();
|
||||
public static final Object2LongOpenHashMap<Pair<ResourceKey<Level>, MobCategory>> spawn_ticks_succ = new Object2LongOpenHashMap<>();
|
||||
public static final Object2LongOpenHashMap<Pair<ResourceKey<Level>, MobCategory>> spawn_ticks_spawns = new Object2LongOpenHashMap<>();
|
||||
public static final Object2LongOpenHashMap<Pair<ResourceKey<Level>, MobCategory>> spawn_cap_count = new Object2LongOpenHashMap<>();
|
||||
public static final HashMap<Pair<ResourceKey<Level>, MobCategory>, EvictingQueue<Pair<EntityType<?>, BlockPos>>> spawned_mobs = new HashMap<>();
|
||||
public static final HashMap<MobCategory, Integer> spawn_tries = new HashMap<>();
|
||||
public static BlockPos lower_spawning_limit = null;
|
||||
public static BlockPos upper_spawning_limit = null;
|
||||
// in case game gets each thread for each world - these need to belong to workd.
|
||||
public static HashMap<MobCategory, Long> local_spawns = null; // per world
|
||||
public static HashSet<MobCategory> first_chunk_marker = null;
|
||||
|
||||
static {
|
||||
reset_spawn_stats(null, true);
|
||||
}
|
||||
private static int spawnTrackingStartTime = 0;
|
||||
private static BoundingBox trackedSpawningArea = null;
|
||||
// in case game gets each thread for each world - these need to belong to workd.
|
||||
public static Object2LongOpenHashMap<MobCategory> local_spawns = null; // per world
|
||||
public static HashSet<MobCategory> first_chunk_marker = null;
|
||||
|
||||
public static void registerSpawn(Mob mob, MobCategory cat, BlockPos pos)
|
||||
{
|
||||
if (lower_spawning_limit != null)
|
||||
if (trackedSpawningArea != null && !trackedSpawningArea.isInside(pos))
|
||||
{
|
||||
if (!( (lower_spawning_limit.getX() <= pos.getX() && pos.getX() <= upper_spawning_limit.getX()) &&
|
||||
(lower_spawning_limit.getY() <= pos.getY() && pos.getY() <= upper_spawning_limit.getY()) &&
|
||||
(lower_spawning_limit.getZ() <= pos.getZ() && pos.getZ() <= upper_spawning_limit.getZ())
|
||||
))
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Pair<ResourceKey<Level>, MobCategory> key = Pair.of(mob.level().dimension(), cat);
|
||||
long count = spawn_stats.get(key).getOrDefault(mob.getType(), 0L);
|
||||
spawn_stats.get(key).put(mob.getType(), count + 1);
|
||||
spawn_stats.get(key).addTo(mob.getType(), 1);
|
||||
spawned_mobs.get(key).put(Pair.of(mob.getType(), pos));
|
||||
if (!local_spawns.containsKey(cat))
|
||||
{
|
||||
CarpetSettings.LOG.error("Rogue spawn detected for category "+cat.getName()+" for mob "+mob.getType().getDescription().getString()+". If you see this message let carpet peeps know about it on github issues.");
|
||||
local_spawns.put(cat, 0L);
|
||||
}
|
||||
local_spawns.put(cat, local_spawns.get(cat)+1);
|
||||
local_spawns.addTo(cat, 1);
|
||||
}
|
||||
|
||||
public static final int MAGIC_NUMBER = (int)Math.pow(17.0D, 2.0D);
|
||||
@@ -120,18 +110,18 @@ public class SpawnReporter
|
||||
}
|
||||
|
||||
List<String> shortCodes = new ArrayList<>();
|
||||
for (MobCategory enumcreaturetype : MobCategory.values())
|
||||
for (MobCategory category : cachedMobCategories())
|
||||
{
|
||||
int cur = dimCounts.getOrDefault(enumcreaturetype, -1);
|
||||
int max = (int)(chunkcount * ((double)enumcreaturetype.getMaxInstancesPerChunk() / MAGIC_NUMBER)); // from ServerChunkManager.CHUNKS_ELIGIBLE_FOR_SPAWNING
|
||||
int cur = dimCounts.getOrDefault(category, -1);
|
||||
int max = (int)(chunkcount * ((double)category.getMaxInstancesPerChunk() / MAGIC_NUMBER)); // from ServerChunkManager.CHUNKS_ELIGIBLE_FOR_SPAWNING
|
||||
String color = Messenger.heatmap_color(cur, max);
|
||||
String mobColor = Messenger.creatureTypeColor(enumcreaturetype);
|
||||
String mobColor = Messenger.creatureTypeColor(category);
|
||||
if (multiline)
|
||||
{
|
||||
int rounds = spawn_tries.get(enumcreaturetype);
|
||||
lst.add(Messenger.c(String.format("w %s: ", enumcreaturetype.getName()),
|
||||
int rounds = spawn_tries.get(category);
|
||||
lst.add(Messenger.c(String.format("w %s: ", category.getName()),
|
||||
(cur < 0) ? "g -" : (color + " " + cur), "g / ", mobColor + " " + max,
|
||||
(rounds == 1) ? "w " : String.format("gi (%d rounds/tick)", spawn_tries.get(enumcreaturetype))
|
||||
(rounds == 1) ? "w " : String.format("gi (%d rounds/tick)", spawn_tries.get(category))
|
||||
));
|
||||
}
|
||||
else
|
||||
@@ -144,7 +134,7 @@ public class SpawnReporter
|
||||
}
|
||||
if (!multiline)
|
||||
{
|
||||
if (shortCodes.size()>0)
|
||||
if (shortCodes.size() > 0)
|
||||
{
|
||||
shortCodes.remove(shortCodes.size() - 1);
|
||||
lst.add(Messenger.c(shortCodes.toArray(new Object[0])));
|
||||
@@ -158,18 +148,18 @@ public class SpawnReporter
|
||||
return lst;
|
||||
}
|
||||
|
||||
public static List<Component> recent_spawns(Level world, MobCategory creature_type)
|
||||
public static List<Component> getRecentSpawns(Level world, MobCategory category)
|
||||
{
|
||||
List<Component> lst = new ArrayList<>();
|
||||
if ((track_spawns == 0L))
|
||||
if (!trackingSpawns())
|
||||
{
|
||||
lst.add(Messenger.s("Spawn tracking not started"));
|
||||
return lst;
|
||||
}
|
||||
String type_code = creature_type.getName();
|
||||
String categoryName = category.getName();
|
||||
|
||||
lst.add(Messenger.s(String.format("Recent %s spawns:",type_code)));
|
||||
for (Pair<EntityType<?>, BlockPos> pair : spawned_mobs.get(Pair.of(world.dimension(), creature_type)).keySet()) // getDImTYpe
|
||||
lst.add(Messenger.s(String.format("Recent %s spawns:", categoryName)));
|
||||
for (Pair<EntityType<?>, BlockPos> pair : spawned_mobs.get(Pair.of(world.dimension(), category)).keySet())
|
||||
{
|
||||
lst.add( Messenger.c(
|
||||
"w - ",
|
||||
@@ -178,7 +168,7 @@ public class SpawnReporter
|
||||
));
|
||||
}
|
||||
|
||||
if (lst.size()==1)
|
||||
if (lst.size() == 1)
|
||||
{
|
||||
lst.add(Messenger.s(" - Nothing spawned yet, sorry."));
|
||||
}
|
||||
@@ -186,37 +176,37 @@ public class SpawnReporter
|
||||
|
||||
}
|
||||
|
||||
public static List<Component> show_mobcaps(BlockPos pos, ServerLevel worldIn)
|
||||
public static List<Component> handleWoolAction(BlockPos pos, ServerLevel worldIn)
|
||||
{
|
||||
DyeColor under = WoolTool.getWoolColorAtPosition(worldIn, pos.below());
|
||||
if (under == null)
|
||||
{
|
||||
if (track_spawns > 0L)
|
||||
if (trackingSpawns())
|
||||
{
|
||||
return tracking_report(worldIn);
|
||||
return makeTrackingReport(worldIn);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printMobcapsForDimension(worldIn, true );
|
||||
}
|
||||
}
|
||||
MobCategory creature_type = get_type_code_from_wool_code(under);
|
||||
if (creature_type != null)
|
||||
MobCategory category = getCategoryFromWoolColor(under);
|
||||
if (category != null)
|
||||
{
|
||||
if (track_spawns > 0L)
|
||||
if (trackingSpawns())
|
||||
{
|
||||
return recent_spawns(worldIn, creature_type);
|
||||
return getRecentSpawns(worldIn, category);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printEntitiesByType(creature_type, worldIn, true);
|
||||
return printEntitiesByType(category, worldIn, true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (track_spawns > 0L)
|
||||
if (trackingSpawns())
|
||||
{
|
||||
return tracking_report(worldIn);
|
||||
return makeTrackingReport(worldIn);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -225,7 +215,7 @@ public class SpawnReporter
|
||||
|
||||
}
|
||||
|
||||
public static MobCategory get_type_code_from_wool_code(DyeColor color)
|
||||
public static MobCategory getCategoryFromWoolColor(DyeColor color)
|
||||
{
|
||||
return switch (color)
|
||||
{
|
||||
@@ -238,13 +228,13 @@ public class SpawnReporter
|
||||
};
|
||||
}
|
||||
|
||||
public static List<Component> printEntitiesByType(MobCategory cat, Level worldIn, boolean all) //Class<?> entityType)
|
||||
public static List<Component> printEntitiesByType(MobCategory cat, ServerLevel worldIn, boolean all)
|
||||
{
|
||||
List<Component> lst = new ArrayList<>();
|
||||
lst.add( Messenger.s(String.format("Loaded entities for %s class:", cat)));
|
||||
for (Entity entity : ((ServerLevel)worldIn).getEntities(EntityTypeTest.forClass(Entity.class), (e) -> e.getType().getCategory()==cat))
|
||||
lst.add( Messenger.s(String.format("Loaded entities for %s category:", cat)));
|
||||
for (Entity entity : worldIn.getEntities(EntityTypeTest.forClass(Entity.class), (e) -> e.getType().getCategory() == cat))
|
||||
{
|
||||
boolean persistent = entity instanceof Mob && ( ((Mob) entity).isPersistenceRequired() || ((Mob) entity).requiresCustomPersistence());
|
||||
boolean persistent = entity instanceof Mob mob && ( mob.isPersistenceRequired() || mob.requiresCustomPersistence());
|
||||
if (!all && persistent)
|
||||
continue;
|
||||
|
||||
@@ -252,104 +242,122 @@ public class SpawnReporter
|
||||
BlockPos pos = entity.blockPosition();
|
||||
lst.add( Messenger.c(
|
||||
"w - ",
|
||||
Messenger.tp(persistent?"gb":"wb",pos),
|
||||
String.format(persistent?"g : %s":"w : %s", type.getDescription().getString())
|
||||
Messenger.tp(persistent ? "gb" : "wb", pos),
|
||||
String.format(persistent ? "g : %s" : "w : %s", type.getDescription().getString())
|
||||
));
|
||||
|
||||
}
|
||||
if (lst.size()==1)
|
||||
if (lst.size() == 1)
|
||||
{
|
||||
lst.add(Messenger.s(" - Empty."));
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
public static void initialize_mocking()
|
||||
public static void initializeMocking()
|
||||
{
|
||||
mock_spawns = true;
|
||||
|
||||
mockSpawns = true;
|
||||
}
|
||||
public static void stop_mocking()
|
||||
public static void stopMocking()
|
||||
{
|
||||
mock_spawns = false;
|
||||
mockSpawns = false;
|
||||
}
|
||||
public static void reset_spawn_stats(MinecraftServer server, boolean full)
|
||||
{
|
||||
|
||||
spawn_stats.clear();
|
||||
spawned_mobs.clear();
|
||||
for (MobCategory enumcreaturetype : MobCategory.values())
|
||||
public static void resetSpawnStats(MinecraftServer server, boolean full)
|
||||
{
|
||||
if (full)
|
||||
{
|
||||
if (full)
|
||||
{
|
||||
spawn_tries.put(enumcreaturetype, 1);
|
||||
}
|
||||
if (server != null) for (ResourceKey<Level> dim : server.levelKeys())
|
||||
{
|
||||
Pair<ResourceKey<Level>, MobCategory> key = Pair.of(dim, enumcreaturetype);
|
||||
overall_spawn_ticks.put(key, 0L);
|
||||
spawn_attempts.put(key, 0L);
|
||||
spawn_ticks_full.put(key, 0L);
|
||||
spawn_ticks_fail.put(key, 0L);
|
||||
spawn_ticks_succ.put(key, 0L);
|
||||
spawn_ticks_spawns.put(key, 0L);
|
||||
spawn_cap_count.put(key, 0L);
|
||||
for (MobCategory category : cachedMobCategories())
|
||||
spawn_tries.put(category, 1);
|
||||
}
|
||||
overall_spawn_ticks.clear();
|
||||
spawn_attempts.clear();
|
||||
spawn_ticks_full.clear();
|
||||
spawn_ticks_fail.clear();
|
||||
spawn_ticks_succ.clear();
|
||||
spawn_ticks_spawns.clear();
|
||||
spawn_cap_count.clear();
|
||||
|
||||
// can't fast-path to clear given different worlds could have different amount of worlds
|
||||
for (MobCategory category : cachedMobCategories()) {
|
||||
for (ResourceKey<Level> world : server.levelKeys()) {
|
||||
Pair<ResourceKey<Level>, MobCategory> key = Pair.of(world, category);
|
||||
spawn_stats.put(key, new Object2LongOpenHashMap<>());
|
||||
spawned_mobs.put(key, new EvictingQueue<>());
|
||||
}
|
||||
}
|
||||
track_spawns = 0L;
|
||||
spawnTrackingStartTime = 0;
|
||||
}
|
||||
|
||||
public static MobCategory[] cachedMobCategories() {
|
||||
return CACHED_MOBCATEGORY_VALUES;
|
||||
}
|
||||
|
||||
public static boolean trackingSpawns() {
|
||||
return spawnTrackingStartTime != 0L;
|
||||
}
|
||||
|
||||
public static void startTracking(MinecraftServer server, BoundingBox trackedArea) {
|
||||
resetSpawnStats(server, false);
|
||||
spawnTrackingStartTime = server.getTickCount();
|
||||
trackedSpawningArea = trackedArea;
|
||||
}
|
||||
|
||||
public static void stopTracking(MinecraftServer server) {
|
||||
resetSpawnStats(server, false);
|
||||
SpawnReporter.spawnTrackingStartTime = 0;
|
||||
trackedSpawningArea = null;
|
||||
}
|
||||
|
||||
private static String getWorldCode(ResourceKey<Level> world)
|
||||
{
|
||||
if (world == Level.OVERWORLD) return "";
|
||||
return "("+world.location().getPath().toUpperCase(Locale.ROOT).replace("THE_","").charAt(0)+")";
|
||||
return "("+Character.toUpperCase(world.location().getPath().charAt("THE_".length()))+")";
|
||||
}
|
||||
|
||||
public static List<Component> tracking_report(Level worldIn)
|
||||
public static List<Component> makeTrackingReport(Level worldIn)
|
||||
{
|
||||
|
||||
List<Component> report = new ArrayList<>();
|
||||
if (track_spawns == 0L)
|
||||
if (!trackingSpawns())
|
||||
{
|
||||
report.add(Messenger.c(
|
||||
"w Spawn tracking disabled, type '",
|
||||
"w Spawn tracking is disabled, type '",
|
||||
"wi /spawn tracking start","/spawn tracking start",
|
||||
"w ' to enable"));
|
||||
return report;
|
||||
}
|
||||
long duration = worldIn.getServer().getTickCount() - track_spawns;
|
||||
int duration = worldIn.getServer().getTickCount() - spawnTrackingStartTime;
|
||||
report.add(Messenger.c("bw --------------------"));
|
||||
String simulated = mock_spawns?"[SIMULATED] ":"";
|
||||
String location = (lower_spawning_limit != null)?String.format("[in (%d, %d, %d)x(%d, %d, %d)]",
|
||||
lower_spawning_limit.getX(),lower_spawning_limit.getY(),lower_spawning_limit.getZ(),
|
||||
upper_spawning_limit.getX(),upper_spawning_limit.getY(),upper_spawning_limit.getZ() ):"";
|
||||
String simulated = mockSpawns ? "[SIMULATED] " : "";
|
||||
String location = (trackedSpawningArea != null) ? String.format("[in (%d, %d, %d)x(%d, %d, %d)]",
|
||||
trackedSpawningArea.minX(), trackedSpawningArea.minY(), trackedSpawningArea.minZ(),
|
||||
trackedSpawningArea.maxX(), trackedSpawningArea.maxY(), trackedSpawningArea.maxZ() ):"";
|
||||
report.add(Messenger.s(String.format("%sSpawn statistics %s: for %.1f min", simulated, location, (duration/72000.0)*60)));
|
||||
for (MobCategory enumcreaturetype : MobCategory.values())
|
||||
|
||||
for (MobCategory category : cachedMobCategories())
|
||||
{
|
||||
//String type_code = String.format("%s", enumcreaturetype);
|
||||
for (ResourceKey<Level> dim : worldIn.getServer().levelKeys()) //String world_code: new String[] {"", " (N)", " (E)"})
|
||||
for (ResourceKey<Level> dim : worldIn.getServer().levelKeys())
|
||||
{
|
||||
Pair<ResourceKey<Level>, MobCategory> code = Pair.of(dim, enumcreaturetype);
|
||||
if (spawn_ticks_spawns.get(code) > 0L)
|
||||
Pair<ResourceKey<Level>, MobCategory> key = Pair.of(dim, category);
|
||||
if (spawn_ticks_spawns.getLong(key) > 0L)
|
||||
{
|
||||
double hours = overall_spawn_ticks.get(code)/72000.0;
|
||||
double hours = overall_spawn_ticks.getLong(key)/72000.0;
|
||||
long spawnAttemptsForCategory = spawn_attempts.getLong(key);
|
||||
report.add(Messenger.s(String.format(" > %s%s (%.1f min), %.1f m/t, %%{%.1fF %.1f- %.1f+}; %.2f s/att",
|
||||
enumcreaturetype.getName().substring(0,3), getWorldCode(dim),
|
||||
category.getName().substring(0,3), getWorldCode(dim),
|
||||
60*hours,
|
||||
(1.0D*spawn_cap_count.get(code))/ spawn_attempts.get(code),
|
||||
(100.0D*spawn_ticks_full.get(code))/ spawn_attempts.get(code),
|
||||
(100.0D*spawn_ticks_fail.get(code))/ spawn_attempts.get(code),
|
||||
(100.0D*spawn_ticks_succ.get(code))/ spawn_attempts.get(code),
|
||||
(1.0D*spawn_ticks_spawns.get(code))/(spawn_ticks_fail.get(code)+spawn_ticks_succ.get(code))
|
||||
(1.0D * spawn_cap_count.getLong(key)) / spawnAttemptsForCategory,
|
||||
(100.0D * spawn_ticks_full.getLong(key)) / spawnAttemptsForCategory,
|
||||
(100.0D * spawn_ticks_fail.getLong(key)) / spawnAttemptsForCategory,
|
||||
(100.0D * spawn_ticks_succ.getLong(key)) / spawnAttemptsForCategory,
|
||||
(1.0D * spawn_ticks_spawns.getLong(key)) / (spawn_ticks_fail.getLong(key) + spawn_ticks_succ.getLong(key))
|
||||
)));
|
||||
for (EntityType<?> type: spawn_stats.get(code).keySet())
|
||||
for (Object2LongMap.Entry<EntityType<?>> entry: spawn_stats.get(key).object2LongEntrySet())
|
||||
{
|
||||
report.add(Messenger.s(String.format(" - %s: %d spawns, %d per hour",
|
||||
type.getDescription().getString(),
|
||||
spawn_stats.get(code).getLong(type),
|
||||
(72000 * spawn_stats.get(code).getLong(type)/duration ))));
|
||||
entry.getKey().getDescription().getString(),
|
||||
entry.getLongValue(),
|
||||
(72000 * entry.getLongValue()/duration ))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,8 +365,6 @@ public class SpawnReporter
|
||||
return report;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void killEntity(LivingEntity entity)
|
||||
{
|
||||
if (entity.isPassenger())
|
||||
@@ -390,51 +396,48 @@ public class SpawnReporter
|
||||
public static List<Component> report(BlockPos pos, ServerLevel worldIn)
|
||||
{
|
||||
List<Component> rep = new ArrayList<>();
|
||||
int x = pos.getX(); int y = pos.getY(); int z = pos.getZ();
|
||||
int x = pos.getX();
|
||||
int y = pos.getY();
|
||||
int z = pos.getZ();
|
||||
ChunkAccess chunk = worldIn.getChunk(pos);
|
||||
int lc = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, x, z) + 1;
|
||||
String where = String.format((y >= lc) ? "%d blocks above it." : "%d blocks below it.", Mth.abs(y-lc));
|
||||
if (y == lc) where = "right at it.";
|
||||
rep.add(Messenger.s(String.format("Maximum spawn Y value for (%+d, %+d) is %d. You are "+where, x, z, lc )));
|
||||
String relativeHeight = (y == lc) ? "right at it." : String.format("%d blocks %s it.", Mth.abs(y - lc), (y >= lc) ? "above" : "below");
|
||||
rep.add(Messenger.s(String.format("Maximum spawn Y value for (%+d, %+d) is %d. You are " + relativeHeight, x, z, lc)));
|
||||
rep.add(Messenger.s("Spawns:"));
|
||||
for (MobCategory enumcreaturetype : MobCategory.values())
|
||||
for (MobCategory category : cachedMobCategories())
|
||||
{
|
||||
String type_code = String.format("%s", enumcreaturetype).substring(0, 3);
|
||||
List<MobSpawnSettings.SpawnerData> lst = getSpawnEntries(worldIn, worldIn.structureManager(), worldIn.getChunkSource().getGenerator(), enumcreaturetype, pos, worldIn.getBiome(pos) );// ((ChunkGenerator)worldIn.getChunkManager().getChunkGenerator()).getEntitySpawnList(, worldIn.getStructureAccessor(), enumcreaturetype, pos);
|
||||
String categoryCode = String.valueOf(category).substring(0, 3);
|
||||
List<MobSpawnSettings.SpawnerData> lst = getSpawnEntries(worldIn, worldIn.structureManager(), worldIn.getChunkSource().getGenerator(), category, pos, worldIn.getBiome(pos));
|
||||
if (lst != null && !lst.isEmpty())
|
||||
{
|
||||
for (MobSpawnSettings.SpawnerData spawnEntry : lst)
|
||||
{
|
||||
if (SpawnPlacements.getPlacementType(spawnEntry.type)==null)
|
||||
if (SpawnPlacements.getPlacementType(spawnEntry.type) == null)
|
||||
continue; // vanilla bug
|
||||
boolean canspawn = NaturalSpawner.isSpawnPositionOk(SpawnPlacements.getPlacementType(spawnEntry.type), worldIn, pos, spawnEntry.type);
|
||||
int will_spawn = -1;
|
||||
boolean fits;
|
||||
boolean fits1;
|
||||
boolean canSpawn = NaturalSpawner.isSpawnPositionOk(SpawnPlacements.getPlacementType(spawnEntry.type), worldIn, pos, spawnEntry.type);
|
||||
int willSpawn = -1;
|
||||
boolean fits = false;
|
||||
|
||||
Mob mob;
|
||||
try
|
||||
{
|
||||
mob = (Mob) spawnEntry.type.create(worldIn);
|
||||
}
|
||||
catch (Exception exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
CarpetSettings.LOG.warn("Exception while creating mob for spawn reporter", exception);
|
||||
CarpetSettings.LOG.warn("Exception while creating mob for spawn reporter", e);
|
||||
return rep;
|
||||
}
|
||||
|
||||
boolean fits_true = false;
|
||||
boolean fits_false = false;
|
||||
|
||||
if (canspawn)
|
||||
if (canSpawn)
|
||||
{
|
||||
will_spawn = 0;
|
||||
willSpawn = 0;
|
||||
for (int attempt = 0; attempt < 50; ++attempt)
|
||||
{
|
||||
float f = x + 0.5F;
|
||||
float f1 = z + 0.5F;
|
||||
mob.moveTo(f, y, f1, worldIn.random.nextFloat() * 360.0F, 0.0F);
|
||||
fits1 = worldIn.noCollision(mob);
|
||||
fits = worldIn.noCollision(mob);
|
||||
EntityType<?> etype = mob.getType();
|
||||
|
||||
for (int i = 0; i < 20; ++i)
|
||||
@@ -453,20 +456,12 @@ public class SpawnReporter
|
||||
continue;
|
||||
}
|
||||
}
|
||||
will_spawn += 1;
|
||||
willSpawn += 1;
|
||||
}
|
||||
}
|
||||
mob.finalizeSpawn(worldIn, worldIn.getCurrentDifficultyAt(mob.blockPosition()), MobSpawnType.NATURAL, null, null);
|
||||
// the code invokes onInitialSpawn after getCanSpawHere
|
||||
fits = fits1 && worldIn.noCollision(mob);
|
||||
if (fits)
|
||||
{
|
||||
fits_true = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fits_false = true;
|
||||
}
|
||||
fits = fits && worldIn.noCollision(mob);
|
||||
|
||||
killEntity(mob);
|
||||
|
||||
@@ -474,32 +469,32 @@ public class SpawnReporter
|
||||
{
|
||||
mob = (Mob) spawnEntry.type.create(worldIn);
|
||||
}
|
||||
catch (Exception exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
CarpetSettings.LOG.warn("Exception while creating mob for spawn reporter", exception);
|
||||
CarpetSettings.LOG.warn("Exception while creating mob for spawn reporter", e);
|
||||
return rep;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String creature_name = mob.getType().getDescription().getString();
|
||||
String pack_size = String.format("%d", mob.getMaxSpawnClusterSize());//String.format("%d-%d", animal.minGroupCount, animal.maxGroupCount);
|
||||
String mobTypeName = mob.getType().getDescription().getString();
|
||||
//String pack_size = Integer.toString(mob.getMaxSpawnClusterSize());//String.format("%d-%d", animal.minGroupCount, animal.maxGroupCount);
|
||||
int weight = spawnEntry.getWeight().asInt();
|
||||
if (canspawn)
|
||||
if (canSpawn)
|
||||
{
|
||||
String c = (fits_true && will_spawn>0)?"e":"gi";
|
||||
String color = (fits && willSpawn > 0) ? "e" : "gi";
|
||||
rep.add(Messenger.c(
|
||||
String.format("%s %s: %s (%d:%d-%d/%d), can: ",c,type_code,creature_name,weight,spawnEntry.minCount, spawnEntry.maxCount, mob.getMaxSpawnClusterSize()),
|
||||
String.format("%s %s: %s (%d:%d-%d/%d), can: ", color, categoryCode, mobTypeName, weight, spawnEntry.minCount, spawnEntry.maxCount, mob.getMaxSpawnClusterSize()),
|
||||
"l YES",
|
||||
c+" , fit: ",
|
||||
((fits_true && fits_false)?"y YES and NO":(fits_true?"l YES":"r NO")),
|
||||
c+" , will: ",
|
||||
((will_spawn>0)?"l ":"r ")+Math.round((double)will_spawn)/10+"%"
|
||||
color + " , fit: ",
|
||||
(fits ? "l YES" : "r NO"),
|
||||
color + " , will: ",
|
||||
((willSpawn > 0)?"l ":"r ") + Math.round((double)willSpawn) / 10 + "%"
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
rep.add(Messenger.c(String.format("gi %s: %s (%d:%d-%d/%d), can: ",type_code,creature_name,weight,spawnEntry.minCount, spawnEntry.maxCount, mob.getMaxSpawnClusterSize()), "n NO"));
|
||||
rep.add(Messenger.c(String.format("gi %s: %s (%d:%d-%d/%d), can: ", categoryCode, mobTypeName, weight, spawnEntry.minCount, spawnEntry.maxCount, mob.getMaxSpawnClusterSize()), "n NO"));
|
||||
}
|
||||
killEntity(mob);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user