use of fi.dy.masa.minihud.renderer.shapes.ShapeDespawnSphere in project MasaGadget by plusls.
the class SearchMobSpawnPointUtil method search.
public static void search() {
ClientWorld world = MinecraftClient.getInstance().world;
ClientPlayerEntity player = MinecraftClient.getInstance().player;
if (world == null || player == null) {
return;
}
ShapeDespawnSphere shapeDespawnSphere = getShapeDespawnSphere();
if (shapeDespawnSphere == null) {
return;
}
Vec3d centerPos = shapeDespawnSphere.getCenter();
BlockPos pos = new BlockPos((int) centerPos.x, (int) centerPos.y, (int) centerPos.z);
ModInfo.LOGGER.warn("shape: {}", shapeDespawnSphere.getCenter());
BlockPos spawnPos = null;
int maxX = pos.getX() + 129;
int maxZ = pos.getZ() + 129;
BlockPos.Mutable currentPos = new BlockPos.Mutable();
int maxSpawnLightLevel = fi.dy.masa.minihud.config.Configs.Generic.LIGHT_LEVEL_THRESHOLD_SAFE.getIntegerValue();
LightingProvider lightingProvider = world.getChunkManager().getLightingProvider();
EntityType<?> entityType = world.getDimension().isUltrawarm() ? EntityType.ZOMBIFIED_PIGLIN : EntityType.CREEPER;
EntityType<?> entityType2 = world.getDimension().isUltrawarm() ? null : EntityType.SPIDER;
for (int x = pos.getX() - 129; x <= maxX; ++x) {
for (int z = pos.getZ() - 129; z <= maxZ; ++z) {
WorldChunk chunk = world.getChunk(x >> 4, z >> 4);
if (chunk == null) {
continue;
}
int maxY = Math.min(pos.getY() + 129, chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE, x, z) + 1);
for (int y = Math.max(pos.getY() - 129, world.getBottomY() + 1); y <= maxY; ++y) {
if (squaredDistanceTo(x, y, z, centerPos) > 16384) {
if (y > centerPos.y) {
break;
} else {
continue;
}
} else if (spawnPos != null && player.squaredDistanceTo(x, y, z) > player.squaredDistanceTo(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ())) {
continue;
}
currentPos.set(x, y, z);
if (SpawnHelper.canSpawn(SpawnRestriction.getLocation(entityType), world, currentPos, entityType) && lightingProvider.get(LightType.BLOCK).getLightLevel(currentPos) < maxSpawnLightLevel) {
Block block = world.getBlockState(currentPos.down()).getBlock();
String blockId = Registry.BLOCK.getId(world.getBlockState(currentPos.down()).getBlock()).toString();
String blockName = block.getName().getString();
if (Configs.Generic.SEARCH_MOB_SPAWN_POINT_BLACK_LIST.getStrings().stream().noneMatch(s -> blockId.contains(s) || blockName.contains(s))) {
if (world.isSpaceEmpty(entityType.createSimpleBoundingBox(currentPos.getX() + 0.5D, currentPos.getY(), currentPos.getZ() + 0.5D))) {
spawnPos = currentPos.mutableCopy();
} else if (entityType2 != null && world.isSpaceEmpty(entityType2.createSimpleBoundingBox(currentPos.getX() + 0.5D, currentPos.getY(), currentPos.getZ() + 0.5D))) {
spawnPos = currentPos.mutableCopy();
}
}
}
}
}
}
Text text;
if (spawnPos == null) {
text = new TranslatableText("masa_gadget_mod.message.noBlockCanSpawn").setStyle(Style.EMPTY.withColor(TextColor.fromFormatting(Formatting.GREEN)));
} else {
// for ommc parser
text = new LiteralText(I18n.translate("masa_gadget_mod.message.spawnPos", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ()));
player.sendChatMessage(String.format("/highlightWaypoint %d %d %d", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ()));
}
Objects.requireNonNull(MinecraftClient.getInstance().player).sendMessage(text, false);
}
Aggregations