Merge pull request #14 from gnembon/spawn

Spawn
This commit is contained in:
gnembon authored and GitHub committed 2019-05-19 09:49:49 -03:00
commit c4276b2bd4
9 files changed
+364 -152

No files matched your search

+26 -17
View File
@@ -9,16 +9,18 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.minecraft.command.arguments.BlockPosArgumentType;
import net.minecraft.command.arguments.DimensionArgumentType;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.DyeColor;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.DyeColor;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.dimension.DimensionType;
import java.util.Arrays;
import java.util.stream.Collectors;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
@@ -54,7 +56,7 @@ public class SpawnCommand
then(literal("stop").
executes( (c) -> stopTracking(c.getSource()))).
then(argument("type", word()).
suggests( (c, b) -> suggestMatching(SpawnReporter.mob_groups,b)).
suggests( (c, b) -> suggestMatching(Arrays.stream(EntityCategory.values()).map(EntityCategory::getName),b)).
executes( (c) -> recentSpawnsForType(c.getSource(), getString(c, "type"))))).
then(literal("test").
executes( (c)-> runTest(c.getSource(), 72000, null)).
@@ -77,7 +79,7 @@ public class SpawnCommand
then(literal("reset").
executes( (c) -> resetSpawnRates(c.getSource()))).
then(argument("type", word()).
suggests( (c, b) -> suggestMatching(SpawnReporter.mob_groups,b)).
suggests( (c, b) -> suggestMatching(Arrays.stream(EntityCategory.values()).map(EntityCategory::getName),b)).
then(argument("rounds", integer(0)).
suggests( (c, b) -> suggestMatching(new String[]{"1"},b)).
executes( (c) -> setSpawnRates(
@@ -94,12 +96,22 @@ public class SpawnCommand
then(literal("entities").
executes( (c) -> generalMobcaps(c.getSource()) ).
then(argument("type", string()).
suggests( (c, b)->suggestMatching(SpawnReporter.mob_groups, b)).
suggests( (c, b)->suggestMatching(Arrays.stream(EntityCategory.values()).map(EntityCategory::getName), b)).
executes( (c) -> listEntitiesOfType(c.getSource(), getString(c, "type")))));
dispatcher.register(literalargumentbuilder);
}
private static EntityCategory getCategory(String string) throws CommandSyntaxException
{
if (!Arrays.stream(EntityCategory.values()).map(EntityCategory::getName).collect(Collectors.toSet()).contains(string))
{
throw new SimpleCommandExceptionType(Messenger.c("r Wrong mob type: "+string+" should be "+ Arrays.stream(EntityCategory.values()).map(EntityCategory::getName).collect(Collectors.joining(", ")))).create();
}
return EntityCategory.valueOf(string.toUpperCase());
}
private static int listSpawns(ServerCommandSource source, BlockPos pos)
{
Messenger.send(source, SpawnReporter.report(pos, source.getWorld()));
@@ -151,14 +163,10 @@ public class SpawnCommand
return 1;
}
private static int recentSpawnsForType(ServerCommandSource source, String mob_type)
private static int recentSpawnsForType(ServerCommandSource source, String mob_type) throws CommandSyntaxException
{
if (!Arrays.asList(SpawnReporter.mob_groups).contains(mob_type))
{
Messenger.m(source, "r Wrong mob type: "+mob_type);
return 0;
}
Messenger.send(source, SpawnReporter.recent_spawns(source.getWorld(), mob_type));
EntityCategory cat = getCategory(mob_type);
Messenger.send(source, SpawnReporter.recent_spawns(source.getWorld(), cat));
return 1;
}
@@ -222,7 +230,7 @@ public class SpawnCommand
private static int resetSpawnRates(ServerCommandSource source)
{
for (String s: SpawnReporter.spawn_tries.keySet())
for (EntityCategory s: SpawnReporter.spawn_tries.keySet())
{
SpawnReporter.spawn_tries.put(s,1);
}
@@ -231,10 +239,10 @@ public class SpawnCommand
return 1;
}
private static int setSpawnRates(ServerCommandSource source, String mobtype, int rounds)
private static int setSpawnRates(ServerCommandSource source, String mobtype, int rounds) throws CommandSyntaxException
{
String code = SpawnReporter.get_creature_code_from_string(mobtype);
SpawnReporter.spawn_tries.put(code, rounds);
EntityCategory cat = getCategory(mobtype);
SpawnReporter.spawn_tries.put(cat, rounds);
Messenger.m(source, "gi "+mobtype+" mobs will now spawn "+rounds+" times per tick");
return 1;
}
@@ -253,9 +261,10 @@ public class SpawnCommand
return 1;
}
private static int listEntitiesOfType(ServerCommandSource source, String mobtype)
private static int listEntitiesOfType(ServerCommandSource source, String mobtype) throws CommandSyntaxException
{
Messenger.send(source, SpawnReporter.printEntitiesByType(mobtype, source.getWorld()));
EntityCategory cat = getCategory(mobtype);
Messenger.send(source, SpawnReporter.printEntitiesByType(cat, source.getWorld()));
return 1;
}
}
+7 -3
View File
@@ -21,10 +21,11 @@ public class XPcombine
}
}
private static long tone = 0;
private static int lastTickCombine = 0;
private static boolean combineItems(ExperienceOrbEntity first, ExperienceOrbEntity other)
{
if (
first == other || first.world.isClient
first == other || first.world.isClient || first.getServer().getTicks() == lastTickCombine
|| !first.isAlive() || !other.isAlive()
|| first.pickupDelay == 32767 || other.pickupDelay == 32767
|| first.age == -32768 || other.age == -32768
@@ -61,9 +62,10 @@ public class XPcombine
(first.world.random.nextDouble() * 0.5D),
(first.world.random.nextDouble() * 1.0D - 0.5D)
)));
double pitch = Math.pow(2.0D, (tone%13)/12.0D )/2.0;
float pitch = (float)Math.pow(2.0D, (tone%13)/12.0D )/2.0F;
tone+=2;
if(tone%13 == 0 || tone%13 == 1 || tone%13 == 6) tone --;
lastTickCombine = newOrb.getServer().getTicks();
for (PlayerEntity p : newOrb.world.getPlayers())
{
ServerPlayerEntity sp = (ServerPlayerEntity)p;
@@ -71,7 +73,9 @@ public class XPcombine
{
sp.networkHandler.sendPacket(new PlaySoundIdS2CPacket(
Registry.SOUND_EVENT.getId(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP),
SoundCategory.BLOCKS, newOrb.getPos(), 1.0F, (float)pitch));
SoundCategory.PLAYERS, newOrb.getPos(),
pitch-newOrb.world.random.nextFloat()/2f,
pitch));
}
}
return true;
@@ -0,0 +1,41 @@
package carpet.mixins;
import carpet.CarpetSettings;
import com.mojang.bridge.game.GameVersion;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(DebugHud.class)
public class DebugHudMixin
{
@Redirect(method = "getLeftText", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/MinecraftClient;getGameVersion()Ljava/lang/String;"
))
private String getCarpetClient(MinecraftClient minecraftClient)
{
return "vanilla enough";
}
@Redirect(method = "getLeftText", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/ClientBrandRetriever;getClientModName()Ljava/lang/String;"
))
private String getModName()
{
return "don't even...";
}
@Redirect(method = "getLeftText", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/MinecraftClient;getVersionType()Ljava/lang/String;"
))
private String getVersionType(MinecraftClient minecraftClient)
{
return "release";
}
}
@@ -1,8 +1,10 @@
package carpet.mixins;
import carpet.CarpetServer;
import carpet.CarpetSettings;
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -18,4 +20,13 @@ public class MinecraftClientMixin
//CM start game hook
CarpetServer.onGameStarted();
}
/**
* @author gnembon
*/
@Overwrite
public String getVersionType()
{
return "carpet "+ CarpetSettings.carpetVersion;
}
}
@@ -1,27 +1,36 @@
package carpet.mixins;
import carpet.CarpetSettings;
import carpet.utils.SpawnReporter;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.entity.EntityCategory;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.SpawnHelper;
import net.minecraft.world.World;
import net.minecraft.world.chunk.WorldChunk;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.level.LevelProperties;
import org.apache.commons.lang3.tuple.Pair;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.HashMap;
import java.util.HashSet;
@Mixin(ServerChunkManager.class)
public abstract class ServerChunkManagerMixin
{
@Shadow @Final private ServerWorld world;
@Shadow @Final private static int CHUNKS_ELIGIBLE_FOR_SPAWNING;
@Inject(
method = "tickChunks",
locals = LocalCapture.CAPTURE_FAILHARD,
@@ -32,6 +41,7 @@ public abstract class ServerChunkManagerMixin
ordinal = 0
))
//this runs once per world spawning cycle. Allows to grab mob counts and count spawn ticks
private void grabMobcaps(CallbackInfo ci,
long long_1,
long long_2,
@@ -48,6 +58,119 @@ public abstract class ServerChunkManagerMixin
DimensionType dim = this.world.dimension.getType();
SpawnReporter.mobCounts.put(dim, (Object2IntMap<EntityCategory>)object2IntMap_1);
SpawnReporter.chunkCounts.put(dim, int_2);
if (SpawnReporter.track_spawns > 0L)
{
//local spawns now need to be tracked globally cause each calll is just for chunk
SpawnReporter.local_spawns = new HashMap<>();
SpawnReporter.first_chunk_marker = new HashSet<>();
for (EntityCategory cat : EntityCategory.values())
{
Pair key = Pair.of(dim, cat);
SpawnReporter.overall_spawn_ticks.put(key,
SpawnReporter.overall_spawn_ticks.get(key)+
SpawnReporter.spawn_tries.get(cat));
}
}
}
@Redirect(method = "tickChunks", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/SpawnHelper;spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/WorldChunk;Lnet/minecraft/util/math/BlockPos;)V"
))
// inject our repeat of spawns if more spawn ticks per tick are chosen.
private void spawnMultipleTimes(EntityCategory entityCategory_1, World world_1, WorldChunk worldChunk_1, BlockPos blockPos_1)
{
for (int i = 0; i < SpawnReporter.spawn_tries.get(entityCategory_1); i++)
{
SpawnHelper.spawnEntitiesInChunk(entityCategory_1, world_1, worldChunk_1, blockPos_1);
}
}
@Redirect(method = "tickChunks", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/EntityCategory;getSpawnCap()I"
))
// allows to change mobcaps and captures each category try per dimension before it fails due to full mobcaps.
private int getNewMobcaps(EntityCategory entityCategory)
{
DimensionType dim = this.world.dimension.getType();
int newCap = (int) ((double)entityCategory.getSpawnCap()*(Math.pow(2.0,(SpawnReporter.mobcap_exponent/4))));
if (SpawnReporter.track_spawns > 0L)
{
int int_2 = SpawnReporter.chunkCounts.get(dim); // eligible chunks for spawning
int int_3 = newCap * int_2 / CHUNKS_ELIGIBLE_FOR_SPAWNING; //current spawning limits
int mobCount = SpawnReporter.mobCounts.get(dim).getInt(entityCategory);
if (SpawnReporter.track_spawns > 0L && !SpawnReporter.first_chunk_marker.contains(entityCategory))
{
SpawnReporter.first_chunk_marker.add(entityCategory);
//first chunk with spawn eligibility for that category
Pair key = Pair.of(dim, entityCategory);
int spawnTries = SpawnReporter.spawn_tries.get(entityCategory);
SpawnReporter.spawn_attempts.put(key,
SpawnReporter.spawn_attempts.get(key) + spawnTries);
SpawnReporter.spawn_cap_count.put(key,
SpawnReporter.spawn_cap_count.get(key) + mobCount);
}
if (mobCount <= int_3)
{
//place 0 to indicate there were spawn attempts for a category
//if (entityCategory != EntityCategory.CREATURE || world.getServer().getTicks() % 400 == 0)
// this will only be called once every 400 ticks anyways
SpawnReporter.local_spawns.putIfAbsent(entityCategory, 0L);
//else
//full mobcaps - and key in local_spawns will be missing
}
}
return SpawnReporter.mock_spawns?Integer.MAX_VALUE:newCap;
}
@Inject(method = "tickChunks", at = @At("RETURN"))
private void onFinishSpawnWorldCycle(CallbackInfo ci)
{
if (SpawnReporter.track_spawns > 0L && SpawnReporter.local_spawns != null)
{
for (EntityCategory cat: EntityCategory.values())
{
DimensionType dim = world.dimension.getType();
Pair key = Pair.of(world.dimension.getType(), cat);
int spawnTries = SpawnReporter.spawn_tries.get(cat);
if (!SpawnReporter.local_spawns.containsKey(cat))
{
// fill mobcaps for that category so spawn got cancelled
SpawnReporter.spawn_ticks_full.put(key,
SpawnReporter.spawn_ticks_full.get(key)+ spawnTries);
}
else if (SpawnReporter.local_spawns.get(cat) > 0)
{
// tick spawned mobs for that type
SpawnReporter.spawn_ticks_succ.put(key,
SpawnReporter.spawn_ticks_succ.get(key)+spawnTries);
SpawnReporter.spawn_ticks_spawns.put(key,
SpawnReporter.spawn_ticks_spawns.get(key)+
SpawnReporter.local_spawns.get(cat));
// this will be off comparing to 1.13 as that would succeed if
// ANY tries in that round were successful.
// there will be much more difficult to mix in
// considering spawn tries to remove, as with warp
// there is little need for them anyways.
}
else // spawn no mobs despite trying
{
//tick didn's spawn mobs of that type
SpawnReporter.spawn_ticks_fail.put(key,
SpawnReporter.spawn_ticks_fail.get(key)+spawnTries);
}
}
}
SpawnReporter.local_spawns = null;
}
}
@@ -0,0 +1,36 @@
package carpet.mixins;
import carpet.CarpetSettings;
import carpet.utils.SpawnReporter;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.world.SpawnHelper;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(SpawnHelper.class)
public abstract class SpawnHelperMixin
{
@Redirect(method = "spawnEntitiesInChunk", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z"
))
private static boolean catchEntitySpawn(World world, Entity entity_1)
{
if (SpawnReporter.track_spawns > 0L && SpawnReporter.local_spawns != null)
{
SpawnReporter.registerSpawn(
world.dimension.getType(),
(MobEntity) entity_1,
entity_1.getType().getCategory(),
entity_1.getBlockPos());
}
if (!SpawnReporter.mock_spawns)
return world.spawnEntity(entity_1);
return false;
}
}
+10 -3
View File
@@ -3,11 +3,18 @@ package carpet.utils;
import java.util.LinkedHashMap;
import java.util.Map;
public class EvictingQueue<K,V> extends LinkedHashMap<K,V>
public class EvictingQueue<K> extends LinkedHashMap<K,Integer>
{
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest)
public void put(K key)
{
super.put(key, 1);
}
@Override
protected boolean removeEldestEntry(Map.Entry<K, Integer> eldest)
{
return this.size() > 10;
}
}
+104 -128
View File
@@ -1,82 +1,69 @@
package carpet.utils;
import java.util.List;
import carpet.mixins.WeightedPickerEntryMixin;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.OcelotEntity;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.DyeColor;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.Heightmap;
import net.minecraft.world.SpawnHelper;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.HashMap;
import carpet.mixins.WeightedPickerEntryMixin;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.structure.OceanMonumentGenerator;
import net.minecraft.util.Pair;
import net.minecraft.util.registry.Registry;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.DyeColor;
import net.minecraft.entity.EntityCategory;
import net.minecraft.world.biome.Biome;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.SpawnHelper;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.OcelotEntity;
import net.minecraft.world.Heightmap;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import java.lang.Math;
import java.util.HashSet;
import java.util.List;
public class SpawnReporter
{
public static String [] mob_groups = {"hostile","passive","water","ambient"};
public static boolean mock_spawns = false;
public static Long track_spawns = 0L;
public static final HashMap<DimensionType, Object2IntMap<EntityCategory>> mobCounts = new HashMap<>();
public static final HashMap<DimensionType, Integer> chunkCounts = new HashMap<>();
public static final HashMap<String, HashMap<String,Long>> spawn_stats = new HashMap<String, HashMap<String,Long>>();
public static final HashMap<Pair<DimensionType, EntityCategory>, Object2LongMap<EntityType>> spawn_stats = new HashMap<>();
public static double mobcap_exponent = 0.0D;
public static final HashMap<String, Long> spawn_attempts = new HashMap<String, Long>();
public static final HashMap<String, Long> overall_spawn_ticks = new HashMap<String, Long>();
public static final HashMap<String, Long> spawn_ticks_full = new HashMap<String, Long>();
public static final HashMap<String, Long> spawn_ticks_fail = new HashMap<String, Long>();
public static final HashMap<String, Long> spawn_ticks_succ = new HashMap<String, Long>();
public static final HashMap<String, Long> spawn_ticks_spawns = new HashMap<String, Long>();
public static final HashMap<String, Long> spawn_cap_count = new HashMap<String, Long>();
public static class SpawnPos
{
public String mob;
public BlockPos pos;
public SpawnPos(String mob, BlockPos pos)
{
this.mob = mob;
this.pos = pos;
}
}
public static final HashMap<String, EvictingQueue<SpawnPos, Integer>> spawned_mobs = new HashMap<>();
public static final HashMap<String, Integer> spawn_tries = new HashMap<>();
public static final HashMap<Pair<DimensionType, EntityCategory>, Long> spawn_attempts = new HashMap<>();
public static final HashMap<Pair<DimensionType, EntityCategory>, Long> overall_spawn_ticks = new HashMap<>();
public static final HashMap<Pair<DimensionType, EntityCategory>, Long> spawn_ticks_full = new HashMap<>();
public static final HashMap<Pair<DimensionType, EntityCategory>, Long> spawn_ticks_fail = new HashMap<>();
public static final HashMap<Pair<DimensionType, EntityCategory>, Long> spawn_ticks_succ = new HashMap<>();
public static final HashMap<Pair<DimensionType, EntityCategory>, Long> spawn_ticks_spawns = new HashMap<>();
public static final HashMap<Pair<DimensionType, EntityCategory>, Long> spawn_cap_count = new HashMap<>();
public static final HashMap<Pair<DimensionType, EntityCategory>, EvictingQueue<Pair<EntityType, BlockPos>>> spawned_mobs = new HashMap<>();
public static final HashMap<EntityCategory, 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<EntityCategory, Long> local_spawns = null; // per world
public static HashSet<EntityCategory> first_chunk_marker = null;
static {
reset_spawn_stats(true);
}
public static void registerSpawn(LivingEntity el, String type, String mob, BlockPos pos) { registerSpawn(el, type, mob, pos, 1L);}
public static void registerSpawn(LivingEntity el, String type, String mob, BlockPos pos, long value)
public static void registerSpawn(DimensionType dim, MobEntity mob, EntityCategory cat, BlockPos pos)
{
if (lower_spawning_limit != null)
{
@@ -88,10 +75,11 @@ public class SpawnReporter
return;
}
}
long count = spawn_stats.get(type).getOrDefault(mob, 0L);
spawn_stats.get(type).put(mob, count + value);
spawned_mobs.get(type).put(new SpawnPos(mob, new BlockPos(el)), 1);
Pair<DimensionType, EntityCategory> key = Pair.of(mob.dimension, cat);
long count = spawn_stats.get(key).getOrDefault(mob.getType(), 0L);
spawn_stats.get(key).put(mob.getType(), count + 1);
spawned_mobs.get(key).put(Pair.of(mob.getType(), pos));
local_spawns.put(cat, local_spawns.get(cat)+1);
}
@@ -112,17 +100,16 @@ public class SpawnReporter
List<String> shortCodes = new ArrayList<>();
for (EntityCategory enumcreaturetype : EntityCategory.values())
{
String type_code = String.format("%s", enumcreaturetype);
int cur = dimCounts.getOrDefault(enumcreaturetype, -1);
int max = chunkcount * enumcreaturetype.getSpawnCap() / (int)Math.pow(17.0D, 2.0D); // from ServerChunkManager.CHUNKS_ELIGIBLE_FOR_SPAWNING
int max = chunkcount * (int)((double)enumcreaturetype.getSpawnCap() * (Math.pow(2.0,(SpawnReporter.mobcap_exponent/4)))) / (int)Math.pow(17.0D, 2.0D); // from ServerChunkManager.CHUNKS_ELIGIBLE_FOR_SPAWNING
String color = Messenger.heatmap_color(cur, max);
String mobColor = Messenger.creatureTypeColor(enumcreaturetype);
if (multiline)
{
int rounds = spawn_tries.get(type_code);
lst.add(Messenger.c(String.format("w %s: ", type_code),
int rounds = spawn_tries.get(enumcreaturetype);
lst.add(Messenger.c(String.format("w %s: ", enumcreaturetype.getName()),
(cur < 0) ? "g -" : (color + " " + cur), "g / ", mobColor + " " + max,
(rounds == 1) ? "w " : String.format("fi (%d rounds/tick)", spawn_tries.get(type_code))
(rounds == 1) ? "w " : String.format("fi (%d rounds/tick)", spawn_tries.get(enumcreaturetype))
));
}
else
@@ -149,28 +136,24 @@ public class SpawnReporter
return lst;
}
public static List<BaseComponent> recent_spawns(World world, String creature_type_code)
public static List<BaseComponent> recent_spawns(World world, EntityCategory creature_type)
{
EntityCategory creature_type = get_creature_type_from_code(creature_type_code);
List<BaseComponent> lst = new ArrayList<>();
if ((track_spawns == 0L))
{
lst.add(Messenger.s("Spawn tracking not started"));
return lst;
}
if (creature_type == null)
{
lst.add(Messenger.s(String.format("Incorrect creature type: %s",creature_type_code)));
return lst;
}
String type_code = get_type_string(creature_type);
String type_code = creature_type.getName();
lst.add(Messenger.s(String.format("Recent %s spawns:",type_code)));
for (SpawnPos entry: spawned_mobs.get(type_code).keySet())
for (Pair<EntityType, BlockPos> pair : spawned_mobs.get(Pair.of(world.getDimension().getType(),creature_type)).keySet())
{
lst.add( Messenger.c(String.format("w - %s ",entry.mob), Messenger.tp("wb",entry.pos)));
lst.add( Messenger.c(
"w - ",
Messenger.tp("wb",pair.getRight()),
String.format("w : %s", EntityType.getId(pair.getLeft()).toString().replaceFirst("minecraft.",""))
));
}
if (lst.size()==1)
@@ -192,10 +175,10 @@ public class SpawnReporter
}
else
{
//return print_general_mobcaps(worldIn);
return new ArrayList<>();
}
}
String creature_type = get_type_code_from_wool_code(under);
EntityCategory creature_type = get_type_code_from_wool_code(under);
if (creature_type != null)
{
if (track_spawns > 0L)
@@ -222,18 +205,18 @@ public class SpawnReporter
}
public static String get_type_code_from_wool_code(DyeColor color)
public static EntityCategory get_type_code_from_wool_code(DyeColor color)
{
switch (color)
{
case RED:
return "hostile";
return EntityCategory.MONSTER;
case GREEN:
return "passive";
return EntityCategory.CREATURE;
case BLUE:
return "water";
return EntityCategory.WATER_CREATURE;
case BROWN:
return "ambient";
return EntityCategory.AMBIENT;
}
return null;
}
@@ -270,27 +253,23 @@ public class SpawnReporter
return get_type_string(get_creature_type_from_code(str));
}
public static List<BaseComponent> printEntitiesByType(String creature_type_code, World worldIn) //Class<?> entityType)
public static List<BaseComponent> printEntitiesByType(EntityCategory cat, World worldIn) //Class<?> entityType)
{
EntityCategory typ = get_creature_type_from_code(creature_type_code);
List<BaseComponent> lst = new ArrayList<>();
if (typ == null)
lst.add( Messenger.s(String.format("Loaded entities for %s class:", get_type_string(cat))));
for (Entity entity : ((ServerWorld)worldIn).getEntities(null, (e) -> e.getType().getCategory()==cat))
{
lst.add(Messenger.c(String.format("r Incorrect creature type: %s",creature_type_code)));
return lst;
if (!(entity instanceof MobEntity) || !((MobEntity)entity).isPersistent())
{
EntityType type = entity.getType();
BlockPos pos = entity.getBlockPos();
lst.add( Messenger.c(
"w - ",
Messenger.tp("wb",pos),
String.format("w : %s", EntityType.getId(type).toString().replaceFirst("minecraft.",""))
));
}
}
Class<?> cls = typ.getDeclaringClass();// getBaseClass();// getCreatureClass();
lst.add( Messenger.s(String.format("Loaded entities for %s class:", get_type_string(typ))));
lst.add(Messenger.s(" <sorry, this list will be populated, once M figures out what counts>"));
//for (Entity entity : ((ServerWorld)worldIn).getEntities(...))
//{
// if ((!(entity instanceof LivingEntity) || !((LivingEntity)entity).isNoDespawnRequired()) && cls.isAssignableFrom(entity.getClass()))
// {
// lst.add(Messenger.c("w - ",
// Messenger.tp("w", entity.posX, entity.posY, entity.posZ),"w : "+EntityType.getId(entity.getType())));
// }
//}
if (lst.size()==1)
{
lst.add(Messenger.s(" - Empty."));
@@ -312,35 +291,35 @@ public class SpawnReporter
}
public static void reset_spawn_stats(boolean full)
{
spawn_stats.clear();
spawned_mobs.clear();
for (EntityCategory enumcreaturetype : EntityCategory.values())
{
String type_code = String.format("%s", enumcreaturetype);
if (full)
{
spawn_tries.put(type_code, 1);
spawn_tries.put(enumcreaturetype, 1);
}
for (String suffix: new String[] {""," (N)"," (E)"})
for (DimensionType dim : DimensionType.getAll())
{
String code = type_code+suffix;
overall_spawn_ticks.put(code, 0L);
spawn_attempts.put(code, 0L);
spawn_ticks_full.put(code, 0L);
spawn_ticks_fail.put(code, 0L);
spawn_ticks_succ.put(code, 0L);
spawn_ticks_spawns.put(code, 0L);
spawn_cap_count.put(code, 0L);
Pair<DimensionType, EntityCategory> 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);
spawn_stats.put(key, new Object2LongOpenHashMap<>());
spawned_mobs.put(key, new EvictingQueue<>());
}
spawn_stats.put(type_code, new HashMap<>());
spawned_mobs.put(type_code, new EvictingQueue<>());
}
track_spawns = 0L;
}
public static List<BaseComponent> tracking_report(World worldIn)
{
List<BaseComponent> report = new ArrayList<>();
if (track_spawns == 0L)
{
@@ -359,17 +338,17 @@ public class SpawnReporter
report.add(Messenger.s(String.format("%sSpawn statistics %s: for %.1f min", simulated, location, (duration/72000.0)*60)));
for (EntityCategory enumcreaturetype : EntityCategory.values())
{
String type_code = String.format("%s", enumcreaturetype);
//String type_code = String.format("%s", enumcreaturetype);
boolean there_are_mobs_to_list = false;
for (String world_code: new String[] {"", " (N)", " (E)"})
for (DimensionType dim: DimensionType.getAll()) //String world_code: new String[] {"", " (N)", " (E)"})
{
String code = type_code+world_code;
Pair<DimensionType, EntityCategory> code = Pair.of(dim, enumcreaturetype);
if (spawn_ticks_spawns.get(code) > 0L)
{
there_are_mobs_to_list = true;
double hours = overall_spawn_ticks.get(code)/72000.0;
report.add(Messenger.s(String.format(" > %s (%.1f min), %.1f m/t, {%.1f%%F / %.1f%%- / %.1f%%+}; %.2f s/att",
code,
code.getRight()+((code.getLeft()==DimensionType.OVERWORLD)?"":( (code.getLeft()==DimensionType.THE_NETHER)?"(N)":"(E)" )),
60*hours,
(1.0D*spawn_cap_count.get(code))/ spawn_attempts.get(code),
(100.0D*spawn_ticks_full.get(code))/ spawn_attempts.get(code),
@@ -377,16 +356,13 @@ public class SpawnReporter
(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))
)));
}
}
if (there_are_mobs_to_list)
{
for (String creature_name : spawn_stats.get(type_code).keySet())
{
report.add(Messenger.s(String.format(" - %s: %d spawns, %d per hour",
creature_name,
spawn_stats.get(type_code).get(creature_name),
(72000 * spawn_stats.get(type_code).get(creature_name)/duration ))));
for (EntityType type: spawn_stats.get(code).keySet())
{
report.add(Messenger.s(String.format(" - %s: %d spawns, %d per hour",
Registry.ENTITY_TYPE.getId(type).toString().replaceFirst("minecraft:",""),
spawn_stats.get(code).getLong(type),
(72000 * spawn_stats.get(code).getLong(type)/duration ))));
}
}
}
}
+5
View File
@@ -5,6 +5,7 @@
"mixins": [
"CommandManagerMixin",
"FillCommandMixin",
"CloneCommandMixin",
"SetBlockCommandMixin",
@@ -28,7 +29,10 @@
"ExperienceOrbEntityMixin",
"PlayerActionC2SPacketMixin",
"ServerPlayerEntityMixin",
"ServerChunkManagerMixin",
"SpawnHelperMixin",
"HopperBlockEntityMixin",
"ContainerMixin",
"ClientConnectionMixin",
@@ -37,6 +41,7 @@
"ExplosionMixin"
],
"client": [
"DebugHudMixin",
"MinecraftClientMixin",
"IntegratedServerMixin",
"InGameHudMixin",