Java Code Examples for net.minecraft.entity.EntityCategory#values()

The following examples show how to use net.minecraft.entity.EntityCategory#values() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpawnReporter.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void reset_spawn_stats(boolean full)
{

    spawn_stats.clear();
    spawned_mobs.clear();
    for (EntityCategory enumcreaturetype : EntityCategory.values())
    {
        if (full)
        {
            spawn_tries.put(enumcreaturetype, 1);
        }
        for (DimensionType dim : DimensionType.getAll())
        {
            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<>());
        }
    }
    track_spawns = 0L;
}
 
Example 2
Source File: SpawnReporter.java    From fabric-carpet with MIT License 4 votes vote down vote up
public static List<BaseText> printMobcapsForDimension(DimensionType dim, boolean multiline)
{
    String name = dim.toString();
    List<BaseText> lst = new ArrayList<>();
    if (multiline)
        lst.add(Messenger.s(String.format("Mobcaps for %s:",name)));
    Object2IntMap<EntityCategory> dimCounts = mobCounts.get(dim);
    int chunkcount = chunkCounts.getOrDefault(dim, -1);
    if (dimCounts == null || chunkcount < 0)
    {
        lst.add(Messenger.c("g   --UNAVAILABLE--"));
        return lst;
    }

    List<String> shortCodes = new ArrayList<>();
    for (EntityCategory enumcreaturetype : EntityCategory.values())
    {
        int cur = dimCounts.getOrDefault(enumcreaturetype, -1);
        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(enumcreaturetype);
            lst.add(Messenger.c(String.format("w   %s: ", enumcreaturetype.getName()),
                    (cur < 0) ? "g -" : (color + " " + cur), "g  / ", mobColor + " " + max,
                    (rounds == 1) ? "w " : String.format("gi  (%d rounds/tick)", spawn_tries.get(enumcreaturetype))
            ));
        }
        else
        {
            shortCodes.add(color+" "+((cur<0)?"-":cur));
            shortCodes.add("g /");
            shortCodes.add(mobColor+" "+max);
            shortCodes.add("g ,");
        }
    }
    if (!multiline)
    {
        if (shortCodes.size()>0)
        {
            shortCodes.remove(shortCodes.size() - 1);
            lst.add(Messenger.c(shortCodes.toArray(new Object[0])));
        }
        else
        {
            lst.add(Messenger.c("g   --UNAVAILABLE--"));
        }

    }
    return lst;
}
 
Example 3
Source File: SpawnReporter.java    From fabric-carpet with MIT License 4 votes vote down vote up
public static List<BaseText> tracking_report(World worldIn)
{

    List<BaseText> report = new ArrayList<>();
    if (track_spawns == 0L)
    {
        report.add(Messenger.c(
                "w Spawn tracking disabled, type '",
                "wi /spawn tracking start","/spawn tracking start",
                "w ' to enable"));
        return report;
    }
    long duration = (long) worldIn.getServer().getTicks() - track_spawns;
    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() ):"";
    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);
        boolean there_are_mobs_to_list = false;
        for (DimensionType dim: DimensionType.getAll()) //String world_code: new String[] {"", " (N)", " (E)"})
        {
            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.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),
                    (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))
                )));
                for (EntityType type: spawn_stats.get(code).keySet())
                {
                    report.add(Messenger.s(String.format("   - %s: %d spawns, %d per hour",
                            type.getName().getString(),
                            spawn_stats.get(code).getLong(type),
                            (72000 * spawn_stats.get(code).getLong(type)/duration ))));
                }
            }
        }
    }
    return report;
}
 
Example 4
Source File: ServerChunkManagerMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Inject(
        method = "tickChunks",
        locals = LocalCapture.CAPTURE_FAILHARD,
        at = @At(
                value = "INVOKE",
                target = "Lnet/minecraft/server/world/ThreadedAnvilChunkStorage;entryIterator()Ljava/lang/Iterable;",
                shift = At.Shift.AFTER,
                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,
                         LevelProperties levelProperties_1,
                         boolean boolean_1,
                         boolean boolean_2,
                         int int_1,
                         BlockPos blockPos_1,
                         boolean boolean_3,
                         int int_2,
                         EntityCategory[] entityCategorys_1,
                         Object2IntMap object2IntMap_1)
{
    DimensionType dim = this.world.dimension.getType();
    //((WorldInterface)world).getPrecookedMobs().clear(); not needed because mobs are compared with predefined BBs
    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));
        }
    }
}
 
Example 5
Source File: ServerChunkManagerMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Inject(method = "tickChunks", at = @At("RETURN"))
private void onFinishSpawnWorldCycle(CallbackInfo ci)
{
    LevelProperties levelProperties_1 = this.world.getLevelProperties();
    boolean boolean_3 = levelProperties_1.getTime() % 400L == 0L;
    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))
            {
                if (!cat.isAnimal() || boolean_3)
                {
                    // 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;
}