Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor SpawnReporter cleanup #1517

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 16 additions & 68 deletions src/main/java/carpet/utils/SpawnReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
Expand All @@ -33,12 +32,12 @@
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.BuiltinStructures;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.structures.NetherFortressStructure;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;

import static net.minecraft.world.entity.MobCategory.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -228,63 +227,21 @@ public static List<Component> show_mobcaps(BlockPos pos, ServerLevel worldIn)

public static MobCategory get_type_code_from_wool_code(DyeColor color)
{
switch (color)
return switch (color)
{
case RED:
return MobCategory.MONSTER;
case GREEN:
return MobCategory.CREATURE;
case BLUE:
return MobCategory.WATER_CREATURE;
case BROWN:
return MobCategory.AMBIENT;
case CYAN:
return MobCategory.WATER_AMBIENT;
default:
return null;
}
}

public static MobCategory get_creature_type_from_code(String type_code)
{
if ("hostile".equalsIgnoreCase(type_code))
{
return MobCategory.MONSTER;
}
else if ("passive".equalsIgnoreCase(type_code))
{
return MobCategory.CREATURE;
}
else if ("water".equalsIgnoreCase(type_code))
{
return MobCategory.WATER_CREATURE;
}
else if ("fish".equalsIgnoreCase(type_code))
{
return MobCategory.WATER_AMBIENT;
}
else if ("ambient".equalsIgnoreCase(type_code))
{
return MobCategory.AMBIENT;
}
return null;
}


public static String get_type_string(MobCategory type)
{
return String.format("%s", type);
}

public static String get_creature_code_from_string(String str)
{
return get_type_string(get_creature_type_from_code(str));
case RED -> MONSTER;
case GREEN -> CREATURE;
case BLUE -> WATER_CREATURE;
case BROWN -> AMBIENT;
case CYAN -> WATER_AMBIENT;
default -> null;
};
}

public static List<Component> printEntitiesByType(MobCategory cat, Level worldIn, boolean all) //Class<?> entityType)
{
List<Component> lst = new ArrayList<>();
lst.add( Messenger.s(String.format("Loaded entities for %s class:", get_type_string(cat))));
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))
{
boolean persistent = entity instanceof Mob && ( ((Mob) entity).isPersistenceRequired() || ((Mob) entity).requiresCustomPersistence());
Expand Down Expand Up @@ -362,7 +319,7 @@ public static List<Component> tracking_report(Level worldIn)
"w ' to enable"));
return report;
}
long duration = (long) worldIn.getServer().getTickCount() - track_spawns;
long duration = worldIn.getServer().getTickCount() - 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)]",
Expand Down Expand Up @@ -427,16 +384,7 @@ public static void killEntity(LivingEntity entity)

// yeeted from NaturalSpawner - temporary access fix
private static List<MobSpawnSettings.SpawnerData> getSpawnEntries(ServerLevel serverLevel, StructureManager structureManager, ChunkGenerator chunkGenerator, MobCategory mobCategory, BlockPos blockPos, @Nullable Holder<Biome> holder) {
return isInNetherFortressBounds(blockPos, serverLevel, mobCategory, structureManager) ? NetherFortressStructure.FORTRESS_ENEMIES.unwrap() : chunkGenerator.getMobsAt(holder != null ? holder : serverLevel.getBiome(blockPos), structureManager, mobCategory, blockPos).unwrap();
}

public static boolean isInNetherFortressBounds(BlockPos blockPos, ServerLevel serverLevel, MobCategory mobCategory, StructureManager structureManager) {
if (mobCategory == MobCategory.MONSTER && serverLevel.getBlockState(blockPos.below()).is(Blocks.NETHER_BRICKS)) {
Structure structure = (Structure)structureManager.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).get(BuiltinStructures.FORTRESS);
return structure == null ? false : structureManager.getStructureAt(blockPos, structure).isValid();
} else {
return false;
}
return NaturalSpawner.isInNetherFortressBounds(blockPos, serverLevel, mobCategory, structureManager) ? NetherFortressStructure.FORTRESS_ENEMIES.unwrap() : chunkGenerator.getMobsAt(holder != null ? holder : serverLevel.getBiome(blockPos), structureManager, mobCategory, blockPos).unwrap();
}

public static List<Component> report(BlockPos pos, ServerLevel worldIn)
Expand Down Expand Up @@ -483,9 +431,9 @@ public static List<Component> report(BlockPos pos, ServerLevel worldIn)
will_spawn = 0;
for (int attempt = 0; attempt < 50; ++attempt)
{
float f = (float)x + 0.5F;
float f1 = (float)z + 0.5F;
mob.moveTo((double)f, (double)y, (double)f1, worldIn.random.nextFloat() * 360.0F, 0.0F);
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);
EntityType<?> etype = mob.getType();

Expand Down